【问题标题】:debug assertion failed vc\include\vector vector iterator + offset out of range in chamferMatching Opencv调试断言失败 vc\include\vector 向量迭代器 + chamferMatching Opencv 中的偏移量超出范围
【发布时间】:2013-10-11 12:03:51
【问题描述】:

我在 OpenCV 中实现倒角匹配程序时遇到了这个问题

https://code.ros.org/trac/opencv/browser/trunk/opencv/samples/cpp/chamfer.cpp?rev=4194

下面是它正在读取的代码 模板图片

和测试图像

,我正在使用 VS 2008 和 OpenCV2.4.6

#include "stdafx.h"

#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/contrib/contrib.hpp>
#include <iostream>
using namespace cv;
using namespace std;

int main( int argc, char** argv )
{    
    IplImage *src;
    src = cvLoadImage("C:\\Users\\JOSHI\\Desktop\\Images\\logo_in_clutter.png",1);      
    Mat img=cvarrToMat(src);  
    imshow("Mat",img); 

    src = cvLoadImage("C:\\Users\\JOSHI\\Desktop\\Images\\logo.png",1);  
    Mat tpl=cvarrToMat(src);  
    imshow("Mat",tpl); 
    Mat cimg;

    // if the image and the template are not edge maps but normal grayscale images,
    // you might want to uncomment the lines below to produce the maps. You can also
    // run Sobel instead of Canny.    
     Canny(img, img, 5, 50, 3);
     Canny(tpl, tpl, 5, 50, 3);    
    vector<vector<Point> > results;
    vector<float> costs;
    int best = chamerMatching( img, tpl, results, costs );
    if( best < 0 )
    {
        cout << "not found;\n";
        return 0;
    }    
    size_t i, n = results[best].size();
    for( i = 0; i < n; i++ )
    {
        Point pt = results[best][i];
        if( pt.inside(Rect(0, 0, cimg.cols, cimg.rows)) )
           cimg.at<Vec3b>(pt) = Vec3b(0, 255, 0);
    }
    imshow("result", cimg);

    waitKey();
    return 0;
}

这是错误图片

你能告诉我为什么我是 OpenCV 和图像处理的新手,为什么会出现这个错误

【问题讨论】:

    标签: c++ visual-studio-2008 opencv image-processing computer-vision


    【解决方案1】:

    我有同样的问题。解决方案:http://code.opencv.org/issues/3603 需要从源码下载opencv,打开chamfermatching.cpp和注释行:

    ~Matching()
    {
        for (size_t i = 0; i<templates.size(); i++) {
            //delete templates[i];
        }
    }
    

    然后你需要重建opencv。之后它应该可以工作了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-27
      • 1970-01-01
      • 2017-06-18
      • 2021-12-22
      • 1970-01-01
      • 1970-01-01
      • 2016-02-14
      • 2016-05-02
      相关资源
      最近更新 更多