OpenCV capture YUYV from camera without RGB conver

2019-05-07 17:28发布

I trying to use openCV/c++ to capture the left and right image from a LI-USB30_V024 stereo camera without automatically converting it to RGB. The camera outputs images in YUYV format.

I have tried using videoCapture.set(CV_CAP_PROP_CONVERT_RGB, false) but I get the message "HIGHGUI ERROR: V4L: Property (16) not supported by device".

The reason I want to avoid the conversion to RGB is because the camera packages the left and right video together in to a single YUYV image. Both cameras are monochrome, and as far as I can tell the left image information is encoded in the Y channels while the right image is encoded in the U and V channels. For example if I run guvcview I get a single image that contains both the left and right images superpositioned. It looks like a black and white image (the left image is encoded in the Y channels) with a green and pink image lying on top (the right camera is encoded in the UV channels). I know this sounds pretty unusual so if you have any other ideas/questions about it then don't hesitate.

My goal is to capture the image as YUYV so that I can use split() to separate the left image (Y channels) from the right image (U and V channels) and display them both as monochrome images. However, once the image has been converted to RGB the luminance and chominance channels get blended together and it becomes impossible to separate the two images.

To sum it up, I need to capture the video without converting it to RGB so that the YUYV format is preserved. This will allow me to separate the left and right images.

OR I need a way of capturing the left and right images separately, but I think this is unlikely.

I think this would be possible in v4l, but I would prefer to only use openCV if possible.

Thanks!

3条回答
Anthone
2楼-- · 2019-05-07 17:55

I dont think there is a way to do this in openCV. In the end it wasn't too much trouble to capture frames with V4L2 and store them in openCV Mats.

查看更多
太酷不给撩
3楼-- · 2019-05-07 17:59

In header file videoio.hpp:

// Generic camera output modes.
// Currently, these are supported through the libv4l interface only.
enum { CAP_MODE_BGR  = 0, // BGR24 (default)
       CAP_MODE_RGB  = 1, // RGB24
       CAP_MODE_GRAY = 2, // Y8
       CAP_MODE_YUYV = 3  // YUYV
     };

Usage:

cv::VideoCapture camera = cv::VideoCapture();
camera.open(0);
camera.set(CV_CAP_PROP_MODE, CV_CAP_MODE_YUYV);
查看更多
等我变得足够好
4楼-- · 2019-05-07 18:12

I used to wrok on a camera which produce YUV420 data,and got some problem in configuring it. But this function works for me.

videoCapture.set(CV_CAP_PROP_CONVERT_RGB, 0)

Can you check if there is any other configuration that cause the problem.

查看更多
登录 后发表回答