-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
51 lines (37 loc) · 1.56 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import cv2
import mediapipe as mp
def main():
capture = cv2.VideoCapture(0)
mp_pose = mp.solutions.pose
pose = mp_pose.Pose()
mp_draw = mp.solutions.drawing_utils
success, img = capture.read()
h, w, c = img.shape
fourcc = cv2.VideoWriter_fourcc(*'MPV4')
writer = cv2.VideoWriter('output.mp4', fourcc, 20.0, (w, h))
while success:
success, img = capture.read()
results = pose.process(img)
cv2.putText(img, "Do some jumping jacks", (0, 20), 0, 1, (255, 255, 255), 3)
# cv2.putText(img, "Do some squats", (0, 20), 0, 1, (255, 255, 255), 3)
if results.pose_landmarks:
mp_draw.draw_landmarks(img, results.pose_landmarks, mp_pose.POSE_CONNECTIONS)
landmarks = results.pose_landmarks.landmark
# Jumping jacks
if landmarks[14].y < landmarks[0].y:
cv2.putText(img, "Good! Now lower your arms.", (0, 100), 0, 1, (255, 255, 255), 3)
else:
cv2.putText(img, "Raise your arms above your head!", (0, 100), 0, 1, (255, 255, 255), 3)
# Squats
# if landmarks[24].y < landmarks[26].y:
# cv2.putText(img, "Bend your knees and lower your body", (0, 100), 0, 1, (255, 255, 255), 3)
# else:
# cv2.putText(img, "Great! Stand up and do it again!", (0, 100), 0, 1, (255, 255, 255), 3)
writer.write(img)
cv2.imshow('Image', img)
cv2.waitKey(1)
capture.release()
writer.release()
cv2.destroyAllWindows()
if __name__ == '__main__':
main()