396:错误:(-5)此LBPH模型尚未计算。你打电话给火车的方法吗?在函数cv :: face :: LBPH :: predict
问题描述:
我想用Python 2.7.13和OpenCV 3.3.0构建一个人脸识别程序。396:错误:(-5)此LBPH模型尚未计算。你打电话给火车的方法吗?在函数cv :: face :: LBPH :: predict
然而,我当它试图发现我的脸收到此错误:
File "C:\GitProject\face_recognition\detector.py", line 20, in
<module> Id = recognizer.predict(gray[y:y+h,x:x+w])
error: C:\projects\opencv-python\opencv_contrib\modules\face\src\lbph_faces.cpp:396:
error: (-5) This LBPH model is not computed yet. Did you call the train method? in function cv::face::LBPH::predict
这里是我的代码:
import cv2 ,os
import numpy as np
from PIL import Image
import pickle
recognizer = cv2.face.LBPHFaceRecognizer_create()
recognizer.read('trainer/training_data.yml')
cascadePath = "haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(cascadePath);
cam = cv2.VideoCapture(0)
font = cv2.FONT_HERSHEY_SIMPLEX
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 = recognizer.predict(gray[y:y+h,x:x+w])
if(conf<50):
if(Id==1):
Id="Anirban"
elif(Id==2):
Id="Sam"
else:
Id="Unknown"
cv2.PutText(cv2.fromarray(im),str(Id), (x,y+h),font, 255)
cv2.imshow('im',im)
if cv2.waitKey(10) & 0xFF==ord('q'):
break
cam.release()
cv2.destroyAllWindows()
答
打开你的教练,改变recognizer.save到recognizer.write 。不要忘记再次运行教练。这个对我有用。
答
欢迎来到Stack Overflow。您收到的错误是告诉您,在您要求它进行任何识别之前,您需要在LBPHFaceRecognizer
的父类中调用火车方法。请参阅the documentation here。