簡體   English   中英

OpenCV和MinGW的運行時錯誤?

[英]Runtime error with OpenCV and MinGW?

我正在嘗試在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來檢查Camera是否有任何問題,它應該終止程序,但事實並非如此。 這是我得到的錯誤

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.

通過查看“ color.cpp”中的OpenCV代碼,看起來錯誤中提到的變量“ scn”是幀的通道數,並且轉換類型(BGR->灰度)要求為3或4渠道:

斷言失敗(scn == 3 || scn == 4)

您確定默認情況下相機不提供​​灰度圖像嗎? 嘗試注釋掉處理框架的行,並僅顯示檢索到的圖像,然后看看您得到了什么。 還是僅在捕獲幀之后放置一個斷點並檢查“ frame”變量-它是否為空? 它具有預期的尺寸等嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM