OpenCV 3 Python

3

我刚将OpenCV版本从2.4升级到3.1。我正在使用python。在升级之前,以下代码将返回预测图像的标签和置信度标签:

label, confidence = model.predict(test_sample_image)

然而,在升级后,上述代码会出现错误:
Traceback (most recent call last):
  File "recognize.py", line 45, in <module>
    label, confidence = model.predict(test_sample_image)
TypeError: 'int' object is not iterable

意思是返回一个整数而不是以前的元组。那么我怎么得到置信度呢?
3个回答

3

我认为我已经找到了你的问题的解决方案。

点击这里

  • 打开文件:opencv_contrib/modules/face/include/opencv2/face.hpp

  • 如果您转到该文件的第259行,您应该会发现它与存储库中的不同。

  • 前往 opencv/build
  • 然后通过 (make -j8, make install) 重新构建

之后应该就能正常工作了。干杯!


0

Mikebarson是正确的,我去了那一行并发现它与当前版本上的不同,根据git显示它在2016年4月20日被更改。

然而,如果你想要一个不需要重建的解决方案,你可以尝试Jaco van Oost在这里提出的方法。这对我很有效:

result = cv2.face.MinDistancePredictCollector()
recognizer.predict()
label = result.getLabel()
confidence = result.getDist()

0

我认为你应该像这样传递裁剪后的人脸数据: (gray[x:x+w, y:y+h]) 而不是 test_sample_image


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