本文整理匯總了Python中cv2.createLBPHFaceRecognizer方法的典型用法代碼示例。如果您正苦於以下問題:Python cv2.createLBPHFaceRecognizer方法的具體用法?Python cv2.createLBPHFaceRecognizer怎麽用?Python cv2.createLBPHFaceRecognizer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cv2
的用法示例。
在下文中一共展示了cv2.createLBPHFaceRecognizer方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: recognize_attendence
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import createLBPHFaceRecognizer [as 別名]
def recognize_attendence():
recognizer = cv2.face.LBPHFaceRecognizer_create() # cv2.createLBPHFaceRecognizer()
recognizer.read("TrainingImageLabel"+os.sep+"Trainner.yml")
harcascadePath = "haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(harcascadePath)
df = pd.read_csv("StudentDetails"+os.sep+"StudentDetails.csv")
cam = cv2.VideoCapture(0)
font = cv2.FONT_HERSHEY_SIMPLEX
col_names = ['Id', 'Name', 'Date', 'Time']
attendance = pd.DataFrame(columns=col_names)
while True:
ret, im = cam.read()
gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(gray, 1.2, 5)
for(x, y, w, h) in faces:
cv2.rectangle(im, (x, y), (x+w, y+h), (225, 0, 0), 2)
Id, conf = recognizer.predict(gray[y:y+h, x:x+w])
if(conf < 50):
ts = time.time()
date = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d')
timeStamp = datetime.datetime.fromtimestamp(
ts).strftime('%H:%M:%S')
aa = df.loc[df['Id'] == Id]['Name'].values
tt = str(Id)+"-"+aa
attendance.loc[len(attendance)] = [Id, aa, date, timeStamp]
else:
Id = 'Unknown'
tt = str(Id)
if(conf > 75):
noOfFile = len(os.listdir("ImagesUnknown"))+1
cv2.imwrite("ImagesUnknown"+os.sep+"Image"+str(noOfFile) +
".jpg", im[y:y+h, x:x+w])
cv2.putText(im, str(tt), (x, y+h), font, 1, (255, 255, 255), 2)
attendance = attendance.drop_duplicates(subset=['Id'], keep='first')
cv2.imshow('im', im)
if (cv2.waitKey(1) == ord('q')):
break
ts = time.time()
date = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d')
timeStamp = datetime.datetime.fromtimestamp(ts).strftime('%H:%M:%S')
Hour, Minute, Second = timeStamp.split(":")
fileName = "Attendance"+os.sep+"Attendance_"+date+"_"+Hour+"-"+Minute+"-"+Second+".csv"
attendance.to_csv(fileName, index=False)
cam.release()
cv2.destroyAllWindows()
print("Attendance Successfull")