<reponame>milan2498/Motor-starter-using-facial-recognition

import cv2
import numpy as np

faceDetect=cv2.CascadeClassifier('C:/Users/DELL/Desktop/python/working/haarcascade_frontalface_default.xml')
cam=cv2.VideoCapture(0);
rec=cv2.face.LBPHFaceRecognizer_create();
rec.read("C:/Users/DELL/Desktop/python/working/trainningData.yml")
id=0
fontFace=cv2.FONT_HERSHEY_SIMPLEX
fontScale=1
fontColor=(255,255,255)

while(True):
	ret,img=cam.read();
	gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
	faces=faceDetect.detectMultiScale(gray,1.3,5);
	for(x,y,w,h) in faces:
		cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,255),2)
		id,conf=rec.predict(gray[y:y+h,x:x+w])	
		if(id == 1):
			id = 'unknown'
		elif(id == 2):
			id = "milan"  
		elif(id==3):
			id = "<NAME>"
		else:
			id="unknown"
		cv2.putText(img,str(id),(x,y+h),cv2.FONT_HERSHEY_SIMPLEX,1,(255,255,255));
	cv2.imshow("Face",img);
	if(cv2.waitKey(1)==ord('q')):
		break;
cam.release()
cv2.destroyAllWindows()



import cv2
import numpy as np

faceDetect=cv2.CascadeClassifier('C:/Users/DELL/Desktop/python/working/haarcascade_frontalface_default.xml')
cam=cv2.VideoCapture(0);
rec=cv2.face.LBPHFaceRecognizer_create();
rec.read("C:/Users/DELL/Desktop/python/working/trainningData.yml")
id=0
fontFace=cv2.FONT_HERSHEY_SIMPLEX
fontScale=1
fontColor=(255,255,255)

while(True):
	ret,img=cam.read();
	gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
	faces=faceDetect.detectMultiScale(gray,1.3,5);
	for(x,y,w,h) in faces:
		cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,255),2)
		id,conf=rec.predict(gray[y:y+h,x:x+w])	
		if(id == 1):
			id = 'unknown'
		elif(id == 2):
			id = "milan"  
		elif(id==3):
			id = "<NAME>"
		else:
			id="unknown"
		cv2.putText(img,str(id),(x,y+h),cv2.FONT_HERSHEY_SIMPLEX,1,(255,255,255));
	cv2.imshow("Face",img);
	if(cv2.waitKey(1)==ord('q')):
		break;
cam.release()
cv2.destroyAllWindows()