Skip to content

Commit

Permalink
Update face_detection.py
Browse files Browse the repository at this point in the history
  • Loading branch information
imPradhyumn authored Aug 25, 2019
1 parent b09ab13 commit b6686db
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions face_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def create_labels():
names.remove('')

names_dic=dict(zip(set(fid),names))
print(names_dic)

return faces_list,fid,names_dic

Expand All @@ -72,24 +73,7 @@ def text(image,text,x,y):

all_labels=[]

#test_prediction
'''img_test=cv2.imread('test.jpg')
faces,img_gray_test=facedetect(img_test)
for f in faces:
(x,y,w,h)=f
req_region=img_gray_test[y:y+w,x:x+h]
label,confi=classifier.predict(req_region)
all_labels.append(names_dic[label].capitalize())
rectangle(f,img_gray_test)
text(img_gray_test,names_dic[label].capitalize(),x,y)
cv2.imshow('Gray',img_gray_test)
cv2.waitKey(0)
cv2.destroyAllWindows()'''

def start_detection(subject='Testing'):
def start_detection(subject):
#live_prediction
cam=cv2.VideoCapture(0)
ch=1
Expand All @@ -113,6 +97,28 @@ def start_detection(subject='Testing'):
cv2.destroyAllWindows()

mark_attendance(all_labels,subject)


#test_prediction
if __name__=='__main__':
start_detection(subject)

img_test=cv2.imread('p4.jpg')
faces,img_gray_test=facedetect(img_test)

for f in faces:
(x,y,w,h)=f
req_region=img_gray_test[y:y+w,x:x+h]
label,confi=classifier.predict(req_region)
name_text=names_dic[label].capitalize()
print(confi)
if confi>50:
name_text='Unknown'
all_labels.append(names_dic[label].capitalize())

rectangle(f,img_gray_test)
text(img_gray_test,name_text,x,y)
img_gray_test=cv2.resize(img_gray_test,(512,512))
cv2.imshow('Gray',img_gray_test)
cv2.waitKey(0)
cv2.destroyAllWindows()


0 comments on commit b6686db

Please sign in to comment.