This commit is contained in:
zaqxs123456 2024-10-25 15:53:59 +08:00
parent 56d930a854
commit 4836fb3d6e
2 changed files with 15 additions and 15 deletions

8
app.py
View File

@ -27,7 +27,7 @@ expo_raw_sd_dir = info['expo_raw_sd_dir']
expo_openpose_dir = info['expo_openpose_dir'] expo_openpose_dir = info['expo_openpose_dir']
on_postprocessing = False on_postprocessing = False
on_testing = False on_testing = True
@app.route('/expo_fencing_pose', methods=['POST']) @app.route('/expo_fencing_pose', methods=['POST'])
def expo_fencing_pose(): def expo_fencing_pose():
@ -44,7 +44,7 @@ def expo_fencing_pose():
if coordinates is None or canvas_size is None or 'batch' not in data or 'step' not in data: if coordinates is None or canvas_size is None or 'batch' not in data or 'step' not in data:
return jsonify({"status": "error", "message": "Missing data"}), 422 return jsonify({"status": "error", "message": "Missing data"}), 422
right_fencer_coordinates = get_predicted_coordinates(coordinates) right_fencer_coordinates = get_predicted_coordinates(coordinates, canvas_size[0], canvas_size[1])
left_fencer_dir = os.path.join(expo_openpose_dir, 'left_fencer') left_fencer_dir = os.path.join(expo_openpose_dir, 'left_fencer')
os.makedirs(left_fencer_dir, exist_ok=True) os.makedirs(left_fencer_dir, exist_ok=True)
@ -151,11 +151,11 @@ async def expo_postprocess():
await asyncio.to_thread(expo_postprocess_main) await asyncio.to_thread(expo_postprocess_main)
await asyncio.to_thread(expo_clear_images) await asyncio.to_thread(expo_clear_images)
on_postprocessing = False on_postprocessing = False
print("Postprocessing completed")
return jsonify({"status": "success", "message": "Postprocessing completed"}), 200 return jsonify({"status": "success", "message": "Postprocessing completed"}), 200
async def wait_for_files_to_match(dir1: str, dir2: str, timeout: int = 60, interval: int = 1) -> bool: async def wait_for_files_to_match(dir1: str, dir2: str, timeout: int = 180, interval: int = 1) -> bool:
start_time = asyncio.get_event_loop().time() start_time = asyncio.get_event_loop().time()
while asyncio.get_event_loop().time() - start_time < timeout: while asyncio.get_event_loop().time() - start_time < timeout:
files1 = get_all_files(dir1) files1 = get_all_files(dir1)

View File

@ -119,13 +119,13 @@ def expo_motion_blur_fencer(image_path: str, output_path: str, sigma: float, dir
subprocess.run(command, check=True) subprocess.run(command, check=True)
return output_path return output_path
def expo_motion_blur_fencers(path_list: list[str], is_left: bool) -> list[str]: def expo_motion_blur_fencers(path_list: list[str]) -> list[str]:
futures = [] futures = []
with ThreadPoolExecutor() as executor: with ThreadPoolExecutor() as executor:
for i, image_path in enumerate(path_list): for i, image_path in enumerate(path_list):
sigma = 15 - 15 * i / (len(path_list) - 1) sigma = 15 - 15 * i / (len(path_list) - 1)
direction = 0 if is_left else 180 direction = 0
future = executor.submit(expo_motion_blur_fencer, image_path, image_path, sigma, direction) future = executor.submit(expo_motion_blur_fencer, image_path, image_path, sigma, direction)
futures.append(future) futures.append(future)
@ -217,24 +217,24 @@ def expo_postprocess_main():
output_files = [] output_files = []
for i, candidate_list in enumerate(left_shuffled_images_paths): for i, candidate_list in enumerate(left_shuffled_images_paths):
left_fencer_paths = expo_resize_fencers(candidate_list, True, 500, 500) left_fencer_paths = expo_resize_fencers(candidate_list, True, 450, 450)
expo_motion_blur_fencers(left_fencer_paths, True) expo_motion_blur_fencers(left_fencer_paths)
expo_decrese_opacities(left_fencer_paths) expo_decrese_opacities(left_fencer_paths)
temp_output_path = os.path.join(expo_postprocess_temp_dir, f"temp_{i}.png") temp_output_path = os.path.join(expo_postprocess_temp_dir, f"temp_{i}.png")
output_files.append(temp_output_path) output_files.append(temp_output_path)
temp_background_path = background_path temp_background_path = background_path
for j, left_fencer_path in enumerate(left_fencer_paths): for j, left_fencer_path in enumerate(left_fencer_paths):
x_position = 65 * math.pow(j, 1.3) - 132 x_position = 34 * math.pow(j, 1.3) - 100
y_position = 192 y_position = 170
expo_add_to_background_image(temp_background_path, left_fencer_path, temp_output_path, x_position, y_position) expo_add_to_background_image(temp_background_path, left_fencer_path, temp_output_path, x_position, y_position)
temp_background_path = temp_output_path temp_background_path = temp_output_path
for i, candidate_list in enumerate(right_shuffled_images_paths): for i, candidate_list in enumerate(right_shuffled_images_paths):
if i > len(left_shuffled_images_paths) - 1: if i > len(left_shuffled_images_paths) - 1:
break break
right_fencer_paths = expo_resize_fencers(candidate_list, False, 500, 500) right_fencer_paths = expo_resize_fencers(candidate_list, False, 450, 450)
expo_motion_blur_fencers(right_fencer_paths, False) expo_motion_blur_fencers(right_fencer_paths)
expo_decrese_opacities(right_fencer_paths) expo_decrese_opacities(right_fencer_paths)
temp_output_path = os.path.join(expo_postprocess_temp_dir, f"temp_{i}.png") temp_output_path = os.path.join(expo_postprocess_temp_dir, f"temp_{i}.png")
@ -242,13 +242,13 @@ def expo_postprocess_main():
break break
for j, right_fencer_path in enumerate(right_fencer_paths): for j, right_fencer_path in enumerate(right_fencer_paths):
x_position = 1080 - (65 * math.pow(j, 1.3) - 132) x_position = 540 - (34 * math.pow(j, 1.3) - 170)
y_position = 192 y_position = 170
expo_add_to_background_image(temp_output_path, right_fencer_path, temp_output_path, x_position, y_position) expo_add_to_background_image(temp_output_path, right_fencer_path, temp_output_path, x_position, y_position)
temp_background_path = temp_output_path temp_background_path = temp_output_path
expo_overlay_bg_gradient(temp_output_path, temp_output_path, bg_gradients[i % len(bg_gradients)]) expo_overlay_bg_gradient(temp_output_path, temp_output_path, bg_gradients[i % len(bg_gradients)])
expo_add_logo(temp_output_path, logo_path, temp_output_path, 750, 700) expo_add_logo(temp_output_path, logo_path, temp_output_path, 650, 630)
output_to_display_folder(output_files) output_to_display_folder(output_files)