简体   繁体   中英

OpenCV 3 Python

I just upgraded my OpenCV version from 2.4 to 3.1. I'm using python with it. Before upgrading, the following code would return the label of the predicted image and the confidence label:

label, confidence = model.predict(test_sample_image)

However, after the upgrade, the above code gives an error:

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

meaning that an integer is returned instead of a tuple as before. So how do I get the confidence?

I've think I've found the solution to your problem. Click here

  • Open the file: opencv_contrib/modules/face/include/opencv2/face.hpp

  • If you go to line 259 on that file you should find it different than what was in the repositiory

  • Head over to opencv/build
  • And rebuild via (make -j8, make install)

It should just work after that. Cheers!

Mikebarson is right, I went to that line and found it different to the one on the current version, according to git it was changed on April 20, 2016.

However if you want a solution that doesn't involve rebuilding you can try what Jaco van Oost suggested here . It worked for me:

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

我认为你应该像(gray[x:x+w, y:y+h])而不是test_sample_image一样传递cropped_face 数据。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM