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
|
# 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))
|
#try:
|
||||||
predicted[:, :, 3] = 1
|
# predicted = pred.predict_pose_keypoints(np.array(coordinates, dtype=np.float32).copy().reshape(1, 18, 3))
|
||||||
return predicted.flatten().tolist()
|
# # 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
|
# for now, just mirror the coordinates and add some random deviation
|
||||||
predicted_coordinates = mirror_coordinates(coordinates, width)
|
predicted_coordinates = mirror_coordinates(coordinates, width)
|
||||||
|
@ -96,9 +106,10 @@ def get_predicted_coordinates(coordinates: list, width: int, height: int) -> lis
|
||||||
return predicted_coordinates
|
return predicted_coordinates
|
||||||
|
|
||||||
def mirror_coordinates(coordinates: list, width: int) -> list:
|
def mirror_coordinates(coordinates: list, width: int) -> list:
|
||||||
|
mirrored = coordinates.copy()
|
||||||
for i in range(0, len(coordinates), 3):
|
for i in range(0, len(coordinates), 3):
|
||||||
coordinates[i] = width - coordinates[i]
|
mirrored[i] = width - coordinates[i]
|
||||||
return coordinates
|
return mirrored
|
||||||
|
|
||||||
def expo_fencer_prompt(openpose_image_path, save_dir, batch, step):
|
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'])
|
@app.route('/expo_postprocess', methods=['POST'])
|
||||||
async def expo_postprocess():
|
async def expo_postprocess():
|
||||||
global on_postprocessing
|
global on_postprocessing
|
||||||
if on_postprocessing:
|
try:
|
||||||
return jsonify({"status": "error", "message": "Postprocessing in progress"}), 503
|
if on_postprocessing:
|
||||||
|
return jsonify({"status": "error", "message": "Postprocessing in progress"}), 503
|
||||||
on_postprocessing = True
|
|
||||||
print("Postprocessing")
|
on_postprocessing = True
|
||||||
|
print("pending postprocessing")
|
||||||
|
|
||||||
# Wait until the directories have the same files or timeout
|
# 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):
|
if not await wait_for_files_to_match(expo_openpose_dir, expo_raw_sd_dir):
|
||||||
print("Timeout reached, proceeding with postprocessing")
|
print("Timeout reached, proceeding with postprocessing")
|
||||||
|
|
||||||
# Check if directories exist and are not empty
|
# Check if directories exist and are not empty
|
||||||
if not os.path.exists(expo_openpose_dir) or not os.listdir(expo_openpose_dir):
|
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
|
on_postprocessing = False
|
||||||
return jsonify({"status": "error", "message": "No images to process in expo_openpose_dir"}), 404
|
print(e)
|
||||||
if not os.path.exists(expo_raw_sd_dir) or not os.listdir(expo_raw_sd_dir):
|
return jsonify({"status": "error", "message": "An error occurred during postprocessing"}), 500
|
||||||
|
finally:
|
||||||
on_postprocessing = False
|
on_postprocessing = False
|
||||||
return jsonify({"status": "error", "message": "No images to process in expo_raw_sd_dir"}), 404
|
await asyncio.to_thread(expo_clear_images)
|
||||||
|
print("Postprocessing completed")
|
||||||
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 = 180, interval: int = 1) -> bool:
|
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']
|
canvas_size = data['canvas_size']
|
||||||
pid = data['pid']
|
pid = data['pid']
|
||||||
base_image = base64.b64decode(data['base_image'])
|
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:
|
if not coordinates_list or not canvas_size or not base_image or not pid:
|
||||||
return jsonify({"status": "error", "message": "Missing data"}), 422
|
return jsonify({"status": "error", "message": "Missing data"}), 422
|
||||||
|
|
Loading…
Reference in New Issue