Heap Corruption using cv::FlannBasedMatcher and std::vector

有些话、适合烂在心里 提交于 2019-12-24 13:41:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!