Skip to content

Commit 5dbdd67

Browse files
committed
Creave version 0.0.8
1 parent 01813a2 commit 5dbdd67

File tree

2 files changed

+40
-41
lines changed

2 files changed

+40
-41
lines changed

faces/__init__.py

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# ©2023 PyJs
2-
31
import os
42
try:
53
import cv2
@@ -10,36 +8,44 @@
108
# Initialize a list to store enrolled faces
119
enrolled_faces = []
1210

13-
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
11+
class dont_run:
12+
def compare_faces(face1, face2):
13+
# Resize the images to the same size
14+
face1 = cv2.resize(face1, (200, 200))
15+
face2 = cv2.resize(face2, (200, 200))
16+
diff = cv2.absdiff(face1, face2)
17+
mean_diff = diff.mean()
18+
return mean_diff < 50
19+
def scan_face():
20+
cap = cv2.VideoCapture(0)
21+
ret, frame = cap.read()
22+
return frame
23+
def is_match(frame):
24+
global enrolled_faces
1425

15-
def scan_face():
16-
cap = cv2.VideoCapture(0)
17-
ret, frame = cap.read()
18-
return frame
26+
# Convert the frame to grayscale for face detection
27+
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
1928

20-
def enroll_face():
21-
frame=scan_face()
22-
global enrolled_faces
29+
# Detect faces in the frame
30+
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))
2331

24-
# Convert the frame to grayscale for face detection
25-
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
32+
if len(faces) > 0:
33+
for (x, y, w, h) in faces:
34+
# Crop the detected face for comparison
35+
detected_face = frame[y:y+h, x:x+w]
2636

27-
# Detect faces in the frame
28-
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))
37+
# Check if the detected face matches any of the enrolled faces
38+
for enrolled_face in enrolled_faces:
39+
if dont_run.compare_faces(enrolled_face, detected_face):
40+
return (True, "That's a match!")
2941

30-
if len(faces) > 0:
31-
for (x, y, w, h) in faces:
32-
# Crop and store each enrolled face
33-
enrolled_faces.append(frame[y:y+h, x:x+w])
42+
return (False, "Not matched.")
3443

35-
return True
36-
else:
37-
return False
44+
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
3845

39-
# Function to match a face
40-
def is_match():
46+
def enroll_face(frame):
4147
global enrolled_faces
42-
frame=scan_face()
48+
4349
# Convert the frame to grayscale for face detection
4450
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
4551

@@ -48,21 +54,14 @@ def is_match():
4854

4955
if len(faces) > 0:
5056
for (x, y, w, h) in faces:
51-
# Crop the detected face for comparison
52-
detected_face = frame[y:y+h, x:x+w]
53-
54-
# Check if the detected face matches any of the enrolled faces
55-
for enrolled_face in enrolled_faces:
56-
if reuowg_w(enrolled_face, detected_face):
57-
return True
57+
# Crop and store each enrolled face
58+
enrolled_faces.append(frame[y:y+h, x:x+w])
5859

59-
return False
60+
return (True, f"success!✅ {len(faces)} are currently saved.")
61+
else:
62+
return (False, "No face found in the frame.😞")
6063

61-
# Function to compare faces (a basic image comparison)
62-
def reuowg_w(face1, face2):
63-
# Resize the images to the same size
64-
face1 = cv2.resize(face1, (200, 200))
65-
face2 = cv2.resize(face2, (200, 200))
66-
diff = cv2.absdiff(face1, face2)
67-
mean_diff = diff.mean()
68-
return mean_diff < 50
64+
def match_face():
65+
frame = dont_run.scan_face()
66+
return dont_run.is_match(frame)
67+
__version__="0.0.8"#---------------------------------------------CHANGE THIS---------------------------------------------#

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "hatchling.build"
55
packages=["faces"]
66
[project]
77
name = "faces-PyJs"
8-
version = "0.0.9"
8+
version = "0.0.8"
99
description = "Lets you have super useful security."
1010
readme = "README.md"
1111
requires-python = ">=3.11.9"

0 commit comments

Comments
 (0)