face.predict error in cv3 python 2.7

asked 2016-12-19 21:50:54 -0600

The following code works in cv2, but neither predict line works in cv3:

recognizer = cv2.face.createLBPHFaceRecognizer(radius=2, neighbors=16, grid_x=3, grid_y=3)
(prediction, conf) = recognizer.predict(testing.data[i])   #OR..
(prediction, conf) = cv2.face.predict(testing.data[i])

The attempt to call predict results in either : object is not iterable or object as no attribute 'predict' error

I found some old discussion related to this Face class,

https://github.com/peterbraden/node-opencv/pull/379/files
https://github.com/opencv/opencv_contrib/issues/184

but not sure if it's still relevant or if it's even the same issue I have. I'm pretty new to this, so I think I'm just calling it the wrong way, especially since predict is listed in the cv3 documentation:

http://docs.opencv.org/3.1.0/dd/d65/classcv_1_1face_1_1FaceRecognizer.html
edit retag flag offensive close merge delete

Comments

berak gravatar imageberak ( 2016-12-19 22:30:17 -0600 )edit

Thanks, it reports Version 3.1.0.. but I don't see predict when doing help(cv2.face) or help(cv2.face.createLBPHFaceRecognizer). And according to that thread, it looks like the issue may have been resolved in #638/#6547. Does this mean I need an update? Since everything else works, I'm a little scared of building openCV again, is there an example of how to call predict in python/cv3?

ru4mj12 gravatar imageru4mj12 ( 2016-12-19 23:09:55 -0600 )edit
  • ah, sorry, typo, has to be: >>> help(cv2.face.createLBPHFaceRecognizer()) (you need to create an instance)

  • if that issue applies to you, you probably can still call: prediction = recognizer.predict(testing.data[i]) (you just won't get any confiidence value

  • yes, rebuilding from latest master branch will solve it

berak gravatar imageberak ( 2016-12-19 23:18:57 -0600 )edit

Thanks, the help now shows the predict function, and it does work as you pointed out with the confidence removed. Interestingly, the commit shows the fix was done in May, but I built in November and the only instance of face.hpp I have is in the opencv_contrib folder (opencv/opencv_contrib/modules/face/include/opencv2/face.hpp) which doesn't have the fix. The reason I installed the _contrib files was in order to get SIFT.. is it possible that doing so automatically replaced the main line face module? Or given my setup, is there a way to get the confidence value?

ru4mj12 gravatar imageru4mj12 ( 2016-12-20 16:28:30 -0600 )edit