Ask Your Question
1

Debayering / demosaicing BGR image?

asked 2014-08-04 12:17:54 -0600

tumbleweed gravatar 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!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-08-09 08:31:35 -0600

tumbleweed gravatar 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.

edit flag offensive delete link more

Comments

I am having this exact same issue. Can you give more detail about how you solved this?

jnj11 gravatar imagejnj11 ( 2015-07-27 08:44:34 -0600 )edit

Question Tools

Stats

Asked: 2014-08-04 12:17:54 -0600

Seen: 3,397 times

Last updated: Aug 17 '14