问题
I am developing a breast imaging features for object recognition, using FlannBasedMatcher to compute spatial histograms.
Mat ComputeSpatialHistogram(Mat features, Mat vocabulary, int* region_index, int level, Ptr<DescriptorMatcher> flann_matcher)
{
int vocab_size = vocabulary.rows;
Mat descriptor = Mat::zeros(1, vocab_size*my_pow(4, level), CV_32FC1);
if (features.rows > 0)
{
vector<DMatch> matches;
flann_matcher->match(features, matches);
int word_idx, region_idx, descr_idx;
for (int i = 0; i < matches.size(); i++){
word_idx = matches[i].trainIdx;
region_idx = region_index[i];
descr_idx = vocab_size*region_idx + word_idx;
descriptor.at<float>(0, descr_idx) = descriptor.at<float>(0, descr_idx) + 1.0f;
}
}
return descriptor;
}
I get an error when ending the execution of the if(features.rows > 0) scope. Can you helpme?
回答1:
Try putting
matches.reserve(size)
with the actually size of the vector, before insert any element. This is necessary if you're using the OpenCV 2.2, but not with the 2.9
来源:https://stackoverflow.com/questions/30787348/heap-corruption-using-cvflannbasedmatcher-and-stdvector