[英]OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cv:: cvtColor, file ..\..\..\..\opencv\modules\imgproc\src\color.cpp, line 3737
Hi I am trying to run this sample code from OpenCV: 您好我试图从OpenCV运行此示例代码:
#include "opencv2\opencv.hpp"
using namespace cv;
int main(int, char**)
{
VideoCapture cap(0); // open the default camera
if (!cap.isOpened()) // check if we succeeded
return -1;
Mat edges;
namedWindow("edges", 1);
for (;;)
{
Mat frame;
cap >> frame; // get a new frame from camera
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;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
I am currently using a Windows 7 x64 BootCamp on a Macbook Pro. 我目前在Macbook Pro上使用Windows 7 x64 BootCamp。 I'm running this code with Visual Studios 2013 and OpenCV 2.4.9. 我正在使用Visual Studios 2013和OpenCV 2.4.9运行此代码。
This is how I've set up my Config Properties: 这就是我设置配置属性的方法:
VC++ Directories: Include Directories: H:\opencv\build\include;$(IncludePath)
Linker:General:Additional Library Directories: H:\opencv\build\x64\vc12\lib;%(AdditionalLibraryDirectories)
Linker:Input:Additional Dependencies: opencv_calib3d249.lib;opencv_contrib249.lib;opencv_core249.lib;opencv_features2d249.lib;opencv_flann249.lib;opencv_gpu249.lib;opencv_highgui249.lib;opencv_imgproc249.lib;opencv_legacy249.lib;opencv_ml249.lib;opencv_nonfree249.lib;opencv_objdetect249.lib;opencv_ocl249.lib;opencv_photo249.lib;opencv_stitching249.lib;opencv_superres249.lib;opencv_ts249.lib;opencv_video249.lib;opencv_videostab249.lib;%(AdditionalDependencies)
When I click on Local Windows Debugger in Release x64 mode I get the following error from Visual Studios: 当我在Release x64模式下单击Local Windows Debugger时,我从Visual Studios收到以下错误:
First-chance exception at 0x000007FEFD21B3DD in Project3.exe: Microsoft C++ exception: cv::Exception at memory location 0x000000000019A8A0. Project3.exe中0x000007FEFD21B3DD的第一次机会异常:Microsoft C ++异常:cv ::内存位置0x000000000019A8A0的异常。
If there is a handler for this exception, the program may be safely continued. 如果存在此异常的处理程序,则可以安全地继续该程序。
When I click Break instead (scared to press Continue), a window named Edges does pop up and the camera does turn on since the green light turns on. 当我单击Break而不是(害怕按Continue)时,会弹出一个名为Edges的窗口,并且自绿灯亮起后相机会打开。 But I also get the following error in the command window: 但我也在命令窗口中收到以下错误:
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cv:: cvtColor, file ........\\opencv\\modules\\imgproc\\src\\color.cpp, line 3737 OpenCV错误:断言失败(scn == 3 || scn == 4)在cv :: cvtColor中,文件........ \\ opencv \\ modules \\ imgproc \\ src \\ color.cpp,第3737行
I'm pretty new to C++ and Visual Studios, any help would be appreciated. 我是C ++和Visual Studios的新手,任何帮助都会受到赞赏。 Thanks in advance! 提前致谢!
From the conversation in the comments to the question, we saw that VideoCapture
gives frame in grayscale. 从评论中的对话到问题,我们看到VideoCapture
以灰度显示帧。 So the call to cvtColor
caused the crash. 因此,对cvtColor
的调用导致了崩溃。
...
Mat frame;
cap >> frame; // frame is already CV_8UC1
//cvtColor(frame, edges, CV_BGR2GRAY); // so don't to convert here, or crash!
edges = frame.clone();
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.