2013-10-15 17 views
0

我是新來的Visual Studio。我不斷收到一個錯誤:Unhadled例外PROJECT1.EXE 在[某些內存位置]時出現的內存位置不斷每個我打了調試時間不斷變化的。我已經嘗試了非常簡單的代碼,但仍然不斷收到此錯誤。未處理的異常在Visual Studio中同時使用開放CV

,當我調試也將打開窗口給出一個錯誤:

OpenCV的錯誤:斷言未知函數失敗(SCN == 3 || SCN == 4),文件.. \ .. \。 \ SRC \ OpenCV的\模塊\ imgproc的\ src \ color.cpp,線路3042

我跑的代碼是:

#include <stdio.h> 
    #include <iostream> 
    #include <vector> 
    #include "opencv2/core/core.hpp" 
    #include "opencv2/features2d/features2d.hpp" 
    #include "opencv2/highgui/highgui.hpp" 
    #include "opencv2/calib3d/calib3d.hpp" 
    #include "opencv2/video/video.hpp" 
    #include "opencv2/opencv.hpp" 
    using namespace cv; 
    using namespace std; 

    int main (int argc, char *argv[]) 
    { 
     cv::Mat frame; 
     cv::Mat back; 
     cv::Mat fore; 
     cv::Mat edges; 
     VideoCapture cap (0); 
     BackgroundSubtractorMOG2 bg; 
     bg.set ("nmixtures", 3); 
     bg.set ("detectShadows", false); 
     std::vector < std::vector <cv::Point> >contours; 

     cv::namedWindow ("Frame"); 
     cv::namedWindow ("Background"); 

     for (;;) 
     { 
      cap >> frame; 
      cvtColor(frame, edges, CV_BGR2GRAY); 

      GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5); 

      Canny(edges, edges, 0, 30, 3); 

      imshow("edges", edges); 

      if(waitKey(30) >= 0) break; 

     } 
     return 0; 
    } 
+0

該斷言失敗表示某些功能的輸入圖像沒有3或4個通道。您發佈的代碼對我無影響。所以這不是完整的代碼? – OpenMinded

回答

1

您需要檢查frame是有效的,即!frame.empty()或而不是for(;;)我們Ëwhile(cap >> frame)
當捕獲到達文件的末尾時,您會收到一個空幀,導致cvtColor()因該錯誤而失敗。

相關問題