Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

i'm afraid, the current facerecognizer interface does not allow you to see, which image was the best match for your test-img.

you could search the labels list for the returned label, stop at the 1st found , and get the image at the same index, but that's just one image of that person, not the actual match image.

you could also go and hack it, first the interface, then all 3 impls, and add an additional index(ref) into the images, but hmmm

i'm afraid, the current facerecognizer interface does not allow you to see, which image was the best match for your test-img.test-img ( as you only get the label, not the index ).

you could search the labels list for the returned label, stop at the 1st found , and get the image at the same index, but that's just one image of that person, not the actual match image.

you could also go and hack it, first the interface, then all 3 impls, and add an additional index(ref) into the images, but hmmm

i'm afraid, the current facerecognizer interface does not allow you to see, which image was the best match for your test-img ( as you only get the label, not the index ).

you could search the labels list for the returned label, stop at the 1st found , and get the image at the same index, but that's just one image of that person, not the actual match image.

you could also go and hack it, first the interface, then all 3 impls, and add an additional index(ref) into the images, but hmmm

-------------------------------------------------------------------------------------------

// contrib.hpp:
class CV_EXPORTS_W FaceRecognizer : public Algorithm
{
public:
    // ....

    // Predicts the label and confidence for a given sample.
    CV_WRAP virtual void predict(InputArray src, CV_OUT int &label, CV_OUT double &confidence, CV_OUT int & matchImageId) const = 0;

// facerec.cpp:

class Eigenfaces : public FaceRecognizer
{
    // ....

    // Predicts the label and confidence for a given sample.
    void predict(InputArray _src, int &label, double &dist, int &matchImgId) const;

int Eigenfaces::predict(InputArray _src) const {
    int label;
    double dummy;
    int  dummyImg;
    predict(_src, label, dummy, dummyImg);
    return label;
}

void Eigenfaces::predict(InputArray _src, int &minClass, double &minDist, int &matchImgId) const {
    // ...
    minDist = DBL_MAX;
    minClass = -1;
    matchImgId = -1;
    for(size_t sampleIdx = 0; sampleIdx < _projections.size(); sampleIdx++) {
        double dist = norm(_projections[sampleIdx], q, NORM_L2);
        if((dist < minDist) && (dist < _threshold)) {
            minDist = dist;
            minClass = _labels.at<int>((int)sampleIdx);
            matchImgId = t;
        }
    }
}

and similar for lbph and fisher

i'm afraid, the current facerecognizer interface does not allow you to see, which image was the best match for your test-img ( as you only get the label, not the index ).

you could search the labels list for the returned label, stop at the 1st found , and get the image at the same index, but that's just one image of that person, not the actual match image.

you could also go and hack it, first the interface, then all 3 impls, and add an additional index(ref) into the images, but hmmm

-------------------------------------------------------------------------------------------

// contrib.hpp:
class CV_EXPORTS_W FaceRecognizer : public Algorithm
{
public:
    // ....

    // Predicts the label and confidence for a given sample.
    CV_WRAP virtual void predict(InputArray src, CV_OUT int &label, CV_OUT double &confidence, CV_OUT int & matchImageId) const = 0;

// facerec.cpp:

class Eigenfaces : public FaceRecognizer
{
    // ....

    // Predicts the label and confidence for a given sample.
    void predict(InputArray _src, int &label, double &dist, int &matchImgId) const;

int Eigenfaces::predict(InputArray _src) const {
    int label;
    double dummy;
    int  dummyImg;
    predict(_src, label, dummy, dummyImg);
    return label;
}

void Eigenfaces::predict(InputArray _src, int &minClass, double &minDist, int &matchImgId) const {
    // ...
    minDist = DBL_MAX;
    minClass = -1;
    matchImgId = -1;
    for(size_t sampleIdx = 0; sampleIdx < _projections.size(); sampleIdx++) {
        double dist = norm(_projections[sampleIdx], q, NORM_L2);
        if((dist < minDist) && (dist < _threshold)) {
            minDist = dist;
            minClass = _labels.at<int>((int)sampleIdx);
            matchImgId = t;
sampleIdx;
        }
    }
}

and similar for lbph and fisher