[英]c++ OpenCV approxPolyDP causes Unhandled exception
Hi i am working on my school project regarding contours. 嗨,我正在做有关轮廓的学校项目。 Everything worked fine until i tried to use approxPolyDP which causes my VS2012 to throw this: Unhandled exception at at 0x000007FEFD0E940D in hugh.exe: Microsoft C++ exception: cv::Exception at memory location 0x00000000002DEC40. 一切工作正常,直到我尝试使用VS2012引发此错误:hugh.exe中0x000007FEFD0E940D的未处理异常:Microsoft C ++异常:内存位置0x00000000002DEC40的cv :: Exception。
I think that code should be fine, so thats why i am kinda lost. 我认为该代码应该很好,所以这就是为什么我有点迷路的原因。
Here is my code, all help is appreciated: 这是我的代码,感谢所有帮助:
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <sstream>
#include <string>
#include <iostream>
#include <opencv\highgui.h>
#include <opencv\cv.h>
#include <opencv\ml.h>
#include <math.h>
using namespace cv;
using namespace std;
vector<vector<Point> > contours0;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
int main( int argc, char** argv )
{
const char* filename = argc >= 2 ? argv[1] : "pic1.jpg";
Mat src = imread(filename, 0);
if(src.empty())
{
cout << "can not open " << filename << endl;
return -1;
}
Mat out;
Canny(src, out, 100,400, 3);
out = out > 1;
namedWindow( "Source", 1 );
imshow( "Source", out );
findContours( out, contours0, hierarchy,
CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE );
contours.resize(contours0.size());
for( size_t k = 0; k < contours0.size(); k++ ){
approxPolyDP(Mat(contours0[k]), contours[k], 3, true);
}
int idx = 0;
for( ; idx >= 0; idx = hierarchy[idx][0] )
{
drawContours( src, contours0, idx, Scalar(128,255,255), 5, 8, hierarchy );
}
namedWindow( "Components", 1 );
imshow( "Components", src );
waitKey(0);
}
Please check you windows environment variable settings and make sure the environment variable is set correctly and matches Visual Studio version For Visual studio 2012, the path variable should use: %opencv%\\build\\x86\\vc11\\bin For Visual Studio 2013, the path variable should be: %opencv%\\build\\x86\\vc12\\bin 请检查Windows环境变量设置,并确保正确设置了环境变量并匹配Visual Studio版本对于Visual Studio 2012,路径变量应使用:%opencv%\\ build \\ x86 \\ vc11 \\ bin对于Visual Studio 2013,路径变量应为:%opencv%\\ build \\ x86 \\ vc12 \\ bin
This is a helpful link for setting up environment: http://blog.amastaneh.com/2014/03/opencv-on-visual-studio-2013.html 这是设置环境的有用链接: http : //blog.amastaneh.com/2014/03/opencv-on-visual-studio-2013.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.