cv2.lbphfacerecognizer has no attribute 'load' 'predict'

依然范特西╮ 提交于 2019-12-06 05:16:49

问题


import cv2
import numpy as np
faceDetect=cv2.CascadeClassifier('haarcascade_frontalface_default.xml');
cam=cv2.VideoCapture(0);
rec=cv2.face.LBPHFaceRecognizer_create();
rec.load("recognizerr\\trainingData.yml")

id=0

fontface=cv2.FONT_HERSHEY_SIMPLEX

while(True):

    ret,img=cam.read();
    gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    faces=faceDetect.detectMultiScale(gray,1.3,5);
    for(x,y,w,h) in faces:
        cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)
        id,conf=rec.predict(gray[y:y+h,x:x+w])
        if(id==1):
            id="Name"
        else:
            id="Unknown"    
        cv2.putText(img,str(id),(x,y+h),fontface,2,(255,0,0),3);
    cv2.imshow("Face",img);
    if(cv2.waitKey(1)==ord('q')):
        break;
cam.release()
cv2.destroyAllWindows()

Facing the error in rec.load Traceback (most recent call last):

File "C:\Users\DELL PC\Downloads\faceDetec_YOUTUBE-20171021T212250Z-001\recognize\detector.py", line 7, in rec.load("recognizerr\trainingData.yml") AttributeError: 'cv2.face_LBPHFaceRecognizer' object has no attribute 'load'


回答1:


I am using python 3.6.3 and openCv 3.3 and face the same problem. In openCV 3.3 has removed load() and save(). load() is replaced with read() and save() is replaced with write()




回答2:


use:

rec=cv2.face.LBPHFaceRecognizer_create();



回答3:


In OpenCV 3.3

load() is replaced by read()

save() is replaced by write()




回答4:


In openCV==3.x

load() is replaced with read() 
save() is replaced with write()


来源:https://stackoverflow.com/questions/46873728/cv2-lbphfacerecognizer-has-no-attribute-load-predict

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!