简体   繁体   English

使用 C++、Opencv 和 GStreamer 捕获视频时出错

[英]Error capturing video using C++, Opencv and GStreamer

I have recently compiled Opencv 4.2.0 with Gstreamer 1.15.1 on 32-bit Windows platform.我最近在 32 位 Windows 平台上用 Gstreamer 1.15.1 编译了 Opencv 4.2.0。 When I try to capture a Video using Gstreamer backend the video capture fails.当我尝试使用 Gstreamer 后端捕获视频时,视频捕获失败。 Here is the code and output:这是代码和输出:

void main()
{
    VideoCapture cap("video/x-raw,format=YUV2,width=640,height=480,framerate=30/1 ! appsink", CAP_GSTREAMER);
   //VideoCapture cap(0,CAP_GSTREAMER);
    if (!cap.isOpened())
    {
        cout << "VideoCapture not opened" << endl;
        exit(-1);
    }

    Mat frame;

    while (true) {

        cap.read(frame);

        if (frame.empty())
            break;

        imshow("output", frame);
        if (waitKey(1) == 's')
            break;
    }
    destroyWindow("output");
}

Here is the output :这是输出:

(testNewOpencv.exe:7392): GStreamer-CRITICAL **: 20:08:16.574: gst_element_make_
from_uri: assertion 'gst_uri_is_valid (uri)' failed
[ WARN:0] global \modules\videoio\src\cap_gstreamer.cpp (713) cv::GStreamerCapture::open OpenCV | GStreamer warning: Error opening bin: no element "video"
[ WARN:0] global \modules\videoio\src\cap_gstreamer.cpp (480) cv::GStreamerCapture::isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
VideoCapture not opened

Any suggestions on resolving the issue?有关解决问题的任何建议?

Try this: "ksvideosrc device-index=0 ! videoscale ! videorate ! video/x-raw, width=640, height=480, framerate=30/1 ! videoconvert ! appsink"试试这个:“ksvideosrc device-index=0!videoscale!videorate!video/x-raw,width=640,height=480,framerate=30/1!videoconvert!appsink”

Works for me with your code and my just built OpenCV 4.3.0, gstreamer 1.15.1, 32-bit Windows 10, USB webcam.使用您的代码和我刚刚构建的 OpenCV 4.3.0、gstreamer 1.15.1、32 位 Windows 10、USB 网络摄像头对我有用。 I don't know gstreamer well enough to explain the pipeline -- I put it together from bits of search results.我不太了解 gstreamer 来解释管道——我从一些搜索结果中把它放在一起。

I think ksvideosrc is from gst-plugins-bad.我认为 ksvideosrc 来自 gst-plugins-bad。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM