Ask Your Question

Brian Pickrell's profile - activity

2013-02-20 19:59:14 -0600 asked a question FeatureDetector factory doesn't work

I've been trying out the abstract class FeatureDetector, which has a factory method to create several child detectors. Unfortunately, this factory doesn't allow passing any parameters to the constructor, which I suspect many of the detectors need (some of the children have a member called Params). The following code caused an exception:

cv::FeatureDetector * the_detector;

the_detector= FeatureDetector::create("FAST");
vector<KeyPoint> keypoints;

the_detector->detect(img, keypoints);

However, identical handling of an automatic variable constructed with the default constructor worked just fine:

cv::FeatureDetector * the_detector;

cv::FastFeatureDetector FFD;
    // the_detector= FeatureDetector::create("FAST");
the_detector = &FFD;
vector<KeyPoint> keypoints;

the_detector->detect(img, keypoints);

I don't know what the create() method is doing, but it doesn't seem to be much good.

2013-02-20 17:42:46 -0600 asked a question Matrix error in FaceRecognizer predict

This is a question I've also asked on Stackoverflow.com

I'm trying to make a FisherFaceRecognizer's predict() method work, but I keep getting an error

Bad argument (Wrong shapes for given matrices. Was size(src) = (1,108000), size(W) = (36000,1).) in subspaceProject, file /tmp/opencv-DCb7/OpenCV-2.4.3/modules/contrib/src/lda.cpp, line 187

I've verified that both source and training images are the same data type, full color. In fact, I even tried copying one to the other just to make sure they were the same.

My code is adapted from the tutorial at http://docs.opencv.org/modules/contrib/doc/facerec/facerec_tutorial.html#fisherfaces

however, my test image is larger than the training images, so I needed to work on a region of interest (ROI) of the right size.

Here's how I read the images and converted sizes. I cloned the ROI matrix because an earlier error message told me the target matrix must be contiguous:

IplImage* img;
img = cvLoadImage( imgName.c_str() );

int height = trainingImages[0].rows;
// Take a subset of the same size as the training images
Mat testSample1(img, Rect( xLoc, yLoc, trainingImages[0].cols,
   trainingImages[0].rows));

Mat testSample;
testSample1.copyTo( testSample);
int testLabel = 1;

// The following lines create an Fisherfaces model for
// face recognition and train it with the images and
// labels read from the given CSV file.

Ptr<FaceRecognizer> model = createFisherFaceRecognizer();
model->train(trainingImages, labels);
cout << " check of data type testSample is " << testSample.type()
  << " images is " <<
   trainingImages[0].type() << endl;
cout << " trainingImages = " << trainingImages[0].elemSize()  <<  " vs
   " << testSample.elemSize() << endl;

int predictedLabel = model->predict(testSample);
//

// I get an exception message at the predict statement.

I know both matrices have type 16, yet somehow it still doesn't believe the matrices are the same size and data type. I've verified that both Mat's are the same dimensions (180x200) and the same elemSize() (3). Is this an internal bug?