调试断言失败vc \include\vector向量迭代器+偏移超出范围在chamferMatching Opencv [英] debug assertion failed vc\include\vector vector iterator + offset out of range in chamferMatching Opencv
问题描述
在OpenCV中实施倒角匹配程序时遇到问题
https:// code.ros.org/trac/opencv/browser/trunk/opencv /samples/cpp/chamfer.cpp?rev=4194
以下是正在读取的代码
template image
和测试图片
,我使用VS 2008和OpenCV2.4.6
#includestdafx.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\\\\\ logo.png,1);
Mat tpl = cvarrToMat(src);
imshow(Mat,tpl);
Mat cimg;
//如果图像和模板不是边缘地图,而是正常的灰度图像,
//您可能想要取消注释以下行以生成地图。你也可以
//运行Sobel而不是Canny。
Canny(img,img,5,50,3);
Canny(tpl,tpl,5,50,3);
vector< vector< Point> >结果;
vector< float>成本;
int best = chamerMatching(img,tpl,results,costs);
if(best< 0)
{
cout<< not found; \\\
;
return 0;
}
size_t i,n = results [best] .size();
for(i = 0; 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和图像处理
我有同样的问题。解决方案: http://code.opencv.org/issues/3603
您需要从源下载opencv,打开chamfermatching.cpp和注释行:
〜Matching()
{
for(size_t i = 0; i< templates.size(); i ++){
// delete templates [i];
}
}
然后你需要重建opencv。之后它应该工作。
I am stuck with the problem while implementing chamfer matching program in OpenCV
https:// code.ros.org/trac/opencv/browser/trunk/opencv/samples/cpp/chamfer.cpp?rev=4194
Following is the code it is reading template image
and test image
, I am using VS 2008 and 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;
}
this is the error image
can you suggest me why I am getting this error as I am new to OpenCV and Image Processing
I had same problem. Solution: http://code.opencv.org/issues/3603 You need to download opencv from source, open the chamfermatching.cpp and comment line:
~Matching()
{
for (size_t i = 0; i<templates.size(); i++) {
//delete templates[i];
}
}
Then you need to rebuild opencv. After this it should work.
这篇关于调试断言失败vc \include\vector向量迭代器+偏移超出范围在chamferMatching Opencv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!