matrix.cpp:310:错误:(-215)s> =函数cv :: setSize中的0

时间:2017-12-17 13:36:56

标签: python-3.x opencv cv2 lbph-algorithm

我对python很新。我正在使用 face_recognizer = cv2.face.LBPHFaceRecognizer_create() 并将我的预测函数定义为

#this function recognizes the person in image passed
#and draws a rectangle around detected face with name of the 
#subject
def predict(test_img):
#make a copy of the image as we don't want to chang original image
img = test_img.copy()
#detect face from the image
face, rect = detect_face(img)

#predict the image using our face recognizer 
label= face_recognizer.predict(face)
#get name of respective label returned by face recognizer
label_text = subjects[label]

#draw a rectangle around face detected
draw_rectangle(img, rect)
#draw name of predicted person
draw_text(img, label_text, rect[0], rect[1]-5)

return img`

我在使用预测函数预测面部时会出现以下错误

---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-13-d6517b4e38bd> in <module>()
  6 
  7 #perform a prediction
----> 8 predicted_img1 = predict(test_img1)
  9 #predicted_img2 = predict(test_img2)
 10 print("Prediction complete")

<ipython-input-12-b46266ecb9d5> in predict(test_img)
  9 
 10     #predict the image using our face recognizer
---> 11     label= face_recognizer.predict(face)
 12     #get name of respective label returned by face recognizer
 13     label_text = subjects[label]

error: C:\projects\opencv-python\opencv\modules\core\src\matrix.cpp:310: 
error: (-215) s >= 0 in function cv::setSize

非常感谢提前

1 个答案:

答案 0 :(得分:0)

我正在测试同一个github项目,并且在添加新的训练图像和测试图像时遇到了相同的错误。当使用训练数据中的图像之一作为测试图像时,问题就消失了。因此问题在于,如@ DaveW.Smith所建议的那样,当找不到匹配项时,没有任何地方可以处理。