MCPcopy Create free account
hub / github.com/dkpython7/open-cv-projects- / process_frame

Method process_frame

GYM/main.py:38–145  ·  view source on GitHub ↗
(self, frame)

Source from the content-addressed store, hash-verified

36 return x, y, w_box, h_box
37
38 def process_frame(self, frame):
39 h, w = frame.shape[:2]
40
41 image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
42 image.flags.writeable = False
43
44 results = self.pose.process(image)
45
46 image.flags.writeable = True
47 image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
48
49 try:
50 if results.pose_landmarks:
51 landmarks = results.pose_landmarks.landmark
52
53 left_wrist = landmarks[self.mp_pose.PoseLandmark.LEFT_WRIST.value]
54 right_wrist = landmarks[self.mp_pose.PoseLandmark.RIGHT_WRIST.value]
55 nose = landmarks[self.mp_pose.PoseLandmark.NOSE.value]
56
57 left_wrist_pos = (int(left_wrist.x * w), int(left_wrist.y * h))
58 right_wrist_pos = (int(right_wrist.x * w), int(right_wrist.y * h))
59 nose_pos = (int(nose.x * w), int(nose.y * h))
60
61 self.bar_y = (left_wrist_pos[1] + right_wrist_pos[1]) // 2
62
63 bar_start = (0, self.bar_y)
64 bar_end = (w, self.bar_y)
65 cv2.line(image, bar_start, bar_end, (0, 255, 0), 3)
66 cv2.putText(image, 'Pulling Bar',
67 (w//2 - 60, self.bar_y - 10),
68 cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 0), 2, cv2.LINE_AA)
69
70 left_hand_indices = [
71 self.mp_pose.PoseLandmark.LEFT_WRIST.value,
72 self.mp_pose.PoseLandmark.LEFT_THUMB.value,
73 self.mp_pose.PoseLandmark.LEFT_PINKY.value,
74 self.mp_pose.PoseLandmark.LEFT_INDEX.value
75 ]
76 lh_x, lh_y, lh_w, lh_h = self.get_bounding_box(landmarks, left_hand_indices, frame.shape)
77
78 right_hand_indices = [
79 self.mp_pose.PoseLandmark.RIGHT_WRIST.value,
80 self.mp_pose.PoseLandmark.RIGHT_THUMB.value,
81 self.mp_pose.PoseLandmark.RIGHT_PINKY.value,
82 self.mp_pose.PoseLandmark.RIGHT_INDEX.value
83 ]
84 rh_x, rh_y, rh_w, rh_h = self.get_bounding_box(landmarks, right_hand_indices, frame.shape)
85
86 head_indices = [
87 self.mp_pose.PoseLandmark.NOSE.value,
88 self.mp_pose.PoseLandmark.LEFT_EYE.value,
89 self.mp_pose.PoseLandmark.RIGHT_EYE.value,
90 self.mp_pose.PoseLandmark.LEFT_EAR.value,
91 self.mp_pose.PoseLandmark.RIGHT_EAR.value
92 ]
93 head_x, head_y, head_w, head_h = self.get_bounding_box(landmarks, head_indices, frame.shape)
94
95 cv2.rectangle(image, (lh_x, lh_y), (lh_x + lh_w, lh_y + lh_h), (255, 0, 0), 2)

Callers 1

runMethod · 0.95

Calls 1

get_bounding_boxMethod · 0.95

Tested by

no test coverage detected