堆腐败使用cv :: FlannBasedMatcher和std :: vector [英] Heap Corruption using cv::FlannBasedMatcher and std::vector

查看:152
本文介绍了堆腐败使用cv :: FlannBasedMatcher和std :: vector的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一种用于对象识别的乳房成像特征,使用FlannBasedMatcher来计算空间直方图。

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



当结束执行if(features.rows> 0)范围。


I get an error when ending the execution of the if(features.rows > 0) scope. Can you helpme?

推荐答案

尝试输入

matches.reserve(size) 

任何元素。这是必要的,如果你使用OpenCV 2.2,但不是与2.9

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

这篇关于堆腐败使用cv :: FlannBasedMatcher和std :: vector的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆