Ask Your Question

tumbleweed's profile - activity

2019-04-29 05:06:00 -0500 received badge  Popular Question (source)
2014-08-09 09:06:20 -0500 received badge  Self-Learner (source)
2014-08-09 08:31:35 -0500 answered a question Debayering / demosaicing BGR image?

It turns out that this camera wraps 12 bits of Bayered color information into each 16 bits and publishes this as "YUYV 4:2:2" via UVC. The normal OpenCV VideoCapture stack interprets that as YUYV and performs RGB/ BGR color conversion on it.
The workaround was to patch cap_libv4l to unwrap the "YUYV" (which isn't actually YUYV) and debayer/demosaic it.

2014-08-05 00:44:16 -0500 received badge  Student (source)
2014-08-04 12:17:54 -0500 asked a question Debayering / demosaicing BGR image?

I'm using OpenCV 2.4.8.2 with V4L2 connected to a UVC camera that claims to provide "raw" video. I've attached a (jpeg compressed) shot from a single frame provided by opencv's VideoCapture:
image description

If I run:

$ v4l2-ctl -V
Format Video Capture:
    Width/Height  : 1280/720
    Pixel Format  : 'YUYV'
    Field         : None
    Bytes per Line: 2560
    Size Image    : 1843200
    Colorspace    : Unknown (00000000)
$v4l2-ctl --list-formats
ioctl: VIDIOC_ENUM_FMT
    Index       : 0
    Type        : Video Capture
    Pixel Format: 'YUYV'
    Name        : YUV 4:2:2 (YUYV)

This appears to be a Bayered image, but opencv's VideoCapture has already split it into BGR24 format. Looking at cv:demosaicing I see that all of the Bayer2Foo methods require a source image has only one channel ...but the image VideoCapture provides already has three channels.

Digging deeper into the VideoCapture sources, it appears that opencv's icvRetrieveFrameCAM_V4L immediately performs yuyv_to_rgb24 on any video source with a detected palette of YUYV. My guess is that bayer2rgb24 would be more appropriate in this case, but I don't see a way to tell icvRetrieveFrameCAM_V4L to try that instead.

Any suggestions on a path forward here? I can't really change what the camera outputs, and apparently icvRetrieveFrameCAM_V4L will always generate BGR24. Is there a straightforward way to map this BGR24 format back to a format that can be demosaiced/debayered? The only alternative I can see is to write our own custom driver to pull images from the camera and skip VideoCapture altogether.

Thanks for any help!