Skip to content
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
31 changes: 31 additions & 0 deletions Face_Detection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import cv2
import os
alg = "haarcascade_frontalface_default.xml"
haar = cv2.CascadeClassifier(alg)
cam = cv2.VideoCapture(0)
dataset = "datasets"
name = "champ"
path = os.path.join(dataset,name)
if not os.path.isdir(path):
os.mkdir(path)
(width,height) = (130,100)
count = 1
while count<30:
_,img = cam.read()
grayImg = cv2.cvtColor(img,cv2.COLOR_BG2GRAY)
faces = haar.detectMultiScale(grayImg,1.3,4)
for (x,y,w,h) in faces:
cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)
onlyface = grayImg[y:y+h,x:x+w]
resizeImg = cv2.resize(grayImg,(width,height)) #complete frame
perfectImg = cv2.resize(perfectImg,(width,height)) #only face
cv2.imwrite("%s/%s.jpg"%(path,count),perfectImg)
cv2.imwrite("%s/%s.jpg"%(path,count),resizeImg)
count+=1
cv2.imshow("FaceDetection",img)
key = cv2.waitKey(10)
if key == 27:
break
print("Face captured Successfully")
cam.release()
cv2.destroyAllWindows()