如何在OpenCV中打开GStreamer管道

问题描述 投票:0回答:1

我正在尝试在 OpenCV 程序中使用 GStreamer 管道打开 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
;我该怎么做?

c++ opencv gstreamer
1个回答
0
投票

要在 cv::VideoCapture 中使用 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";
© www.soinside.com 2019 - 2024. All rights reserved.