Open machinekoder opened 5 years ago
The output format should also be selectable. BGR8 is hard-coded.
@machinekoder OpenCV only guarantees support for reading BGR8 from video streams. See these references:
Sorry for late response.
@J-Rojas I think what @machinekoder mentioned about is not about format of published image messages but image data format captured from v4l2 camera device.
@machinekoder Currently since we don't specify any option to set pixel format for v4l2 camera device, OpenCV tries to set possible format in certain order.
( https://github.com/opencv/opencv/blob/f663e8f903645a3dd66f6833f63717b86e861d77/modules/videoio/src/cap_v4l.cpp#L485 )
Looking at the code, it looks we can change the format by setting cv::CAP_PROP_FOURCC
( https://github.com/opencv/opencv/blob/f663e8f903645a3dd66f6833f63717b86e861d77/modules/videoio/src/cap_v4l.cpp#L1832 )
I'll create a PR to support the feature when I have time.
I was able to get images from the MJPG stream by adding the following in this line:
cap->set(cv::CAP_PROP_FOURCC, cv::VideoWriter::fourcc('M','J','P','G'));
It worked, but the CPU usage went through the roof... not sure if that's expected, but I'd appreciate if anyone had any ideas on how to overcome high CPU usage, or whether that'll be a given for getting data from a MJPG stream
Is there a way to select the v4l2 cameras pixel format when starting the opencv stream?
It looks like it selects the uncompressed stream per default on my device, which rather slow at 1080p even with USB 3.0.