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

3

我很新手 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`

使用predict函数进行面部预测时,我遇到了以下错误。
---------------------------------------------------------------------------
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

Many thanks in advance


1
detect_face() 是否可能给出一些指示(例如 face is None),表明它没有找到人脸,而您正在使用无效的 rect 进行处理? - Dave W. Smith
@DaveW.Smith,我没有收到你提到的任何错误。 上面提到的是我唯一遇到的错误。 - SRK
有时,如果您传递无效输入,底层的OpenCV C++代码会出现一些奇怪的错误。在调用face_recognizer.predict()之前正确执行print(repr(face))会显示什么? - Dave W. Smith
@DaveW.Smith,我使用了git repo中的代码,并仅更改了face_recognizer = cv2.face.LBPHFaceRecognizer_create() - SRK
1
仔细查看detect_face()方法。请注意,如果它没有找到人脸,它将返回None, None。您复制的调用该方法的示例方法没有检查None。我怀疑问题就出在那里。 - Dave W. Smith
1个回答

0

我正在测试同一个Github项目,当添加新的训练图像和测试图像时遇到了相同的错误。当使用训练数据中的一张图像作为测试图像时,问题就消失了。因此,正如@DaveW.Smith所建议的那样,问题可能是没有处理找不到匹配项的情况。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接