Ask Your Question

Can't get predict confidence

asked 2016-01-05 09:40:59 -0600

alextorre98 gravatar image

When I run the predict(src) function, it returns only a int, instead of a int and a double.

using help() throws this:

Help on built-in function predict:

predict(...) method of cv2.face_BasicFaceRecognizer instance
    predict(src) -> retval  or  predict(src) -> label, confidence  or  predict(src, collector[, state]) -> None

The code I'm using is:

nbr_predicted, conf = recognizer.predict(imgp)
edit retag flag offensive close merge delete



bug was fixed by adding proper python overloads

berak gravatar imageberak ( 2016-11-30 02:10:26 -0600 )edit

1 answer

Sort by » oldest newest most voted

answered 2016-01-05 11:08:27 -0600

berak gravatar image

imho, that's a bug in the generated wrapper code. the 'label only' code shadows the 'label and confidence' part in pyopencv_cv_face_face_FaceRecognizer_predict .

as a quick workaround, remove the CV_WRAP here , and rebuild. this will disable the 'label only' version, but let you acess the confidence/distance.

edit flag offensive delete link more


Ok, thanks.

alextorre98 gravatar imagealextorre98 ( 2016-01-05 11:12:13 -0600 )edit

Curious if this is considered an actual bug by the devs? It doesn't look like anyone has submitted a patch for it, but it's a relatively recent change (december). Is it worth doing a pull for, or was it done on purpose?

cmcfadden gravatar imagecmcfadden ( 2016-01-10 21:55:27 -0600 )edit

idon't think, it was done on purpose, it's one of those small things, that don't break the build, and thus go unrecognized.

maybe you could start with making an issue there.

berak gravatar imageberak ( 2016-01-11 00:45:29 -0600 )edit

Thanks a lot berak, I had the same problem here, and it worked perfectly.

Kelvin gravatar imageKelvin ( 2016-03-09 08:41:48 -0600 )edit

Hi guys? i'm so new with opencv, i would like to know how to fix this bug? if i delete CV_WRAP line, how can i do a rebuild?

Thanks a lor per your help

Angel gravatar imageAngel ( 2016-04-08 11:06:44 -0600 )edit

I have commented out CV_WRAP int predict(InputArray src) const; But when I build I get the following error: /home/pi/opencv_contrib-3.1.0/modules/face/src/facerec.cpp:75:5: error: prototype for ‘int cv::face::FaceRecognizer::predict(cv::InputArray) const’ does not match any in class ‘cv::face::FaceRecognizer’ int FaceRecognizer::predict(InputArray src) const { ^ In file included from /home/pi/opencv_contrib-3.1.0/modules/face/src/facerec.cpp:19:0: /home/pi/opencv_contrib-3.1.0/modules/face/include/opencv2/face.hpp:309:26: error: candidates are: virtual void cv::face::FaceRecognizer::predict(cv::InputArray, cv::Ptr<cv::face::PredictCollector>, int) const CV_WRAP virtual void predict(InputArray src, Ptr<PredictCollector> collector, const int state = 0) const = 0; Thanks

alexylem gravatar imagealexylem ( 2016-04-08 11:53:21 -0600 )edit

alexylem, I have the same problem. If you know how to fix it, please help.

arcticworker gravatar imagearcticworker ( 2016-04-10 21:14:59 -0600 )edit

Well just one Question. nbr_predicted, conf = recognizer.predict(imgp)

here imgp is your array????

Craftech Systems gravatar imageCraftech Systems ( 2016-04-11 11:55:24 -0600 )edit

you should remove CV_WRAP, not comment out the whole line. it should look:

int predict(InputArray src) const;
berak gravatar imageberak ( 2016-04-11 12:00:26 -0600 )edit

@Craftech Systems : it is the image (array). what are you asking ?

berak gravatar imageberak ( 2016-04-11 12:02:50 -0600 )edit

Question Tools

1 follower


Asked: 2016-01-05 09:40:59 -0600

Seen: 5,886 times

Last updated: Feb 12 '18