0


I try to calculate Haar feature using opencv (Given an image).
Input: an image
output: haar feature
For that, I am using the FeatureEvaluator from OpenCV.

But I got an exception when I try to calculate one feature. Here is how I am doing:

Ptr<FeatureEvaluator> ptrHaar = FeatureEvaluator::create(FeatureEvaluator::HAAR);

Mat img = imread(image_path);       // image of size 2048*1536 correctly loaded
ptrHaar->setImage(img, Size(100, 100));
ptrHaar->setWindow(Point(0, 0));
double res = ptrHaar->calcOrd(0);   // get the exception here
cyh24
  • 266
  • 1
  • 3
  • 13
  • And the exception message is...? – cyriel Apr 19 '15 at 22:39
  • Unhandled exception at 0x000007FEE8D2EF6C (opencv_objdetect249d.dll) in FeatureExtract.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF. – cyh24 Apr 20 '15 at 06:30

2 Answers2

0

I think that you need to load/create some type of Haar feature, not just create an object. Try to load some Haar cascade classifier using load method and than try to use calcOrd method.

cyriel
  • 3,522
  • 17
  • 34
0

Your code is almost right. Only is missing is to read the CascadeClassifier previously trained. You can do this as follow:

FileStorage fs( "cascade.xml", FileStorage::READ );

//2) Then, create a FileNode to access the features:

FileNode featuresNode = fs["cascade"]["features"];

//3) Create the FeatureEvaluator, as you did in your first line

//4) Read the FileNode you have created:

ptrHaar->read(featuresNode);

And continue accordingly your code.

Note that ptrHaar->calcOrd(0) will read just the first feature rectangle, if you have more to read, you will need a loop, like this:

FileNodeIterator it = featuresNode.begin(), it_end = featuresNode.end();

int idx = 0;

for( ; it != it_end; ==it, idx++ )
{
    res = ptrHaar.calcOrd(idx);
}
Daniel
  • 1