首页 > 解决方案 > AttributeError:“NoneType”对象没有属性“预测”

问题描述

#creating recognizer
recognizer= cv2.face_LBPHFaceRecognizer()
....
#predicting sad images
image_paths = [os.path.join(path, f) for f in os.listdir(path) if f.endswith('.sad')]
for image_path in image_paths:
    predict_image_pil = Image.open(image_path).convert('L')
    predict_image = np.array(predict_image_pil, 'uint8')
    faces = faceCascade.detectMultiScale(predict_image)
    for (x, y, w, h) in faces:
        nbr_predicted, conf = recognizer.predict(predict_image[y: y + h, x: x + w])
....

得到错误

nbr_predicted, conf = Recognizer.predict(predict_image[y: y + h, x: x + w]) AttributeError: 'NoneType' object has no attribute 'predict'

如何解决这个错误,因为 face_PredictCollector() 也不起作用

标签: pythonopencvface-recognitiontraining-data

解决方案


推荐阅读