gpt4 book ai didi

c++ - OpenCV 错误:cv::cvtColor 中的断言失败 (scn == 3 || scn == 4),文件 ..\..\..\..\opencv\modules\imgproc\src\color.cpp,第 3737 行

转载 作者:可可西里 更新时间:2023-11-01 18:38:26 25 4
gpt4 key购买 nike

您好,我正在尝试从 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;
}

我目前在 Macbook Pro 上使用 Windows 7 x64 BootCamp。我正在使用 Visual Studios 2013 和 OpenCV 2.4.9 运行此代码。

这就是我设置配置属性的方式:

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)

当我在 Release x64 模式下单击 Local Windows Debugger 时,我从 Visual Studios 收到以下错误:

First-chance exception at 0x000007FEFD21B3DD in Project3.exe: Microsoft C++ exception: cv::Exception at memory location 0x000000000019A8A0.

If there is a handler for this exception, the program may be safely continued.

当我改为单击 Break(不敢按 Continue)时,会弹出一个名为 Edges 的窗口,并且相机会打开,因为绿灯亮起。但是我在命令窗口中也收到以下错误:

OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cv:: cvtColor, file ........\opencv\modules\imgproc\src\color.cpp, line 3737

我是 C++ 和 Visual Studios 的新手,如有任何帮助,我们将不胜感激。提前致谢!

最佳答案

从评论中的对话到问题,我们看到 VideoCapture 给出了灰度帧。所以对 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();
...

关于c++ - OpenCV 错误:cv::cvtColor 中的断言失败 (scn == 3 || scn == 4),文件 ..\..\..\..\opencv\modules\imgproc\src\color.cpp,第 3737 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31297841/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com