2016-11-19 33 views
-1

実行時にOpenCV findContoursに問題があります。私はエラーが何であるかをよく理解していません。ビルド中にエラーはありません。ここOpenCV findContours()エラーVS2015 Opencv2413

はエラーメッセージである:ここ

[Error when run] 1

私のコードである:

#include <iostream> 
#include "opencv2/highgui/highgui.hpp" 
#include "opencv2/imgproc/imgproc.hpp" 

using namespace cv; 
using namespace std; 

int main(int argc, char** argv) 
{ 
    VideoCapture cap(0); //capture the video from web cam 

    if (!cap.isOpened()) // if not success, exit program 
    { 
     cout << "Cannot open the web cam" << endl; 
     return -1; 
    } 

    namedWindow("Control", CV_WINDOW_AUTOSIZE); //create a window called "Control" 

    int iLowH = 0; 
    int iHighH = 179; 

    int iLowS = 0; 
    int iHighS = 255; 

    int iLowV = 0; 
    int iHighV = 255; 

    //Create trackbars in "Control" window 
    cvCreateTrackbar("LowH", "Control", &iLowH, 179); //Hue (0 - 179) 
    cvCreateTrackbar("HighH", "Control", &iHighH, 179); 

    cvCreateTrackbar("LowS", "Control", &iLowS, 255); //Saturation (0 - 255) 
    cvCreateTrackbar("HighS", "Control", &iHighS, 255); 

    cvCreateTrackbar("LowV", "Control", &iLowV, 255); //Value (0 - 255) 
    cvCreateTrackbar("HighV", "Control", &iHighV, 255); 

    while (true) 
    { 
     Mat imgOriginal; 

     bool bSuccess = cap.read(imgOriginal); // read a new frame from video 

     if (!bSuccess) //if not success, break loop 
     { 
      cout << "Cannot read a frame from video stream" << endl; 
      break; 
     } 

     Mat imgHSV; 

     cvtColor(imgOriginal, imgHSV, COLOR_BGR2HSV); //Convert the captured frame from BGR to HSV 

     Mat imgThresholded; 

     inRange(imgHSV, Scalar(iLowH, iLowS, iLowV), Scalar(iHighH, iHighS, iHighV), imgThresholded); //Threshold the image 

                             //morphological opening (remove small objects from the foreground) 
     erode(imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(5, 5))); 
     dilate(imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(5, 5))); 

     //morphological closing (fill small holes in the foreground) 
     dilate(imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(5, 5))); 
     erode(imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(5, 5))); 

     vector<vector<Point> > contours; 
     vector<Vec4i> hierarchy; 

     findContours(imgThresholded, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0)); 

     imshow("Thresholded Image", imgThresholded); //show the thresholded image 
     imshow("Original", imgOriginal); //show the original image 

     if (waitKey(30) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop 
     { 
      cout << "esc key is pressed by user" << endl; 
      break; 
     } 
    } 

    return 0; 

} 
+0

最小限のコードを再現すると、このように答えることは不可能です。このエラーから、メモリにアクセスしているように見えますが、必要な入力を割り当てられていない可能性があります。 http://stackoverflow.com/questions/1102123/debug-assertion-failed-expression-block-type-is-validのように – stijn

+0

あなたがリンクしているOpenCVライブラリの完全な名前は何ですか?この場合、デバッグモードまたはリリースモードでアプリケーションをコンパイルしましたか? –

+0

@DanMašek私はデバッグモードでコンパイルします。ライブラリのリスト:opencv_core2413d.lib opencv_imgproc2413d.lib opencv_highgui2413d.lib opencv_ml2413d.lib opencv_video2413d.lib opencv_features2d2413d.lib opencv_calib3d2413d.lib opencv_legacy2413d.lib opencv_objdetect2413d.lib opencv_contrib2413d.lib opencv_flann2413d.lib –

答えて

0

実際、これはVS2013、VS2015とOpenCVの間の既知の互換性エラーです。一時的な解決策は、復帰前に以下の2行を追加することです。

cv::imshow("img", threshold); 
cv::destroyAllWindows(); 
+0

Dan Masek、改善してくれてありがとう。また@Tom、findContoursのエラーを取り除くのに役立ちました。追加ラインの理由は何ですか? –

関連する問題