c++ - 使用 cv::FlannBasedMatcher 和 std::vector 的堆损坏

标签 c++ opencv vector feature-extraction heap-corruption

我正在开发用于对象识别的乳房成像功能,使用 FlannBasedMatcher 计算空间直方图。

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;
}

结束执行 if(features.rows > 0) 范围时出现错误。你能帮我吗?

最佳答案

尝试放置

matches.reserve(size) 

在插入任何元素之前使用 vector 的实际大小。如果您使用的是 OpenCV 2.2,这是必需的,但不是 2.9

关于c++ - 使用 cv::FlannBasedMatcher 和 std::vector 的堆损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30787348/

相关文章:

c++ - Mac C++/eclipse 无法调试 : Error while launching command: gdb --version

opencv - 我收到错误。我想反对计数

opencv - 使用 OpenCV 识别鼠标行为的重复运动模式

C++:结构中的 vector ,push_back 错误

c++ - 循环为 vector<struct> 元素生成大写字符

c++ - BGL 中的 slistS 发生了什么?

c++ - C++ 中的静态类

c++ - C++ 中的运算符重载 "<<"

python - 如何在Python中使用OpenCV提高Caffe的性能?

c++ - C++ 中真正空的 std::vector 是什么?