Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python cv2.lbphfacerecognizer没有属性';加载'';预测';_Python_Load_Predict - Fatal编程技术网

Python cv2.lbphfacerecognizer没有属性';加载'';预测';

Python cv2.lbphfacerecognizer没有属性';加载'';预测';,python,load,predict,Python,Load,Predict,面对rec.load中的错误 回溯(最近一次呼叫最后一次): 文件“C:\Users\DELL PC\Downloads\faceDetec_YOUTUBE-20171021T212250Z-001\recognize\detector.py”,第7行,在 记录加载(“识别器r\trainingData.yml”) AttributeError:'cv2.face\u lbphFaceRecognitizer'对象没有属性'load' 我使用的是python 3.6.3和openCv 3.3,面

面对rec.load中的错误 回溯(最近一次呼叫最后一次):

文件“C:\Users\DELL PC\Downloads\faceDetec_YOUTUBE-20171021T212250Z-001\recognize\detector.py”,第7行,在 记录加载(“识别器r\trainingData.yml”) AttributeError:'cv2.face\u lbphFaceRecognitizer'对象没有属性'load'


我使用的是python 3.6.3和openCv 3.3,面临着同样的问题。在openCV 3.3中,删除了load()和save()。load()替换为read(),save()替换为write()

使用:

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()
在OpenCV 3.3中

load()替换为read()

在openCV==3.x中,save()被write()替换

rec=cv2.face.LBPHFaceRecognizer_create();
load() is replaced with read() 
save() is replaced with write()