Ask Your Question
0

How can i show an image in opencv.

asked 2013-08-09 05:01:48 -0500

updated 2013-08-09 05:12:41 -0500

How can I view the photo (from the database) knowing the label. opencv and facerecognizer. Sory for my English ...

edit retag flag offensive close merge delete

Comments

2

your english is no problem. but please don't be sloppy ( and remove that garbage from your title )

berak gravatar imageberak ( 2013-08-09 05:09:33 -0500 )edit

2 answers

Sort by ยป oldest newest most voted
3

answered 2013-08-09 05:20:11 -0500

berak gravatar image

updated 2013-08-09 05:57:57 -0500

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 = sampleIdx;
        }
    }
}

and similar for lbph and fisher

edit flag offensive delete link more

Comments

1

I am able to override the function "predict", just do not know where the place and what it can add up. I know that in its current form, the function is not possible.

roserek gravatar imageroserek ( 2013-08-09 05:39:31 -0500 )edit

yea, definitely some sweat required for this ;)

berak gravatar imageberak ( 2013-08-09 06:19:30 -0500 )edit
0

answered 2013-08-09 05:08:07 -0500

simon111 gravatar image

please try the following Python code:

import cv2
im=cv2.imread('image file name') # please put the actual image file name in the quothes
cv2.imshow('image', im)
cv2.waitKey(0)
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-08-09 05:01:48 -0500

Seen: 218 times

Last updated: Aug 09 '13