QTQuick, OpenCv and Gstreamer frame capturing
-
I am new and using the QT for streaming gstreamer video (now from webcam) to QML using QMediaPlayer. It works when I only run the video stream part but I want to take these video frames and process it to find some objects using openCV. How can I capture these frames using VideoCapture and gstreamer pipeline as it is. Or could you suggest another qt way to garb a frame?
My main.cpp is below;
QMediaPlayer* player = new QMediaPlayer(); auto qmlPlayer = engine.rootObjects()[0]->findChild<QObject*>("player"); player = qvariant_cast<QMediaPlayer*>(qmlPlayer->property("mediaObject")); player->setMedia(QUrl("gst-pipeline: v4l2src device=/dev/video0 ! videoconvert ! videoscale ! video/x-raw,width=1280,height=720 ! qtvideosink")); player->play(); cv::VideoCapture* cap; cv::Mat img; cap = new VideoCapture(CAP_GSTREAMER); bool deneme = cap->isOpened(); if (!deneme){ qInfo() << "false"; }
Above code works when there is no videoCapture but if I run it like this I get errors below.
libv4l2: error setting pixformat: Device or resource busy [ WARN:0] global /home/elif/opencv-4.5.4/source/modules/videoio/src/cap_gstreamer.cpp (2076) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src1 reported: Device '/dev/video0' is busy [ WARN:0] global /home/elif/opencv-4.5.4/source/modules/videoio/src/cap_gstreamer.cpp (1053) open OpenCV | GStreamer warning: unable to start pipeline [ WARN:0] global /home/elif/opencv-4.5.4/source/modules/videoio/src/cap_gstreamer.cpp (616) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created false libv4l2: error got 4 consecutive frame decode errors, last error: v4l-convert: error unexpected width / height in JPEG header: expected: 1280x720, header: 160x120 Error: "Failed to allocate a buffer"
My versions:
QT: 5.15.2 OpenCV: 4.5.4 Gstreamer: 1.0