You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.3 KiB
Python

1 year ago
# Imports
import cv2
import mediapipe as mp
# Face Class
class Face:
# Constructor Function
def __init__(self, faces, thickness, circle_radius):
self.video = cv2.VideoCapture(0)
self.image = None
self.mpDraw = mp.solutions.drawing_utils
self.mpFaceMesh = mp.solutions.face_mesh
self.faceMesh = self.mpFaceMesh.FaceMesh(max_num_faces=faces)
self.drawSpec = self.mpDraw.DrawingSpec(thickness=thickness, circle_radius=circle_radius)
self.points = []
self.faces = 0
# Track
def track(self):
success, self.image = self.video.read()
imageRgb = cv2.cvtColor(self.image, cv2.COLOR_BGR2RGB)
results = self.faceMesh.process(imageRgb)
self.points = []
self.faces = 0
if results.multi_face_landmarks:
for faceNumber, face in enumerate(results.multi_face_landmarks):
self.faces += 1
self.mpDraw.draw_landmarks(self.image, face, self.mpFaceMesh.FACEMESH_CONTOURS, self.drawSpec)
for landmarkNumber, landmark in enumerate(face.landmark):
self.points += [faceNumber, landmarkNumber, landmark.x, landmark.y, landmark.z]
# Display
def display(self):
cv2.imshow("Image", self.image)
cv2.waitKey(1)