한종서 2024. 7. 30. 16:33
import cv2
import mediapipe as mp

cam = cv2.VideoCapture(0)

mp_face = mp.solutions.face_mesh
mp_drawing = mp.solutions.drawing_utils
face = mp_face.FaceMesh(refine_landmarks=True)

line_style=mp_drawing.DrawingSpec(
    color=(166,151,18),
    thickness=5
)

circle_style=mp_drawing.DrawingSpec(
    color=(166,115,31),
    thickness=2,
    circle_radius=5
)

cv2.namedWindow('face')

while( cv2.getWindowProperty('face', cv2.WND_PROP_VISIBLE)):
    check, frame = cam.read()
    if not check:
        break
    image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    results=face.process(image)
    if results.multi_face_landmarks:
        lm=results.multi_face_landmarks[0]
       
        mp_drawing.draw_landmarks(
            frame, lm, mp_face.FACEMESH_TESSELATION, circle_style, line_style
        )
    cv2.imshow('face',frame)
    if cv2.waitKey(1)==27:
        break