Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- .gitattributes +1 -0
- main.py +38 -0
- shape_predictor_68_face_landmarks.dat +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
shape_predictor_68_face_landmarks.dat filter=lfs diff=lfs merge=lfs -text
|
main.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import dlib
|
3 |
+
import cv2
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
# Load the pre-trained face detector and facial landmarks predictor
|
7 |
+
detector = dlib.get_frontal_face_detector()
|
8 |
+
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat") # You'll need to download this file
|
9 |
+
|
10 |
+
# Function to detect eyes in the image
|
11 |
+
def detect_eyes(image):
|
12 |
+
image = cv2.imdecode(np.frombuffer(image.read(), np.uint8), -1)
|
13 |
+
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
14 |
+
|
15 |
+
# Detect faces in the image
|
16 |
+
faces = detector(gray)
|
17 |
+
|
18 |
+
# Loop through detected faces
|
19 |
+
for face in faces:
|
20 |
+
landmarks = predictor(gray, face)
|
21 |
+
|
22 |
+
# Define regions of interest for left and right eyes
|
23 |
+
left_eye_region = [(36, 37, 38, 39, 40, 41)]
|
24 |
+
right_eye_region = [(42, 43, 44, 45, 46, 47)]
|
25 |
+
|
26 |
+
# Draw rectangles around eyes
|
27 |
+
for region in left_eye_region + right_eye_region:
|
28 |
+
for i in region:
|
29 |
+
x = landmarks.part(i).x
|
30 |
+
y = landmarks.part(i).y
|
31 |
+
cv2.circle(image, (x, y), 2, (0, 255, 0), -1)
|
32 |
+
|
33 |
+
# Encode the image back to bytes
|
34 |
+
_, buffer = cv2.imencode('.jpg', image)
|
35 |
+
return buffer.tobytes()
|
36 |
+
|
37 |
+
iface = gr.Interface(fn=detect_eyes, inputs=gr.inputs.Imagebox(), outputs=gr.outputs.Imagebox())
|
38 |
+
iface.launch()
|
shape_predictor_68_face_landmarks.dat
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:fbdc2cb80eb9aa7a758672cbfdda32ba6300efe9b6e6c7a299ff7e736b11b92f
|
3 |
+
size 99693937
|