簡體   English   中英

C ++ OpenCVroxPolyDP導致未處理的異常

[英]c++ OpenCV approxPolyDP causes Unhandled exception

嗨,我正在做有關輪廓的學校項目。 一切工作正常,直到我嘗試使用VS2012引發此錯誤:hugh.exe中0x000007FEFD0E940D的未處理異常:Microsoft C ++異常:內存位置0x00000000002DEC40的cv :: Exception。

我認為該代碼應該很好,所以這就是為什么我有點迷路的原因。

這是我的代碼,感謝所有幫助:

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

請檢查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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM