UVC Camera control in Mac OS X

Hi all,

i’ve been using UVC webcams since long time in OS X and as they require no drivers its was extremely annoying that there was no interface to manually control camera properties such as exposure and white balance.

I am sure many of you had same issues, so I thought I’d post this here:
http://www.phoboslab.org/log/2009/07/uv-…-r-mac-os-x

Its an ObjC class to control camera properties including a demo app with source!

Cheers,

Borut

Hi

I am trying to use your obj-c class in openframeworks.

it complies fine.
like some other people i get the following error when trying to change the exposure for example.

other thread with same problem: http://forum.openframeworks.cc/t/objc-classes-within-of-app/2319/11

since you spend much more time with this, maybe you have some good ideas on how to solve this.

thanks a bunch,
stephan.

as so often asking a question stimulates the brain and makes me look at the problem from a new perspective.

it turns out that the normal ofvideoGrabber and the uvc camera control block each other.

so i found this QTKit based video grabber here:
http://forum.openframeworks.cc/t/ofxqtkitvideograbber-qtkit-amp;-corevideo-±of/3555/0

all i had to do was to download the addon, place it in the addon folder, include the following in my header file
#include “ofxQTKitVideoGrabber.h”
ofxQTKitVideoGrabber vidGrabber;

and all is good now.

thanks for this great objc class.

regards,
stephan.

update:

here is my working version
lozano-hemmer.com/ss/uvc+qtkit.zip

Hey there

I’m trying to help a friend with controlling his IPEVO Point2View camera.
http://www.ipevo.com/prods/Point-2-View-USB-Camera/IPEVO
It’s a document cam with auto-focus/one-shot focus + macro lens.
It’s own software can trigger the one-shot autofocus, but not manually control the focus.

The camera supports capture via UVC, but so far having trouble getting any control.
kumpri’s standalone example runs, but the camera doesn’t respond to any of the controls ( exposure, auto-white balance, …)
Since this example appears to reference the IOKit USB device without the vendor/product ID, I didn’t make an changes to the code relative to the hardware.

With Stephan’s example, I also get an image but no camera control.
In this case we change the product and vendor ID to match the camera.
If the vendor/product ID is incorrect, then our program fails at:

  
  
            NSLog( @"CameraControl Error: IOCreatePlugInInterfaceForService returned 0x%08x.",   
  

inside

  
  
- (id)initWithVendorID:(long)vendorID productID:(long)productID {  
  

And since with the correct ID’s it gets to the end of that function, we can presume that IOKit USB device is being correctly referenced.

We get our first error at

  
  
	[cameraControl setAutoExposure:YES];  
  

in setup();

this fails at sendControlRequest
on line:

  
  
	kr = (*interface)->ControlRequest( interface, 0, &controlRequest );  
  

The error code given is kIOUSBPipeStalled
Which appears to be related to either a communications error, or a rejection of the command from the USB device (e.g. unsupported command, doesn’t at all accept commands)

There’s no UVC documentation available for this device.

So I’m left wondering, do pretty much all UVC devices support exposure control?
I.e. is it likely that the camera would support exposure control, and therefore i’m doing something wrong somewhere.
(alternatively, if UVC exposure control is rare, then perhaps this camera just doesn’t support any UVC control signals).

Also, is there an alternative clean way to reproduce the ‘one shot focus’ signal that’s given by the official software? I’ve tried probing it with USB Prober, but I get nothing noticeable up to detail level 6, and detail level 7 goes barmy (since all the frame data gets logged).

Thanks
Elliot

i’m sure i’m out of my depth here, but i have been fiddling with 2 UVC cameras on a Mac OS X for (many) hours (days, etc). there’s a comment in dominic’s code (re: phoboslab link at top of post) about the UVC exposure boolean. apparently it’s not as simple as YES and NO, and he had to tweak the code to reflect this.

might mean something for your case…

The error was a broken pipe on the IOKit calls.
this happens regardless of what call is being made

It seems that there’s something more fundamental
I moved it over to the quickcam team forums and end up giving up (going to windows for that project) after some null responses.
But would definitely love to see this implemented properly

Hey

If any of you use a Logitech C910 you will notice that it doesn’t work with this uvc class

To fix it just change

  
controlRequest.wIndex = (unitId << 8) | 0x00;  

to

  
controlRequest.wIndex = (unitId << 8) | 0x02;  

on lines: 247 and 261

Cheers

@az_rr : if this works, then that’s really fantastic
however, can you let us know why it works?
does this mean it should work for all cameras, or is that code specific to each product?

wIndex is supposed to hold the interface number of the video interface. That’s often interface 0x00 but on some devices, eg. logitech c910, the video-control interface has the index of 0x02.

It might work with other devices, I dont have anything else to test with. Id give it a try if your having problems.

Also,

I posted example code on how to control a UVC camera here

http://forum.openframeworks.cc/t/uvc-camera-control—mac-osx/9391/0

I’m having an even weirder result trying to work with a Microsoft LifeCam HD-3000:

With:

controlRequest.wIndex = (unitId << 8) | 0x02;

The camera didn’t work at all. When I switched it to:

controlRequest.wIndex = (unitId << 8) | 0x00;

The auto-exposure control, and only the auto-exposure, control started to work.

Has anyone figure out what’s going on here? The same issue seems to exist with the pre-built CameraControl.app I can only control the auto-exposure toggle. Auto-exposure on/off is pretty useless without the ability to set the exposure thereafter.

Ok. I’ve made a teeny bit of progress: I switched getDataFor to also shift the controlRequest.wIndex by 0x00 for the LifeCam. And now, when I turn auto-exposure off, the camera at least stays set to the same exposure setting that autoExposure found. This may be minimally viable for my current application, but it’s not that satisfying of a result. Does anybody have a guide to understanding the UVC spec that’s more concise than the spec itself?

Az, one other thing: I’m working from your example code. Any reason why it only works with ofxQTKitVideoRecorder and not ofVideoGrabber? I assume this has to do with the way that ofVideoGrabber interfaces with the camera/controls the USB connection. Is there anyway around this?

I made some progress on this. With the help of James George, I managed to wrap Dominic’s code into an addon that doesn’t force your main OF app to use .mm files or call cocoa code directly. The repo is here:

https://github.com/atduskgreg/ofxUVC

I also added a function to query all of the features that the camera supports in UVC (see the example).

The main problem right now is that the normal ofVideoGrabber interferes with the ability to do UVC communication. So you have to use this with ofxQTKitVideoGrabber instead. I wonder if this is a problem that could be fixed in the ofVideoGrabber API in some way?

I’d love to add Windows and Linux support to this (and test it with other cameras) if anyone wants to dive in…

fantastic!
windows support already exists in principle.
theo’s videoInput capture code (which wraps DirectShow and is employed by ofDirectShowGrabber) allows full control of both ‘filter’ parameters (brightness, colour balance, i.e. things that are performed by the OS/driver, and are available in osx) and ‘camera’ settings (exposure, gain, focus, i.e. things that are performed by the sensor, and require specific uvc control to access in osx)

so ofxUVC could wrap the videoInput component to give a common api for camera control on both platforms.

Thanks, Elliot! And thanks for pointing out videoInput. I’ll definitely give it a try. I’m going to have to do Windows compatibility on this project at some point so when I do I’ll incorporate it into this API exactly as you suggest.

Will you give it a test on your camera? I’m starting to think the issue with the wIndex values has to do with some kind of little- vs. big-endian issue rather than spec implementation differences. Does that sound plausible to you? I’m wondering about how I can deal with that in this addon.

This any use? http://www.dm9.se/?p=693

I’m posting this as I was unable to find any info on manual controls for the new Logitech C920.
After some usb sniffing on a windows machine I was able to figure out the differences, which of course turned out to be quite minor.

I posted the info on the ofxUVC issues page: https://github.com/atduskgreg/ofxUVC/issues/2

but the crux of it is:

in UVCCameraControl.h
#define UVC_PROCESSING_UNIT_ID 0x03

in setData and getDataFor in UVCCameraControl.m ( two instances )
controlRequest.wIndex = (unitId << 8) | 0x00;

This gives you control over white-balance, gain, sharpness etc.

when i use the ofxUVC with the osxVideoRecorderExample

i get this error in the console:
2013-02-26 10:54:13.217 osxVideoRecorderExampleDebug[72215:707] CameraControl Error: No interface to send request

i set in camera-settings.yml to cameraToUse: the right camera. (logitech c910)

any ideas why?

thx.

would any one know how to add zoom control to the UVC class?

i found some info here: http://www.usb.org/developers/devclass-docs

“CT_ZOOM_ABSOLUTE_CONTROL
?
0x0B
CT_ZOOM_RELATIVE_CONTROL
?
0x0C”

but not sure how to combine that with the current addon

update:
this seems to work now:

  
  
    .absoluteZoom = {  
		.unit = UVC_INPUT_TERMINAL_ID,  
		.selector = 0x0B,  
		.size = 2,  
	},  
  

1 Like