【问题标题】:Runtime error with OpenCV and MinGW?OpenCV 和 MinGW 的运行时错误?
【发布时间】:2014-03-31 11:03:53
【问题描述】:

我正在尝试在 OpenCV 的文档中运行一个示例,如下所示

#include <iostream>
#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv\cv.h>


int main(int argc, char **argv)
{   
    cv::VideoCapture cap(0);
    if ( !cap.isOpened())
    {
        std::cout << "Error with opening Camera" << std::endl;
        return -1;
    }

    cv::Mat frame, edges;
    cv::namedWindow("edges", 1);
    for(;;)
    {
        cap >> frame;
        cvtColor(frame, edges, CV_BGR2GRAY);
        GaussianBlur(edges, edges, cv::Size(7,7), 1.5, 1.5);
        Canny(edges, edges, 0, 30, 3);
        cv::imshow("edges", edges);
        if ( cv::waitKey(30) >= 0) break;
    }

    return 0;
}

我有if statement 来检查相机是否有任何问题,它应该终止程序,但事实并非如此。这是我得到的错误

OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file C:\opencv_2_4_8\opencv\sources\modules\imgproc\src\color.cpp, line 3737
terminate called after throwing an instance of 'cv::Exception'
  what():  C:\opencv_2_4_8\opencv\sources\modules\imgproc\src\color.cpp:3737: error: (-215) scn == 3 || scn == 4 in function cvtColor


This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

【问题讨论】:

    标签: c++ windows opencv mingw qt5


    【解决方案1】:

    通过查看“color.cpp”中的OpenCV代码,看起来错误中提到的变量“scn”是帧的通道数,转换类型(BGR->灰度)需要有3 或 4 个通道:

    断言失败(scn == 3 || scn == 4)

    您确定您的相机默认不提供灰度图像吗?尝试注释掉处理框架的行并仅显示检索到的图像,看看你得到了什么。或者只是在帧捕获之后放置一个断点并检查“帧”变量 - 它是空的吗?是否有预期的大小等等?

    【讨论】:

    • 其实是因为凸轮有问题,所以显示的是灰色图像。我确实禁用了凸轮,但它不是凸轮,我的意思是 if 语句。感谢您的建议。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-27
    • 2012-01-21
    • 1970-01-01
    • 1970-01-01
    • 2013-01-14
    • 1970-01-01
    相关资源
    最近更新 更多