无法在opencv

时间:2017-09-19 04:48:50

标签: c++ opencv

我正在尝试阅读视频文件,但它的抛出错误。 代码是:

#include <iostream>
#include <opencv/highgui.h>
#include <opencv/cv.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char* argv[])
{
    Mat inputVideo;
    Mat frame;
    Mat HSV;
    Mat tracking;
    char checkKey;
    VideoCapture capture;
    capture.open("video/input.mp4");
    capture.set(CV_CAP_PROP_FRAME_WIDTH, 640);
    capture.set(CV_CAP_PROP_FRAME_HEIGHT,480);      
    namedWindow("Original Video", WINDOW_AUTOSIZE );
    while(1){
        capture.read(inputVideo);
        if (!inputVideo.empty())
        {
            imshow("Original Video",inputVideo);

        }
        waitKey(20);

    }
    return 0;
 }

运行此代码时,我得到的错误是:

  

无法停止信息流:设备不适当的ioctl

     

(video_reading:3459):GLib-GObject-CRITICAL **:g_object_set:   断言'G_IS_OBJECT(对象)'失败

     

我尝试寻找解决方案,但我没有得到它。有人可以帮助我解决这个错误。

1 个答案:

答案 0 :(得分:0)

我对你的代码做了一些改动。试试这个:

#include <iostream>
#include <opencv/highgui.h>
#include <opencv/cv.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char* argv[])
{
    Mat inputVideo;
    Mat frame;
    Mat HSV;
    Mat tracking;
    char checkKey;
    VideoCapture capture;
    capture.open("video/input.mp4");
    capture.set(CV_CAP_PROP_FRAME_WIDTH, 640);
    capture.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
    namedWindow("Original Video", WINDOW_AUTOSIZE);
    while (1) {
        capture >> inputVideo;
        if (inputVideo.empty())
            break;
        imshow("Original Video", inputVideo);
        waitKey(1);
    }
    capture.release();
    return 0;
}