0

我是 Visual Studio 的新手。我不断收到错误消息:Project1.exe 中的 [some memory location] 发生未处理的异常 每次我点击调试时,内存位置都会不断变化。我已经尝试过非常简单的代码,但我仍然不断收到这个错误。

我调试时打开的窗口也给出了错误:

OpenCV 错误:未知函数中的断言失败 (scn == 3 || scn == 4),文件 ..\..\..\src\opencv\modules\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;
    }
4

1 回答 1

1

You need to check that frame is valid, i.e. !frame.empty() or instead of for(;;) use while(cap >> frame).
When the capture reaches the end of the file you are getting an empty frame which causes cvtColor() to fail with that error.

于 2013-10-15T09:40:12.397 回答