2014-02-20 136 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

相關問題