-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
44 lines (31 loc) · 1.11 KB
/
main.py
File metadata and controls
44 lines (31 loc) · 1.11 KB
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
import cv2
import mediapipe as mp
import numpy as np
mp_pose = mp.solutions.pose
pose = mp_pose.Pose()
mp_drawing = mp.solutions.drawing_utils
cap = cv2.VideoCapture(0)
width, height = 1920, 1080
cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
pose_bg = np.zeros((height, width, 3), dtype=np.uint8)
landmarks_present = 0
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
results = pose.process(frame_rgb)
if results.pose_landmarks:
if landmarks_present == 0:
mp_drawing.draw_landmarks(pose_bg, results.pose_landmarks, mp_pose.POSE_CONNECTIONS)
landmarks_present = 1
else:
pose_bg = np.zeros((height, width, 3), dtype=np.uint8)
mp_drawing.draw_landmarks(pose_bg, results.pose_landmarks, mp_pose.POSE_CONNECTIONS)
cv2.imshow('Body Tracking', pose_bg)
cv2.imshow('Camera Footage', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()