(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_face_mesh = mp.solutions.face_mesh |
| 29 | drawing_spec = mp_drawing.DrawingSpec(thickness=1, circle_radius=1) |
| 30 | |
| 31 | try: |
| 32 | pTime = time.time() |
| 33 | |
| 34 | with mp_face_mesh.FaceMesh( |
| 35 | min_detection_confidence=0.5, min_tracking_confidence=0.5 |
| 36 | ) as face_mesh: |
| 37 | |
| 38 | while cap.isOpened(): |
| 39 | # Read from video capture device |
| 40 | success, img = cap.read() |
| 41 | if not success: |
| 42 | continue |
| 43 | |
| 44 | # FPS |
| 45 | pTime, img = calculate_fps(img, pTime) |
| 46 | |
| 47 | # Convert from BGR to RGB |
| 48 | img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) |
| 49 | |
| 50 | # To improve performance, optionally mark the image as not writeable to pass by reference. |
| 51 | img.flags.writeable = False |
| 52 | |
| 53 | results = face_mesh.process(img) |
| 54 | |
| 55 | # Draw the hand annotations on the image. |
| 56 | img.flags.writeable = True |
| 57 | img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR) |
| 58 | |
| 59 | if results.multi_face_landmarks: |
| 60 | for face_landmarks in results.multi_face_landmarks: |
| 61 | mp_drawing.draw_landmarks( |
| 62 | image=img, |
| 63 | landmark_list=face_landmarks, |
| 64 | connections=mp_face_mesh.FACEMESH_TESSELATION, |
| 65 | landmark_drawing_spec=None, |
| 66 | connection_drawing_spec=mp_drawing_styles.get_default_face_mesh_tesselation_style(), |
| 67 | ) |
| 68 | mp_drawing.draw_landmarks( |
| 69 | image=img, |
| 70 | landmark_list=face_landmarks, |
| 71 | connections=mp_face_mesh.FACEMESH_CONTOURS, |
| 72 | landmark_drawing_spec=None, |
| 73 | connection_drawing_spec=mp_drawing_styles.get_default_face_mesh_contours_style(), |
| 74 | ) |
| 75 | |
| 76 | # Show video |
| 77 | if img is not None: |
| 78 | cv2.imshow("Face mesh", img) |
| 79 |
no test coverage detected