Controlling iSight Autoexposure programmatically

One of the things that make computer vision with Apple’s builtin iSight quite cumbersome, are the extremely annoying auto-exposure and auto-whitebalance features. Also, Apple does not seem to care one bit about providing any kind of documentation on how to deactivate these features (and/or control other features) of your iSight. Anyways, after a long time of googling/research I found an Objective-C class at phoboslab.org, which allows to control UVC compliant USB webcams.

With the help of this class and a few tweaks to its code I was finally able to deactivate auto-exposure and auto-whitebalance of my builtin iSight.

Here are my steps:

1.  Get the UVCCameraControl class and include it in your project.

2.  Instantiate this class after you started your QTCapture session with something like this:
“cameraControl = [[UVCCameraControl alloc] initWithVendorID:0×05ac productID:0×8507];”
(You might have to adjust the parameters, USB Prober is your friend)

3. In the file “UVCCameraControl.h” change the line “#define UVC_PROCESSING_UNIT_ID 0×02″ to
“#define UVC_PROCESSING_UNIT_ID 0×03″

4. In  the method  “- (BOOL)sendControlRequest:(IOUSBDevRequest)controlRequest” remove the calls to USBInterfaceOpen() and USBInterfaceClose().

That’s it! At least this is how it worked out for me on my MacBook Pro (latest Generation). If you still have some problems, just drop a comment.

Note: This does not seem to work, if you access your iSight via the old sequence grabber component. Be sure to use the newer Quicktime API.

5 Responses to “Controlling iSight Autoexposure programmatically”

  1. iMac 2.4Ghz Core Two Duo running 10.6.0 (also tested under 10.5.8) - I’m getting a bunch of Control request failed kIOUSBPipeStalled messages whenever I try to change autoexposure/exposure/autowhitebalance etc
    (I see that iPinchMe is reporting the same type of thing to the console)
    Oddly sending UVC_GET_INFO messages reports back that I can indeed set/get these properties…

    On a plus note: saturation, brightness and contrast are now working fine.

    Any thoughts?

    ps If I get the go ahead from work then I’ll release my version of the www.phoboslab.org code… it plugs the memory leaks and has pieces from USBProber to automatically determine the terminal and processing unit, getting the serial number, etc… so that it works automatically with most cameras - except iSight! :(

  2. Hmm, I am running OS X 10.5.8 on a MacBook Pro 2.53Ghz Core2 Duo and I do not get these messages.

    Since you get the same errors with iPinchMe, I do not know how to fix this for your situation. Do you know whether there is a difference (hardware wise) between the iSight in the iMacs and the MacBook Pros? Maybe you can send me the output of USB Prober, so I can compare with what I have here.

  3. I can now adjust whiteBalance - it is vital to respect the UVC_GET_RES field, i.e. from the spec “If a Control supports GET_MIN, GET_MAX and GET_RES requests, the values of MAX, MIN and RES shall be constrained such that (MAX-MIN)/RES is an integral number. The device shall indicate protocol STALL … if an invalid CUR value is provided in a SET_CUR operation”

  4. Ok, this sounds interesting, but why does it still work on my MacBook Pro without respecting this?

    Any luck with autoExposure?

  5. I had the same problems with the kIOUSBPipeStalled messages (10.6.4 Unibody Macbook). I could turn autoExposure off (i.e., to manual mode) correctly, but I couldn’t turn it back on. I fixed this by changing the value corresponding to enabled in setAutoExposure from 0×08 to 0×02. I think this makes sense according to the spec as well.

    Still working on gain, but the rest of the controls in the demo application seem to work.

Discussion Area - Leave a Comment




   


   Twitter
   Impressum