(capture)
| 20 | |
| 21 | |
| 22 | def 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_pose = mp.solutions.pose |
| 29 | |
| 30 | try: |
| 31 | pTime = time.time() |
| 32 | |
| 33 | with mp_pose.Pose( |
| 34 | min_detection_confidence=0.5, min_tracking_confidence=0.5 |
| 35 | ) as pose: |
| 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 = pose.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.pose_landmarks, |
| 61 | mp_pose.POSE_CONNECTIONS, |
| 62 | landmark_drawing_spec=mp_drawing_styles.get_default_pose_landmarks_style(), |
| 63 | ) |
| 64 | |
| 65 | # Show video |
| 66 | if img is not None: |
| 67 | cv2.imshow("Face mesh", img) |
| 68 | |
| 69 | # Wait for key to exit |
| 70 | if cv2.waitKey(10) & 0xFF == ord("q"): |
| 71 | break |
| 72 | |
| 73 | finally: |
| 74 | cap.release() |
| 75 | cv2.destroyAllWindows() |
| 76 | |
| 77 | |
| 78 | if __name__ == "__main__": |
no test coverage detected