MCPcopy Create free account
hub / github.com/alpha2phi/python-apps / show_video

Function show_video

computer-vision/05_holistic.py:22–98  ·  view source on GitHub ↗
(capture)

Source from the content-addressed store, hash-verified

20
21
22def show_video(capture):
23 # cap = cv2.VideoCapture(0) # Capture from camera. Adjust the number
24 cap = cv2.VideoCapture(capture) # Capture from video
25
26 mp_drawing = mp.solutions.drawing_utils
27 mp_drawing_styles = mp.solutions.drawing_styles
28 mp_holistic = mp.solutions.holistic
29
30 try:
31 pTime = time.time()
32
33 with mp_holistic.Holistic(
34 min_detection_confidence=0.5, min_tracking_confidence=0.5
35 ) as holistic:
36
37 while cap.isOpened():
38 # Read from video capture device
39 success, img = cap.read()
40 if not success:
41 continue
42
43 # FPS
44 pTime, img = calculate_fps(img, pTime)
45
46 # Convert from BGR to RGB
47 img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
48
49 # To improve performance, optionally mark the image as not writeable to pass by reference.
50 img.flags.writeable = False
51
52 results = holistic.process(img)
53
54 # Draw the hand annotations on the image.
55 img.flags.writeable = True
56 img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
57
58 mp_drawing.draw_landmarks(
59 img,
60 results.face_landmarks,
61 mp_holistic.FACEMESH_CONTOURS,
62 landmark_drawing_spec=None,
63 connection_drawing_spec=mp_drawing_styles.get_default_face_mesh_contours_style(),
64 )
65 mp_drawing.draw_landmarks(
66 img,
67 results.pose_landmarks,
68 mp_holistic.POSE_CONNECTIONS,
69 landmark_drawing_spec=mp_drawing_styles.get_default_pose_landmarks_style(),
70 )
71
72 mp_drawing.draw_landmarks(
73 img,
74 results.right_hand_landmarks,
75 mp_holistic.HAND_CONNECTIONS,
76 landmark_drawing_spec=mp_drawing_styles.get_default_hand_landmarks_style(),
77 connection_drawing_spec=mp_drawing_styles.get_default_hand_connections_style(),
78 )
79

Callers 1

05_holistic.pyFile · 0.70

Calls 1

calculate_fpsFunction · 0.70

Tested by

no test coverage detected