fffiloni commited on
Commit
79cf760
·
1 Parent(s): bb76ef3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -28
app.py CHANGED
@@ -51,24 +51,24 @@ def predict(img):
51
  print(f"POSE_RESULTS: {pose_results}")
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
@@ -80,23 +80,23 @@ def predict(img):
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]):
98
- pt = (int(keypoints[i][0]), int(keypoints[i][1]))
99
- cv2.circle(black_img, pt, 3, (255, 255, 255), thickness=-1, lineType=cv2.LINE_AA)
100
 
101
 
102
 
 
51
  print(f"POSE_RESULTS: {pose_results}")
52
 
53
  # define colors for each body part
54
+ body_part = {
55
+ "nose": 0,
56
+ "left_eye": 1,
57
+ "right_eye": 2,
58
+ "left_ear": 3,
59
+ "right_ear": 4,
60
+ "left_shoulder": 5,
61
+ "right_shoulder": 6,
62
+ "left_elbow": 7,
63
+ "right_elbow": 8,
64
+ "left_wrist": 9,
65
+ "right_wrist": 10,
66
+ "left_hip": 11,
67
+ "right_hip": 12,
68
+ "left_knee": 13,
69
+ "right_knee": 14,
70
+ "left_ankle": 15,
71
+ "right_ankle": 16
72
  }
73
 
74
  # create a black image of the same size as the original image
 
80
  keypoints = person['keypoints']
81
 
82
  # draw lines between keypoints to form a skeleton
83
+ skeleton = [("right_eye", "left_eye", (255,128,0)),("nose", "left_eye", (255,128,0)), ("left_eye", "left_ear", (255,128,0)), ("nose", "right_eye", (255,128,0)), ("right_eye", "right_ear", (255,128,0)),
84
+ ("left_shoulder", "left_ear", (255,128,0)),("right_shoulder", "right_ear", (255,128,0)), ("left_shoulder", "right_shoulder", (255,128,0)), ("left_shoulder", "left_elbow", (0, 255, 0)), ("right_shoulder", "right_elbow",(51,153,255)),
85
+ ("left_elbow", "left_wrist",(0, 255, 0)), ("right_elbow", "right_wrist",(51,153,255)), ("left_shoulder", "left_hip",(255,128,0)),
86
+ ("right_shoulder", "right_hip", (255,128,0)), ("left_hip", "right_hip", (255,128,0)), ("left_hip", "left_knee",(0, 255, 0)),
87
+ ("right_hip", "right_knee",(51,153,255)), ("left_knee", "left_ankle",(0, 255, 0)), ("right_knee", "right_ankle",(51,153,255))]
88
  for start_part, end_part, color in skeleton:
89
+ start_idx = list(body_part.keys()).index(start_part)
90
+ end_idx = list(body_part.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]):
98
+ # pt = (int(keypoints[i][0]), int(keypoints[i][1]))
99
+ # cv2.circle(black_img, pt, 3, (255, 255, 255), thickness=-1, lineType=cv2.LINE_AA)
100
 
101
 
102