Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

face recognition #89

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions facedet/faces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import os

import cv2

haar_file = "haarcascade_frontalface_default.xml"

# path where the training data is saved
datasets = "C:\\Users\\attar\\OneDrive\\Documents\\datasets"

# enter the name of the person whose face is being recorded and collected for the data
sub_data = "name of the person"

path = os.path.join(datasets, sub_data)
if not os.path.isdir(path):
os.mkdir(path)
(width, height) = (130, 100)

face_cascade = cv2.CascadeClassifier(haar_file)
cam = cv2.VideoCapture(0)

count = 1
while count < 31:
print(count)
(_, img) = cam.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 4)

for x, y, w, h in faces:

cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
face = gray[y: y + h, x: x + w]
face_resize = cv2.resize(face, (width, height))
cv2.imwrite("%s/%s.png" % (path, count), face_resize)
count += 1

cv2.imshow("FaceDetection", img)
key = cv2.waitKey(10)
if key == 27:
break

cam.release()
cv2.destroyAllWindows()
Loading
Loading