J'essaye de construire un programme de reconnaissance faciale en utilisant Python 2.7.13 et OpenCV 3.3.0.396: erreur: (-5) Ce modèle LBPH n'est pas encore calculé. Avez-vous appelé la méthode de train? dans la fonction cv :: face :: LBPH :: predict
Cependant, je reçois cette erreur quand il essaie de détecter mon visage:
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
Voici mon code:
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()