How can i show an image in opencv.
How can I view the photo (from the database) knowing the label. opencv and facerecognizer. Sory for my English ...
How can I view the photo (from the database) knowing the label. opencv and facerecognizer. Sory for my English ...
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
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)
Asked: 2013-08-09 05:01:48 -0600
Seen: 693 times
Last updated: Aug 09 '13
your english is no problem. but please don't be sloppy ( and remove that garbage from your title )