Spaces:
Paused
Paused
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
@@ -12,21 +12,21 @@ def prepare_image(img_path):
|
|
12 |
body_bboxes, body_keypoints = pose_result.boxes, pose_result.keypoints
|
13 |
# generate heatmap
|
14 |
heatmap = get_heatmap(img_path)
|
15 |
-
heatmap_pil = Image.fromarray(heatmap)
|
16 |
# pose on heatmap
|
17 |
-
heatmap_n_pose = draw_pose(heatmap_pil,body_keypoints) #PIL.Image
|
18 |
|
19 |
# area in bounding_box below head (rectangular)
|
20 |
-
face_y1,
|
21 |
-
|
22 |
-
body_box = body_bboxes.numpy().
|
23 |
-
body_box[1] =
|
24 |
|
25 |
# Calculate the coordinates for cropping
|
26 |
-
|
27 |
-
cropped_region = heatmap_n_pose.crop((
|
28 |
original_image = Image.open(img_path)
|
29 |
-
original_image.paste(cropped_region, (
|
30 |
|
31 |
# Return the modified image
|
32 |
return original_image
|
|
|
12 |
body_bboxes, body_keypoints = pose_result.boxes, pose_result.keypoints
|
13 |
# generate heatmap
|
14 |
heatmap = get_heatmap(img_path)
|
15 |
+
heatmap_pil = Image.fromarray(heatmap).convert('RGB')
|
16 |
# pose on heatmap
|
17 |
+
heatmap_n_pose = draw_pose(heatmap_pil,body_keypoints,0.5) #PIL.Image
|
18 |
|
19 |
# area in bounding_box below head (rectangular)
|
20 |
+
face_y1, face_h = face_bboxes[0][1], face_bboxes[0][2] #xywh of first face
|
21 |
+
face_y2 = face_y1 + face_h
|
22 |
+
body_box = body_bboxes.numpy().xyxy[0]
|
23 |
+
body_box[1] = face_y2 #shift below head
|
24 |
|
25 |
# Calculate the coordinates for cropping
|
26 |
+
x1, y1, x2, y2 = map(int, body_box)
|
27 |
+
cropped_region = heatmap_n_pose.crop((x1, y1, x2, y2))
|
28 |
original_image = Image.open(img_path)
|
29 |
+
original_image.paste(cropped_region, (x1, y1))
|
30 |
|
31 |
# Return the modified image
|
32 |
return original_image
|