andro-flock commited on
Commit
6e98be6
·
verified ·
1 Parent(s): 0d66750

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +9 -9
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, face_w = face_bboxes[0][1] #xywh
21
- face_center_y = (face_w - face_y1) // 2
22
- body_box = body_bboxes.numpy().xywh[0]
23
- body_box[1] = face_center_y
24
 
25
  # Calculate the coordinates for cropping
26
- x, y, w, h = map(int, body_box)
27
- cropped_region = heatmap_n_pose.crop((x, y, x + w, y + h))
28
  original_image = Image.open(img_path)
29
- original_image.paste(cropped_region, (x, y))
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