2014-02-20 135 views
1

嗨,我正在研究关于轮廓的学校项目。一切工作正常,直到我试图使用approxPolyDP这会导致我的VS2012抛出:在hugh.exe中的0x000007FEFD0E940D处未处理的异常:Microsoft C++异常:cv ::内存位置0x00000000002DEC40处的异常。C++ OpenCV approxPolyDP导致未处理的异常

我认为代码应该没问题,所以这就是为什么我有点失落。

这里是我的代码,所有的帮助表示赞赏:

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

回答

0

请检查您的Windows环境变量设置,确保环境变量设置正确,并且匹配的Visual Studio版本 对于Visual Studio 2012,路径变量应该使用:%opencv%\ build \ x86 \ vc11 \ bin 对于Visual Studio 2013,路径变量应该是:%opencv%\ build \ x86 \ vc12 \ bin

这是建立环境: http://blog.amastaneh.com/2014/03/opencv-on-visual-studio-2013.html

相关问题