OpenCV troubles

Troubles with Linux, UVC driver and jpeglib decompression

I have recently obtained a Logitech Quickcam Pro 5000 webcam. The good news is that there is a driver (UVC) available for Linux - I am running 2.6.21 kernel on Debian Testing, with OpenCV 1.0.0.3 and UVC 0.1.0. The bad news is, that under the heavy computer load it seems to send corrupt JPEG frames time to time. And here the V4L (Video4Linux) part of OpenCV kicks in.

Update: The issue seems to be be related to USB 1.1. The problem disappears with USB 2.0.

Although the OpenCV frame retrieval does have a proper propagation of error values set up, the V4L subpart does not use it. Does it assume that the JPEG frame is always correct? It can be corrupt. The only way, how to know about an error, is a message printed to stderr by jpeglib:

Corrupt JPEG data: premature end of data segment
or
Corrupt JPEG data: 115 extraneous bytes before marker 0xd9
or
Corrupt JPEG data: bad Huffman code
or something similar.

Possible solution

All that needs to be done is to check for an error during jpeg operations and propagate this information back through the function call chain. The grfmt_jpeg.cpp patch does the error checking and first level of error propagation, the cvcap_v4l.cpp patch continues the propagation. These are just few lines of changes - they are easy to understand (and not so easy to write, at least for me ;-) ).

A glimpse at the code suggests, there may be similar issues with other functions, not only mjpeg decompression.

Better solution

The current OpenCV code uses the standard error routine of jpeglib. It is the one, that prints an error message to stderr. However, it can, according to library descriptions, exit the whole application, when a "non-recoverable" error is encountered. It may be worth consideration to use a less aggressive variant of this error handler.

And why do I not post this information to the OpenCV developers? I am not interested in Yahoo Groups registration. No at all.

Troubles with FreeBSD

Even though there is no UVC-like FreeBSD driver at the moment (August 11th 2007), I would still like to use my FreeBSD-only laptop for the development. But ...

The FreeBSD maintainer of the OpenCV package "solves" the jpeglib problem by a wrong package - it does not have CFLAGS, CPPFLAGS and LDFLAGS set (to contain /usr/local/include and /usr/local/lib respectively), hence OpenCV's ./configure script does not find jpeglib (and ffmpeg) and does not compile it in. The result is a seriously crippled version of OpenCV installation.

Windows surprise

No serious error hit by me, sorry. But ... :-)
Did you know, that OpenCV tends to store some information to the Windows registry? I like those ...