如何在OpenCV中打开GSTREAMER管道

发布于 2025-01-26 19:41:17 字数 1113 浏览 2 评论 0原文

我正在尝试使用OpenCV程序中的Gstreamer Pipeline打开 WebM 视频。

我正在Visual Studio 19 Community IDE中使用OpenCV 3.4.1。

#include <opencv2/opencv.hpp>

int main()
{
    std::string pipeline = "playbin uri=https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm";
    std::cout << "Using pipeline: \n" << pipeline << "\n";

    cv::VideoCapture cap(pipeline, cv::CAP_GSTREAMER);

    if (!cap.isOpened()) {
        std::cout << "Failed to open camera." << std::endl;
        return (-1);
    }

    cv::namedWindow("CSI Camera", cv::WINDOW_AUTOSIZE);
    cv::Mat img;

    std::cout << "Hit ESC to exit" << "\n";
    while (true)
    {
        if (!cap.read(img)) {
            std::cout << "Capture read error" << std::endl;
            break;
        }

        cv::imshow("CSI Camera", img);
        int keycode = cv::waitKey(10) & 0xff;
        if (keycode == 27) break;
    }

    cap.release();
    cv::destroyAllWindows();
    return 0;
}

我无法打开vieocapture cap;我该怎么做?

I'm trying to open webm video using GStreamer pipeline in OpenCV program.

I'm using OpenCV 3.4.1 in Visual Studio 19 Community IDE.

#include <opencv2/opencv.hpp>

int main()
{
    std::string pipeline = "playbin uri=https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm";
    std::cout << "Using pipeline: \n" << pipeline << "\n";

    cv::VideoCapture cap(pipeline, cv::CAP_GSTREAMER);

    if (!cap.isOpened()) {
        std::cout << "Failed to open camera." << std::endl;
        return (-1);
    }

    cv::namedWindow("CSI Camera", cv::WINDOW_AUTOSIZE);
    cv::Mat img;

    std::cout << "Hit ESC to exit" << "\n";
    while (true)
    {
        if (!cap.read(img)) {
            std::cout << "Capture read error" << std::endl;
            break;
        }

        cv::imshow("CSI Camera", img);
        int keycode = cv::waitKey(10) & 0xff;
        if (keycode == 27) break;
    }

    cap.release();
    cv::destroyAllWindows();
    return 0;
}

I can't open VieoCapture cap; how do I do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌逼全场 2025-02-02 19:41:17

要在CV ::视频贴上使用GSTREAMER管道,它必须以AppSink结束。 AppSink是GSTREAMER元素,允许应用程序(在这种情况下为OpenCV)将缓冲区从管道中取出。

修改管道以如下图:

std::string pipeline = "uridecodebin uri=https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm ! videoconvert ! video/x-raw,format=RGB ! appsink";

To use a GStreamer pipeline in a cv::VideoCapture it must end in an appsink. The appsink is a GStreamer element that allows an application (in this case OpenCV) to take buffers out of the pipeline.

Modify your pipeline to look like the following:

std::string pipeline = "uridecodebin uri=https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm ! videoconvert ! video/x-raw,format=RGB ! appsink";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文