Quantcast
Viewing all articles
Browse latest Browse all 53

OpenCV Contrib Face module with Java wrapper - returning multiple predictions

I'm using [OpenCV Contrib Face module](https://github.com/Itseez/opencv_contrib/tree/master/modules/face) in Java. Java wrapper is automatically generated from C++ source code based on [`CV_WRAP`](http://answers.opencv.org/question/6528/cv_wrap-and-cv_exports_w/) tag. So far so good, **but** unfortunately not all methods I need have wrappers. :-( I'm using `FaceRecognizer.predict` method which returns label of face that is most similar (in terms of [eigenfaces](https://en.wikipedia.org/wiki/Eigenface)) to given face. What I desperately need is to get `N>1` (for example `N=5`) best matches, ie. `N` images with minimal [`PredictResult.distance`](https://github.com/Itseez/opencv_contrib/blob/master/modules/face/include/opencv2/face/predict_collector.hpp#L88). This is automatically generated Java's wrapper for `predict` method: // // C++: void predict(Mat src, int& label, double& confidence) // //javadoc: FaceRecognizer::predict(src, label, confidence) public void predict(Mat src, int[] label, double[] confidence) { double[] label_out = new double[1]; double[] confidence_out = new double[1]; predict_1(nativeObj, src.nativeObj, label_out, confidence_out); if(label!=null) label[0] = (int)label_out[0]; if(confidence!=null) confidence[0] = (double)confidence_out[0]; return; } As you can see, it uses two arrays (`label_out` and `confidence_out`) of length equal `1`. I need more generalized version which is available in C++ source code as a [`StandardCollector::getResults`](https://github.com/Itseez/opencv_contrib/blob/master/modules/face/src/predict_collector.cpp#L87) method. Is there an easy way to add a few [`CV_WRAP`](http://answers.opencv.org/question/6528/cv_wrap-and-cv_exports_w/) *'here and there'* to get multiple predictions using Java wrapper for: std::vector< std::pair> StandardCollector::getResults(bool sorted) const { std::vector< std::pair> res(data.size()); std::transform(data.begin(), data.end(), res.begin(), &toPair); if (sorted) { std::sort(res.begin(), res.end(), &pairLess); } return res; } ? Thanks in advance!

Viewing all articles
Browse latest Browse all 53

Trending Articles