python - 396: error: (-5) This LBPH model is not computed yet. Did you call the train method? in function cv::face::LBPH::predict -


i trying built face recognition using python first time,

this error occur when tries detect face.

traceback (most recent call last):   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) lbph model not computed yet. did call train method? in function cv::face::lbph::predict 

this code using python 2.7.13 , opencv 3.3.0

import cv2 ,os import numpy np 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() 

open trainer, change recognizer.save recognizer.write. don't forget run trainer again. works me.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -