Document Actions

How to enable raw streaming on Logitech webcams

Explains how to retrieve raw Bayer streaming data from Logitech UVC cameras.

Purpose

Logitech UVC cameras support streaming of raw Bayer data through the use of UVC extension controls. This document explains how to enable this feature and provides sample programs.

Prerequisities

You need a Logitech UVC camera running on Linux or Windows to follow this how-to. On Windows the Logitech UVC driver which comes with the product is required.

If you are planning to use the Bayer mode with a QuickCam Pro 9000, QuickCam Pro for Notebooks, or QuickCam Orbit/Sphere AF please refer to the following article. Unfortunately certain versions do not support Bayer mode:

How many versions of the QuickCam Pro 9000 are there?

If you don't know what raw/Bayer mode is you're probably not interested in this article. This is about enabling an advanced feature for which interest has been reported by a few users. In general, raw mode does not give you superior image quality because it disables most of the image processing done in the camera (that's why it's called "raw"), so you lose all the benefits of the many days that Logitech engineers spent on tuning the hardware. You have been warned. :-)

Background

Switching the camera to Bayer mode is accomplished by disabling the color processing pipe within the camera. This also disables the format conversion, resulting in raw output.

The video processing extension unit contains the controls required to set the camera into raw mode. It is defined in the Linux UVC driver as:

#define UVC_GUID_LOGITECH_VIDEO   {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, \
0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x50}

On the Windows platform it can be defined as follows:

DEFINE_GUIDSTRUCT("63610682-5070-49AB-B8CC-B3855E8D2250", PROPSETID_LOGITECH_VIDEO_XU);
#define PROPSETID_LOGITECH_VIDEO_XU DEFINE_GUIDNAMED(PROPSETID_LOGITECH_VIDEO_XU)

The two controls are:

#define LXU_COLOR_PROCESSING_DISABLE_CONTROL   0x05
Function: Enable or disable the color processing pipeline within the camera.
Size: 8 bit
Values: 0 = color processing enabled (default)
1 = color processing disabled
#define LXU_RAW_DATA_BIT_PER_PIXEL_CONTROL     0x08
Function: Specify the number of bits per pixel for raw data. This value is only relevant if LXU_COLOR_PROCESSING_DISABLE_CONTROL is set to 0.
Size: 8 bit
Values: 0 = 8 bits per pixel (default)
1 = 10 bits per pixel

Step by step

Linux

The easiest way to extract Bayer format images is with the help of the bayer tool and a corresponding patch for the Linux UVC driver (see the Sample code and tools section below).

  1. Patch, compile, and load the Linux UVC driver.
  2. Use the bayer tool to enable raw Bayer mode:
    bayer /dev/video0 1
  3. Use luvcview with the -c or -C option to store the raw frames into files:
    luvcview -f yuv -s 1280x960
  4. You can use the provided bayer2rgb.m function in MATLAB to convert the received data to RGB format.

Windows

The attached Bayer-x.y.zip file contains Bayer.exe, a tool to enable and disable raw Bayer mode as well as the source code.

Specifying the /? switch on the command line will output a simple syntax help:

C:\>bayer /?
Usage: bayer [enable [bpp]]
enable: 1 to enable Bayer mode, 0 to disable it
bpp: bits per pixel (currently only 8 and 10 are supported, default is 8)

Calling the program without any options displays the current state:

C:\>bayer
Enumerating video input devices ...
Found device: QuickCam Orbit/Sphere AF [\\?\usb#vid_046d&pid_0994...]
Current status: Bayer mode disabled.

To enable raw mode set the first argument to 1. The second argument is optional and can be either 8 or 10, indicating the number of bits per pixel.

C:\>bayer 1
Enumerating video input devices ...
Found device: QuickCam Orbit/Sphere AF [\\?\usb#vid_046d&pid_0994...]
Bayer mode successfully enabled (8 bits).

C:\>bayer
Enumerating video input devices ...
Found device: QuickCam Orbit/Sphere AF [\\?\usb#vid_046d&pid_0994...]
Current status: Bayer mode enabled (8 bits).

To disable raw mode, set the first argument to 0.

C:\>bayer 0
Enumerating video input devices ...
Found device: QuickCam Orbit/Sphere AF [\\?\usb#vid_046d&pid_0994...]
Bayer mode successfully disabled.

C:\>bayer
Enumerating video input devices ...
Found device: QuickCam Orbit/Sphere AF [\\?\usb#vid_046d&pid_0994...]
Current status: Bayer mode disabled.

You can use a tool like AMCap to see the raw Bayer video stream. You need to write your own software to decode the data properly, but a sample algorithm in MATLAB format is provided below. Please also read the notes in the next section.

Notes

  • Changing these settings does not have any effect while the camera is streaming video. The video stream must be restarted for the settings to take effect.
  • Raw mode only works in certain resolutions. For 1.3 MP cameras, those will usually be the camera's "native" resolutions, i.e. 960x720 or 1280x960. For 2 MP cameras more resolutions may be supported. If color processing is disabled (i.e. "Bayer mode" is enabled) and streaming is started in a not supported resolution, the camera sends no data and the application may appear to hang. If this happens, just choose another resolution.
  • If Bayer images are captured in any resolution lower than the maximum resolution supported by the sensor, clipping occurs. For example, if the sensor supports 1280x960 and a 960x720 image is recorded, the frame will appear clipped at the right and lower borders.
  • The Logitech UVC driver for Windows packs the Bayer data into RGB24 as follows:

    8-bit raw Bayer data:

    Each 8-bit raw pixel is copied into the R, G, and B bytes of the 24-bit RGB pixel.

    10-bit raw Bayer data:

    The 8 least significant bits of the 10-bit raw pixel are copied into the B byte of the 24-bit RGB pixel, the 2 most significant bits are copied into the least significant bits of the G byte.

Sample images

The following sample images were taken in Linux with a Logitech QuickCam Orbit MP (PID: 0x08CC). The resolution is 960x720 pixels. Note how the Bayer images are cropped.

Description
Download link
Size calculation
Raw YUY2 Colorchart-yuy2.raw 1,382,400 bytes: 960*720 px * 2 Bpp
Raw YUY2 converted to RGB Colorchart-yuy2-rgb.bmp 2,073,654 bytes: 2,073,600 B data (960*720 px * 3 Bpp) + 54 B header
Raw MJPEG Colorchart-mjpeg.raw 78,504 bytes
Raw 8-bit Bayer Colorchart-bayer8.raw 691,200 bytes: 960*720 px * 1 Bpp
Raw 8-bit Bayer converted to RGB Colorchart-bayer8-rgb.bmp 2,073,654 bytes
Raw 10-bit Bayer Colorchart-bayer10.raw 864,000 bytes: 960*720 px * 10 bpp

Note that the YUY2 and MJPEG pictures are for comparison only. They were taken under the same lighting conditions but don't represent the exact same picture data as the Bayer samples.

Sample code and tools

  • uvcvideo-bayer-v2.patch (Adds the above custom V4L2 controls to the UVC driver.)
  • bayer.c (Sample tool for Linux to enable and disable bayer mode.)
  • bayer2rgb.m (MATLAB function to convert from raw Bayer format to RGB. Note that this algorithm does only a simple linear interpolation and may not handle the image borders in an optimal way. Also, it does not process 10 bpp Bayer data.)
  • Bayer-1.0.zip (Sample tool with source code for Windows to enable and disable Bayer mode.)

History

2008-04-11: Added a sample tool and sample source code to enable/disable raw Bayer mode on Windows.

2007-11-12: Updated to use the UVC_GUID_LOGITECH_VIDEO extension unit instead of UVC_GUID_LOGITECH_XU1. On newer devices (2007 models) only the former one is supported.

Links


Attached files
by Martin Rubli last modified 2008-09-16 16:57
Powered by Plone CMS.