Hello,
I want to capture the camera video and use Gstreamer pipeline in OpenCV. The camera’s output pixel format is UYVY 8bit. It works fine using gst-launch-1.0 directly.
gst-launch-1.0 v4l2src device=/dev/video0 ! 'video/x-raw, format=(string)UYVY, width=(int)1920, height=(int)1080, framerate=(fraction)30/1' ! xvimagesink -ev
Then I build OpenCV3.4.6 with Gstreamer and use VideoCapture to fetch the video.
When I use OpenCV COLOR_YUV2BGR_UYVY, it can display on the screen however the CPU usage is high.
string pipeline = "v4l2src device=/dev/video0 !
video/x-raw, width=(int)1920, height=(int)1080,
format=(string)UYVY, framerate=(fraction)30/1 ! appsink";
VideoCapture cap(pipeline,CAP_GSTREAMER);
// View video
Mat frame;
while (1) {
cap >> frame; // Get a new frame from camera
Mat bgr;
cvtColor(frame, bgr, COLOR_YUV2BGR_UYVY);
// Display frame
imshow("Display window", bgr);
waitKey(1); //needed to show frame
}
Then, I try to use nvvidconv to transfer UYVY to BGR format. The code is like:
string pipeline = "-v v4l2src device=/dev/video0 ! video/x-raw, width=(int)1920, height=(int)1080, format=(string)UYVY, framerate=(fraction)30/1
! nvvidconv ! video/x-raw(memory:NVMM), format=(string)BGR ! appsink";
VideoCapture cap(pipeline,CAP_GSTREAMER);
// View video
Mat frame;
while (1) {
cap >> frame; // Get a new frame from camera
// Display frame
imshow("Display window", frame);
waitKey(1); //needed to show frame
}
There is an error occurred.
(test_nvvidconv:18774): GStreamer-CRITICAL **: 20:28:25.106: gst_element_get_state: assertion 'GST_IS_ELEMENT (element)' failed
Is it a gstreamer problem?
Thank you very much.