简体   繁体   中英

How to open GStreamer pipeline in OpenCV

I'm a software engineer in South Korea.

I'm trying to open webm video using GStreamer pipeline in opencv program But I can't find any solution to figure out it.

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

Below is my code.

#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;

}


It is very simple code like Tutorial. But I can't open VieoCapure cap...

Anybody have tried this project or figured out?

Best regard

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";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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