fffiloni commited on
Commit
da2d10b
·
1 Parent(s): 848b9af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -10
app.py CHANGED
@@ -50,6 +50,26 @@ def predict(img):
50
  #vis_result = cv2.resize(vis_result, dsize=None, fx=0.5, fy=0.5)
51
  print(f"POSE_RESULTS: {pose_results}")
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  # create a black image of the same size as the original image
54
  black_img = np.zeros((width, height, 3), np.uint8)
55
 
@@ -59,22 +79,25 @@ def predict(img):
59
  keypoints = person['keypoints']
60
 
61
  # draw lines between keypoints to form a skeleton
62
- #skeleton = [(0,1), (1,2), (2,3), (3,4), (1,5), (5,6), (6,7), (1,8), (8,9), (9,10), (10,11), (8,12), (12,13), (13,14), (0,15), (15,16)]
63
- skeleton = [(0,1), (1,2), (3,4), (4,5), (2,6), (5,7), (2,3), (3,8), (8,9), (9,10), (10,11), (8,12), (12,13), (13,14), (1,0), (6,2), (11,5)]
64
- for i, j in skeleton:
65
- if keypoints[i][2] < 0.1 or keypoints[j][2] < 0.1:
66
- continue
67
- pt1 = (int(keypoints[i][0]), int(keypoints[i][1]))
68
- pt2 = (int(keypoints[j][0]), int(keypoints[j][1]))
69
- cv2.line(black_img, pt1, pt2, (255, 255, 255), thickness=2, lineType=cv2.LINE_AA)
 
 
 
 
70
 
71
  # draw circles at each keypoint
72
  for i in range(keypoints.shape[0]):
73
- if keypoints[i][2] < 0.1:
74
- continue
75
  pt = (int(keypoints[i][0]), int(keypoints[i][1]))
76
  cv2.circle(black_img, pt, 3, (255, 255, 255), thickness=-1, lineType=cv2.LINE_AA)
77
 
 
78
 
79
  # write black_img to a jpg file
80
 
 
50
  #vis_result = cv2.resize(vis_result, dsize=None, fx=0.5, fy=0.5)
51
  print(f"POSE_RESULTS: {pose_results}")
52
 
53
+ # define colors for each body part
54
+ colors = {
55
+ "nose": (255, 0, 0),
56
+ "left_eye": (0, 255, 0),
57
+ "right_eye": (0, 0, 255),
58
+ "left_ear": (255, 255, 0),
59
+ "right_ear": (0, 255, 255),
60
+ "left_shoulder": (255, 0, 255),
61
+ "right_shoulder": (128, 0, 128),
62
+ "left_elbow": (0, 128, 128),
63
+ "right_elbow": (128, 128, 0),
64
+ "left_wrist": (128, 128, 128),
65
+ "right_wrist": (0, 0, 0),
66
+ "left_hip": (255, 128, 0),
67
+ "right_hip": (0, 128, 255),
68
+ "left_knee": (128, 0, 255),
69
+ "right_knee": (255, 0, 128),
70
+ "left_ankle": (0, 255, 128),
71
+ "right_ankle": (128, 255, 0)
72
+ }
73
  # create a black image of the same size as the original image
74
  black_img = np.zeros((width, height, 3), np.uint8)
75
 
 
79
  keypoints = person['keypoints']
80
 
81
  # draw lines between keypoints to form a skeleton
82
+ skeleton = [("nose", "left_eye"), ("left_eye", "left_ear"), ("nose", "right_eye"), ("right_eye", "right_ear"),
83
+ ("left_shoulder", "right_shoulder"), ("left_shoulder", "left_elbow"), ("right_shoulder", "right_elbow"),
84
+ ("left_elbow", "left_wrist"), ("right_elbow", "right_wrist"), ("left_shoulder", "left_hip"),
85
+ ("right_shoulder", "right_hip"), ("left_hip", "right_hip"), ("left_hip", "left_knee"),
86
+ ("right_hip", "right_knee"), ("left_knee", "left_ankle"), ("right_knee", "right_ankle")]
87
+ for start_part, end_part in skeleton:
88
+ start_idx = BODY_PARTS[start_part]
89
+ end_idx = BODY_PARTS[end_part]
90
+ if keypoints[start_idx][2] > 0.1 and keypoints[end_idx][2] > 0.1:
91
+ pt1 = (int(keypoints[start_idx][0]), int(keypoints[start_idx][1]))
92
+ pt2 = (int(keypoints[end_idx][0]), int(keypoints[end_idx][1]))
93
+ cv2.line(black_img, pt1, pt2, colors[start_part], thickness=2, lineType=cv2.LINE_AA)
94
 
95
  # draw circles at each keypoint
96
  for i in range(keypoints.shape[0]):
 
 
97
  pt = (int(keypoints[i][0]), int(keypoints[i][1]))
98
  cv2.circle(black_img, pt, 3, (255, 255, 255), thickness=-1, lineType=cv2.LINE_AA)
99
 
100
+
101
 
102
  # write black_img to a jpg file
103