Skip to content

Commit c67b81a

Browse files
committed
Update __init__.py
1 parent b592e2f commit c67b81a

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

__init__.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
©2023 PyJs
1+
# ©2023 PyJs
22

33
import os
44
try:
@@ -12,7 +12,13 @@
1212

1313
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
1414

15-
def enroll_face(frame):
15+
def scan_face():
16+
cap = cv2.VideoCapture(0)
17+
ret, frame = cap.read()
18+
return frame
19+
20+
def enroll_face():
21+
frame=scan_face()
1622
global enrolled_faces
1723

1824
# Convert the frame to grayscale for face detection
@@ -26,14 +32,14 @@ def enroll_face(frame):
2632
# Crop and store each enrolled face
2733
enrolled_faces.append(frame[y:y+h, x:x+w])
2834

29-
return f"{len(faces)} face(s) enrolled successfully."
35+
return True
3036
else:
31-
return "No face found in the frame."
37+
return False
3238

3339
# Function to match a face
34-
def is_match(frame):
40+
def is_match():
3541
global enrolled_faces
36-
42+
frame=scan_face()
3743
# Convert the frame to grayscale for face detection
3844
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
3945

@@ -47,21 +53,16 @@ def is_match(frame):
4753

4854
# Check if the detected face matches any of the enrolled faces
4955
for enrolled_face in enrolled_faces:
50-
if compare_faces(enrolled_face, detected_face):
51-
return "Face match found."
56+
if reuowg_w(enrolled_face, detected_face):
57+
return True
5258

53-
return "No matching face found."
59+
return False
5460

5561
# Function to compare faces (a basic image comparison)
56-
def compare_faces(face1, face2):
62+
def reuowg_w(face1, face2):
5763
# Resize the images to the same size
5864
face1 = cv2.resize(face1, (200, 200))
5965
face2 = cv2.resize(face2, (200, 200))
6066
diff = cv2.absdiff(face1, face2)
6167
mean_diff = diff.mean()
62-
return mean_diff < 50
63-
64-
def scan_face():
65-
cap = cv2.VideoCapture(0)
66-
ret, frame = cap.read()
67-
return frame
68+
return mean_diff < 50

0 commit comments

Comments
 (0)