fffiloni commited on
Commit
cc1cb8d
·
1 Parent(s): 21e82dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -24
app.py CHANGED
@@ -52,24 +52,25 @@ def predict(img):
52
 
53
  # define colors for each body part
54
  body_part_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,18 +80,18 @@ def predict(img):
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 = list(body_part_colors.keys()).index(start_part)
89
  end_idx = list(body_part_colors.keys()).index(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, body_part_colors[start_part], thickness=2, lineType=cv2.LINE_AA)
94
 
95
  # draw circles at each keypoint
96
  for i in range(keypoints.shape[0]):
 
52
 
53
  # define colors for each body part
54
  body_part_colors = {
55
+ "nose": (255, 165, 0),
56
+ "left_eye": (255, 165, 0),
57
+ "right_eye": (255, 165, 0),
58
+ "left_ear": (255, 165, 0),
59
+ "right_ear": (255, 165, 0),
60
+ "left_shoulder": (0, 128, 0),
61
+ "right_shoulder": (0, 0, 255),
62
+ "left_elbow": (0, 128, 0),
63
+ "right_elbow": (0, 0, 255),
64
+ "left_wrist": (0, 128, 0),
65
+ "right_wrist": (0, 0, 255),
66
+ "left_hip": (0, 128, 0),
67
+ "right_hip": (0, 0, 255),
68
+ "left_knee": (0, 128, 0),
69
+ "right_knee": (0, 0, 255),
70
+ "left_ankle": (0, 128, 0),
71
+ "right_ankle": (0, 0, 255)
72
  }
73
+
74
  # create a black image of the same size as the original image
75
  black_img = np.zeros((width, height, 3), np.uint8)
76
 
 
80
  keypoints = person['keypoints']
81
 
82
  # draw lines between keypoints to form a skeleton
83
+ skeleton = [("right_eye", "left_eye", (255, 165, 0)),("nose", "left_eye", (255, 165, 0)), ("left_eye", "left_ear", (255, 165, 0)), ("nose", "right_eye", (255, 165, 0)), ("right_eye", "right_ear", (255, 165, 0)),
84
+ ("left_shoulder", "left_ear", (255, 165, 0)),("right_shoulder", "right_ear", (255, 165, 0)), ("left_shoulder", "right_shoulder", (255, 165, 0)), ("left_shoulder", "left_elbow", (0, 128, 0)), ("right_shoulder", "right_elbow",(0, 0, 255)),
85
+ ("left_elbow", "left_wrist",(0, 128, 0), ("right_elbow", "right_wrist",(0, 0, 255)), ("left_shoulder", "left_hip",(255, 165, 0)),
86
+ ("right_shoulder", "right_hip", (255, 165, 0)), ("left_hip", "right_hip", (255, 165, 0)), ("left_hip", "left_knee",(0, 128, 0)),
87
+ ("right_hip", "right_knee",(0, 0, 255)), ("left_knee", "left_ankle",(0, 128, 0)), ("right_knee", "right_ankle",(0, 0, 255))]
88
+ for start_part, end_part, color in skeleton:
89
  start_idx = list(body_part_colors.keys()).index(start_part)
90
  end_idx = list(body_part_colors.keys()).index(end_part)
91
  if keypoints[start_idx][2] > 0.1 and keypoints[end_idx][2] > 0.1:
92
  pt1 = (int(keypoints[start_idx][0]), int(keypoints[start_idx][1]))
93
  pt2 = (int(keypoints[end_idx][0]), int(keypoints[end_idx][1]))
94
+ cv2.line(black_img, pt1, pt2, color, thickness=2, lineType=cv2.LINE_AA)
95
 
96
  # draw circles at each keypoint
97
  for i in range(keypoints.shape[0]):