Controlling camera settings in code


this is my first ever post & it’s all about controlling webcam functions manually in code…

I have a Logitech c910 webcam running on Windows.

I can control the settings of the camera using the vidGrabber.videoSettings() function, but I want to be able to do all of this (especially focussing) in the code I am writing. Is there any way do achieve this?




I have delved into videoInput.h file & found a bunch of camera properties that look promising…

bool setVideoSettingCamera(int deviceID, long Property, long lValue, long Flags = NULL, bool useDefaultValue = false);  
		bool setVideoSettingCameraPct(int deviceID, long Property, float pctValue, long Flags = NULL);  
		bool getVideoSettingCamera(int deviceID, long Property, long &min, long &max, long &SteppingDelta, long &currentValue, long &flags, long &defaultValue);  
		//bool setVideoSettingCam(int deviceID, long Property, long lValue, long Flags = NULL, bool useDefaultValue = false);  
		//get width, height and number of pixels  
		int  getWidth(int deviceID);  
		int  getHeight(int deviceID);  
		int  getSize(int deviceID);  
		//completely stops and frees a device  
		void stopDevice(int deviceID);  
		//as above but then sets it up with same settings  
		bool restartDevice(int deviceID);  
		//number of devices available  
		int  devicesFound;  
		long propBrightness;  
		long propContrast;  
		long propHue;  
		long propSaturation;  
		long propSharpness;  
		long propGamma;  
		long propColorEnable;  
		long propWhiteBalance;  
		long propBacklightCompensation;  
		long propGain;  
		long propPan;  
		long propTilt;  
		long propRoll;  
		long propZoom;  
		long propExposure;  
		long propIris;  
		long propFocus;  

Does anyone know how I implement these? I feel a bit out of my league!

I’m not on a DirectShow compatible system, but wouldn’t it just be:

setVideoSettingCamera(devId, propBrightness, brightnessVal);  

It looks like right now you can’t get the deviceID directly, so you could just hardcode it (you can find it using listDevices()) or you could hack the ofDirectShowGrabber to give you access to the deviceId.

This is a bit of an outdated topic, however I have the exact same question: is it possible to contol (web)cam settings from inside OF? Now I run guvcviewer prior to running my app, which does simple background substraction. It would really add to the functionality if I can enable/disable things like autogain, and control gain and contrast by myself.

Are these parameters that differ from platform to platform? Or would it be possible to write a wrapper that works both on Linux and Windows?
I run Ubuntu 11.04 64bits, and use a ps3 eye cam (actually two of them, which is currently somehow disastrous, even inside guvcview, but one works fine).

Just took a quick look into the ofVideoGrabber class: there is a function “void videoSettings()”.

However for the Gstreamer implementation, the code is thus:

void videoSettings(){};//TODO: what is this??  

For the DirectShow implementation all this does is:

if (bGrabberInited == true) VI.showSettingsWindow(device);  

I guess inside Ubuntu the ofVideoGrabber class gets instantiated as a Gstreamer object? I am really not so familiar with the differences between all this, and what gets instantiated when and why.
If it is possible to write a working implementation of the settings function for the Gstreamer version, I am happy to do so, though I would some pointers how to do it.

hi mennowo

Did managed to control the settings inside OF?

Hi bcr0520,

for the ofVideoGrabber class I believe I never managed this, at least not up until oF0.8. Maybe a newer incarnation of oF has implemented this? Or is the VideoSettings method still just a place holder?

If you are on Linux, you may consider directly using the V4L2 (Video for Linux 2) driver: Please note this implementation of/wrapper around the driver is imperfect and incomplete, only supporting black and white. I wrote it to speed up capturing from PS3 eye cameras overUSB2.0. It allows in a rudimentary way to set things like qhite balance, etc.

Another option, on Linux, I have found, is using Guvcview to set the settings of a cam, then using it from oF, those settings (mostly) remain in place.

Otherwise, maybe you can implement the empty method in the ofVideoGrabber class? If at all it is possible to do that in a generic, multi-OS, multi-platform way…