From bb497ac8aafad27c6971e1754fd4e0414a6bec36 Mon Sep 17 00:00:00 2001 From: AK391 Date: Thu, 10 Jun 2021 22:26:43 +0000 Subject: [PATCH] add demo file --- gradio/demo.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 gradio/demo.py diff --git a/gradio/demo.py b/gradio/demo.py new file mode 100644 index 000000000..a158423b1 --- /dev/null +++ b/gradio/demo.py @@ -0,0 +1,31 @@ +import mediapipe as mp +import gradio as gr +mp_face_mesh = mp.solutions.face_mesh + +# Prepare DrawingSpec for drawing the face landmarks later. +mp_drawing = mp.solutions.drawing_utils +drawing_spec = mp_drawing.DrawingSpec(thickness=1, circle_radius=1) + +# Run MediaPipe Face Mesh. + +def inference(image): + with mp_face_mesh.FaceMesh( + static_image_mode=True, + max_num_faces=2, + min_detection_confidence=0.5) as face_mesh: + # Convert the BGR image to RGB and process it with MediaPipe Face Mesh. + results = face_mesh.process(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)) + + # Draw face landmarks of each face. + print(f'Face landmarks of {name}:') + if not results.multi_face_landmarks: + continue + annotated_image = image.copy() + for face_landmarks in results.multi_face_landmarks: + mp_drawing.draw_landmarks( + image=annotated_image, + landmark_list=face_landmarks, + connections=mp_face_mesh.FACE_CONNECTIONS, + landmark_drawing_spec=drawing_spec, + connection_drawing_spec=drawing_spec) + return annotated_image \ No newline at end of file