From 4836fb3d6eb116c39ac73d117d882f5058317049 Mon Sep 17 00:00:00 2001 From: zaqxs123456 <18200842@life.hkbu.edu.hk> Date: Fri, 25 Oct 2024 15:53:59 +0800 Subject: [PATCH] more fix --- app.py | 8 ++++---- postprocessing.py | 22 +++++++++++----------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/app.py b/app.py index 218c078..f0556a8 100644 --- a/app.py +++ b/app.py @@ -27,7 +27,7 @@ expo_raw_sd_dir = info['expo_raw_sd_dir'] expo_openpose_dir = info['expo_openpose_dir'] on_postprocessing = False -on_testing = False +on_testing = True @app.route('/expo_fencing_pose', methods=['POST']) 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: 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') 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_clear_images) on_postprocessing = False - + print("Postprocessing completed") 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() while asyncio.get_event_loop().time() - start_time < timeout: files1 = get_all_files(dir1) diff --git a/postprocessing.py b/postprocessing.py index 0605a13..b1302cf 100644 --- a/postprocessing.py +++ b/postprocessing.py @@ -119,13 +119,13 @@ def expo_motion_blur_fencer(image_path: str, output_path: str, sigma: float, dir subprocess.run(command, check=True) 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 = [] with ThreadPoolExecutor() as executor: for i, image_path in enumerate(path_list): 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) futures.append(future) @@ -217,24 +217,24 @@ def expo_postprocess_main(): output_files = [] for i, candidate_list in enumerate(left_shuffled_images_paths): - left_fencer_paths = expo_resize_fencers(candidate_list, True, 500, 500) - expo_motion_blur_fencers(left_fencer_paths, True) + left_fencer_paths = expo_resize_fencers(candidate_list, True, 450, 450) + expo_motion_blur_fencers(left_fencer_paths) expo_decrese_opacities(left_fencer_paths) temp_output_path = os.path.join(expo_postprocess_temp_dir, f"temp_{i}.png") output_files.append(temp_output_path) temp_background_path = background_path for j, left_fencer_path in enumerate(left_fencer_paths): - x_position = 65 * math.pow(j, 1.3) - 132 - y_position = 192 + x_position = 34 * math.pow(j, 1.3) - 100 + y_position = 170 expo_add_to_background_image(temp_background_path, left_fencer_path, temp_output_path, x_position, y_position) temp_background_path = temp_output_path for i, candidate_list in enumerate(right_shuffled_images_paths): if i > len(left_shuffled_images_paths) - 1: break - right_fencer_paths = expo_resize_fencers(candidate_list, False, 500, 500) - expo_motion_blur_fencers(right_fencer_paths, False) + right_fencer_paths = expo_resize_fencers(candidate_list, False, 450, 450) + expo_motion_blur_fencers(right_fencer_paths) expo_decrese_opacities(right_fencer_paths) temp_output_path = os.path.join(expo_postprocess_temp_dir, f"temp_{i}.png") @@ -242,13 +242,13 @@ def expo_postprocess_main(): break for j, right_fencer_path in enumerate(right_fencer_paths): - x_position = 1080 - (65 * math.pow(j, 1.3) - 132) - y_position = 192 + x_position = 540 - (34 * math.pow(j, 1.3) - 170) + y_position = 170 expo_add_to_background_image(temp_output_path, right_fencer_path, temp_output_path, x_position, y_position) temp_background_path = temp_output_path 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)