Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OpenCV Contrib Face module with Java wrapper - returning multiple prediction

I'm using OpenCV Contrib Face module in Java. Java wrapper is automatically generated from C++ source code based on CV_WRAP 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) 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.

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 method.

Is there an easy way to add a few CV_WRAP 'here and there' to get multiple predictions using Java wrapper for:

std::vector< std::pair<int, double> > StandardCollector::getResults(bool sorted) const {
    std::vector< std::pair<int, double> > 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!

OpenCV Contrib Face module with Java wrapper - returning multiple predictionpredictions

I'm using OpenCV Contrib Face module in Java. Java wrapper is automatically generated from C++ source code based on CV_WRAP 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) 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.

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 method.

Is there an easy way to add a few CV_WRAP 'here and there' to get multiple predictions using Java wrapper for:

std::vector< std::pair<int, double> > StandardCollector::getResults(bool sorted) const {
    std::vector< std::pair<int, double> > 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!