1515
1616tasks = set ()
1717
18- # You can download a face landmark model file from https://developers.google.com/mediapipe/solutions/vision/face_landmarker#models
19- model_file = "face_landmarker.task"
20- model_path = os .path .dirname (os .path .realpath (__file__ )) + "/" + model_file
21-
22- BaseOptions = mp .tasks .BaseOptions
23- FaceLandmarker = mp .tasks .vision .FaceLandmarker
24- FaceLandmarkerOptions = mp .tasks .vision .FaceLandmarkerOptions
25- VisionRunningMode = mp .tasks .vision .RunningMode
26-
27- options = FaceLandmarkerOptions (
28- base_options = BaseOptions (model_asset_path = model_path ),
29- running_mode = VisionRunningMode .VIDEO ,
30- )
31-
3218
3319async def main (room : rtc .Room ) -> None :
3420 video_stream = None
@@ -103,7 +89,6 @@ def draw_landmarks_on_image(rgb_image, detection_result):
10389
10490
10591async def frame_loop (video_stream : rtc .VideoStream ) -> None :
106- landmarker = FaceLandmarker .create_from_options (options )
10792 cv2 .namedWindow ("livekit_video" , cv2 .WINDOW_AUTOSIZE )
10893 cv2 .startWindowThread ()
10994 async for frame_event in video_stream :
@@ -112,19 +97,11 @@ async def frame_loop(video_stream: rtc.VideoStream) -> None:
11297 arr = np .frombuffer (buffer .data , dtype = np .uint8 )
11398 arr = arr .reshape ((buffer .height , buffer .width , 3 ))
11499
115- mp_image = mp .Image (image_format = mp .ImageFormat .SRGB , data = arr )
116- detection_result = landmarker .detect_for_video (
117- mp_image , frame_event .timestamp_us
118- )
119-
120- draw_landmarks_on_image (arr , detection_result )
121-
122100 arr = cv2 .cvtColor (arr , cv2 .COLOR_RGB2BGR )
123101 cv2 .imshow ("livekit_video" , arr )
124102 if cv2 .waitKey (1 ) & 0xFF == ord ("q" ):
125103 break
126104
127- landmarker .close ()
128105 cv2 .destroyAllWindows ()
129106
130107
0 commit comments