Commit
·
9386e65
1
Parent(s):
d9d1ebe
Create facemace
Browse files
facemace
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
import mediapipe as mp
|
3 |
+
mp_drawing = mp.solutions.drawing_utils
|
4 |
+
mp_face_mesh = mp.solutions.face_mesh
|
5 |
+
|
6 |
+
drawing_spec = mp_drawing.DrawingSpec(thickness=1, circle_radius=1)
|
7 |
+
cap = cv2.VideoCapture(0)
|
8 |
+
with mp_face_mesh.FaceMesh(
|
9 |
+
min_detection_confidence=0.5,
|
10 |
+
min_tracking_confidence=0.5) as face_mesh:
|
11 |
+
while cap.isOpened():
|
12 |
+
success, image = cap.read()
|
13 |
+
if not success:
|
14 |
+
print("Ignoring empty camera frame.")
|
15 |
+
# If loading a video, use 'break' instead of 'continue'.
|
16 |
+
continue
|
17 |
+
|
18 |
+
# Flip the image horizontally for a later selfie-view display, and convert
|
19 |
+
# the BGR image to RGB.
|
20 |
+
image = cv2.cvtColor(cv2.flip(image, 1), cv2.COLOR_BGR2RGB)
|
21 |
+
# To improve performance, optionally mark the image as not writeable to
|
22 |
+
# pass by reference.
|
23 |
+
image.flags.writeable = False
|
24 |
+
results = face_mesh.process(image)
|
25 |
+
|
26 |
+
# Draw the face mesh annotations on the image.
|
27 |
+
image.flags.writeable = True
|
28 |
+
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
29 |
+
if results.multi_face_landmarks:
|
30 |
+
for face_landmarks in results.multi_face_landmarks:
|
31 |
+
#print(face_landmarks)
|
32 |
+
mp_drawing.draw_landmarks(
|
33 |
+
image=image,
|
34 |
+
landmark_list=face_landmarks,
|
35 |
+
connections=mp_face_mesh.FACE_CONNECTIONS,
|
36 |
+
landmark_drawing_spec=drawing_spec,
|
37 |
+
connection_drawing_spec=drawing_spec)
|
38 |
+
cv2.imshow('MediaPipe FaceMesh', image)
|
39 |
+
if cv2.waitKey(5) & 0xFF == 27:
|
40 |
+
break
|
41 |
+
cap.release()
|