bump
This commit is contained in:
parent
5268543b7a
commit
624eba00b0
71
app.py
71
app.py
|
@ -81,9 +81,19 @@ def get_predicted_coordinates(coordinates: list, width: int, height: int) -> lis
|
|||
|
||||
# when testing, can visualize with the method expo_save_bodypose in openpose_gen.py
|
||||
|
||||
predicted = pred.predict_pose_keypoints(np.array(coordinates).reshape(1, 18, 3))
|
||||
predicted[:, :, 3] = 1
|
||||
return predicted.flatten().tolist()
|
||||
#try:
|
||||
# predicted = pred.predict_pose_keypoints(np.array(coordinates, dtype=np.float32).copy().reshape(1, 18, 3))
|
||||
# # add confidence score
|
||||
# predicted = np.concatenate((predicted, np.ones((1, 18, 1))), axis=2)
|
||||
# print(predicted.flatten().tolist())
|
||||
# print('done')
|
||||
# return predicted.flatten().tolist()
|
||||
#except Exception as e:
|
||||
# print(e)
|
||||
# pass
|
||||
|
||||
#predicted[:, :, 3] = 1
|
||||
#return predicted.flatten().tolist()
|
||||
|
||||
# for now, just mirror the coordinates and add some random deviation
|
||||
predicted_coordinates = mirror_coordinates(coordinates, width)
|
||||
|
@ -96,9 +106,10 @@ def get_predicted_coordinates(coordinates: list, width: int, height: int) -> lis
|
|||
return predicted_coordinates
|
||||
|
||||
def mirror_coordinates(coordinates: list, width: int) -> list:
|
||||
mirrored = coordinates.copy()
|
||||
for i in range(0, len(coordinates), 3):
|
||||
coordinates[i] = width - coordinates[i]
|
||||
return coordinates
|
||||
mirrored[i] = width - coordinates[i]
|
||||
return mirrored
|
||||
|
||||
def expo_fencer_prompt(openpose_image_path, save_dir, batch, step):
|
||||
|
||||
|
@ -136,29 +147,37 @@ def expo_clear_images():
|
|||
@app.route('/expo_postprocess', methods=['POST'])
|
||||
async def expo_postprocess():
|
||||
global on_postprocessing
|
||||
if on_postprocessing:
|
||||
return jsonify({"status": "error", "message": "Postprocessing in progress"}), 503
|
||||
|
||||
on_postprocessing = True
|
||||
print("Postprocessing")
|
||||
try:
|
||||
if on_postprocessing:
|
||||
return jsonify({"status": "error", "message": "Postprocessing in progress"}), 503
|
||||
|
||||
on_postprocessing = True
|
||||
print("pending postprocessing")
|
||||
|
||||
# Wait until the directories have the same files or timeout
|
||||
if not await wait_for_files_to_match(expo_openpose_dir, expo_raw_sd_dir):
|
||||
print("Timeout reached, proceeding with postprocessing")
|
||||
# Wait until the directories have the same files or timeout
|
||||
if not await wait_for_files_to_match(expo_openpose_dir, expo_raw_sd_dir):
|
||||
print("Timeout reached, proceeding with postprocessing")
|
||||
|
||||
# Check if directories exist and are not empty
|
||||
if not os.path.exists(expo_openpose_dir) or not os.listdir(expo_openpose_dir):
|
||||
# Check if directories exist and are not empty
|
||||
if not os.path.exists(expo_openpose_dir) or not os.listdir(expo_openpose_dir):
|
||||
on_postprocessing = False
|
||||
return jsonify({"status": "error", "message": "No images to process in expo_openpose_dir"}), 404
|
||||
if not os.path.exists(expo_raw_sd_dir) or not os.listdir(expo_raw_sd_dir):
|
||||
on_postprocessing = False
|
||||
return jsonify({"status": "error", "message": "No images to process in expo_raw_sd_dir"}), 404
|
||||
|
||||
print("Postprocessing")
|
||||
|
||||
await asyncio.to_thread(expo_postprocess_main)
|
||||
return jsonify({"status": "success", "message": "Postprocessing completed"}), 200
|
||||
except Exception as e:
|
||||
on_postprocessing = False
|
||||
return jsonify({"status": "error", "message": "No images to process in expo_openpose_dir"}), 404
|
||||
if not os.path.exists(expo_raw_sd_dir) or not os.listdir(expo_raw_sd_dir):
|
||||
print(e)
|
||||
return jsonify({"status": "error", "message": "An error occurred during postprocessing"}), 500
|
||||
finally:
|
||||
on_postprocessing = False
|
||||
return jsonify({"status": "error", "message": "No images to process in expo_raw_sd_dir"}), 404
|
||||
|
||||
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
|
||||
await asyncio.to_thread(expo_clear_images)
|
||||
print("Postprocessing completed")
|
||||
|
||||
|
||||
async def wait_for_files_to_match(dir1: str, dir2: str, timeout: int = 180, interval: int = 1) -> bool:
|
||||
|
@ -208,6 +227,10 @@ def gen_group_pic():
|
|||
canvas_size = data['canvas_size']
|
||||
pid = data['pid']
|
||||
base_image = base64.b64decode(data['base_image'])
|
||||
# resize base image to 1280x720
|
||||
#base_image = cv2.imdecode(np.frombuffer(base_image, np.uint8), cv2.IMREAD_COLOR)
|
||||
#base_image = cv2.resize(base_image, (1280, 720))
|
||||
#base_image = cv2.imencode('.png', base_image)[1].tobytes()
|
||||
|
||||
if not coordinates_list or not canvas_size or not base_image or not pid:
|
||||
return jsonify({"status": "error", "message": "Missing data"}), 422
|
||||
|
|
Loading…
Reference in New Issue