commit 684d63fbdb66f5fb83ee4c0704cbf5b64dd4a34b Author: The-Tysonator Date: Sun Apr 23 14:36:16 2023 +0100 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bc6664a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.DS_STORE +venv/ \ No newline at end of file diff --git a/FaceMesh.py b/FaceMesh.py new file mode 100755 index 0000000..41c6efa --- /dev/null +++ b/FaceMesh.py @@ -0,0 +1,37 @@ +# 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) diff --git a/main.py b/main.py new file mode 100755 index 0000000..75a4957 --- /dev/null +++ b/main.py @@ -0,0 +1,10 @@ +# Imports +from FaceMesh import Face + +# Create Face +face = Face(100, 2, 1) + +# Program Loop +while True: + face.track() + face.display() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1c78bed --- /dev/null +++ b/requirements.txt @@ -0,0 +1,23 @@ +absl-py==1.4.0 +attrs==23.1.0 +cffi==1.15.1 +contourpy==1.0.7 +cycler==0.11.0 +flatbuffers==23.3.3 +fonttools==4.39.3 +importlib-resources==5.12.0 +kiwisolver==1.4.4 +matplotlib==3.7.1 +mediapipe==0.9.3.0 +numpy==1.24.3 +opencv-contrib-python==4.7.0.72 +opencv-python==4.7.0.72 +packaging==23.1 +Pillow==9.5.0 +protobuf==3.20.3 +pycparser==2.21 +pyparsing==3.0.9 +python-dateutil==2.8.2 +six==1.16.0 +sounddevice==0.4.6 +zipp==3.15.0