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

Create Face_detection_dataset.py #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
43 changes: 43 additions & 0 deletions Face_detection_dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import cv2 #importing OpenCV file
import os #operation system library

camera = cv2.VideoCapture(0) #accessing the webcam using OpenCV

camera.set(3, 640) #width using for the images

camera.set(4, 480) #Height using for the images

face_detector = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') #a provided machine learning algorithm that is used to identify the picture

face_name = input('\n Enter user name: ') #Asking user name

print("\n [INFO] Initializing face capture.") #status message

counter= 0 #countdown the nunber of pictures

while(True):
ret,img=camera.read()

gray_color = cv2.cvtColor(img, cv2.COLOR_BGR2GRY) #to convert the images to gray color

faces = face_detector.detectMultiScale(gray_color, 1.3,5) #function used to detect the images

for(x, y, w,h) in faces:

cv2.rectangle(img, (x,y), (x+w, y+h), (255,0,0),2) #to resize the images
counter +=1

cv2.imwrite("dataset_for_Face_Recognition/User." + str(face_name) + '.' + str(counter) + ".jpg", gray_color[y:y+h,x:x+w]) #save the images to the folder that I already create in my drive (must create your own folder and then update the correct path)
cv2.imshow('image', img)

I = cv2.waitkey(100) & 0xff
if I ==47:
break
elif counter >= 50:
break #taking 50 pictures

print("\n [INFO] Existing program")

camera.release()

cv2.destroyAllWindows()