下面附上的代码
import cv2
import numpy as np
recognizer = cv2.face
recognizer.loadTrainingData('trainer/example.yml')
#recognizer.read()
cascadePath = "haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(cascadePath);
cam = cv2.VideoCapture(1)
font = cv2.FONT_HERSHEY_SIMPLEX
while True:
ret, im =cam.read()
gray=cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
faces=faceCascade.detectMultiScale(gray, 1.3,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])
cv2.PutText(cv2.cv.fromarray(im),str(Id), (x,y+h),font, 255)
cv2.imshow('face',im)
if cv2.waitKey(10) == ord('q'):
break
cam.release()
cv2.destroyAllWindows()
我发现在这个 opencv 版本中不可能写出像下面这样的代码
recognizer = cv2.createLBPHFaceRecognizer()
recognizer.load('trainer/example.yml')
目标是在example.yml中加载之前收集的数据。但是我不确定该怎么做,并且附加的代码几乎没有不完整的参数。