Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing USB camera controls with AForge

I have a project where i need to work with a USB camera to process images aquired at a very close range (under 5mm). Because the space available is very short, I can't use auxiliary lens.

I know I can do some post processing at bitmap level, but I would like to gain access to properties like auto-focus or white balancing at camera level.

I'm developing in C# with AForge for image aquisition and post processing, but I can't seem to find a way to control the camera before the image aquisition takes place.

Can you help me?

like image 838
Shadlan Avatar asked Feb 15 '12 10:02

Shadlan


2 Answers

After some more thorough research I've found the answer by myself.

If anyone else is searching for this you can try the following;

VideoCaptureDevice Cam1;
FilterInfoCollection VideoCaptureDevices;

VideoCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
Cam1 = new VideoCaptureDevice(VideoCaptureDevices[0].MonikerString);
Cam1.DisplayPropertyPage(IntPtr.Zero); //This will display a form with camera controls

It also seems possible to control these items without the form by using IAMVideoProcAmp

like image 118
Shadlan Avatar answered Nov 14 '22 02:11

Shadlan


To access other camera properties like brightness, contrast see IAMVideoProcAmp implementation

videoDevice.SetVideoProperty(
    VideoProcAmpProperty.Brightness,
    brightnessValue,
    VideoProcAmpFlags.Manual);

videoDevice.SetVideoProperty(
    VideoProcAmpProperty.Contrast,
    contrastValue,
    VideoProcAmpFlags.Manual);

videoDevice.SetVideoProperty(
    VideoProcAmpProperty.Saturation,
    saturationValue,
    VideoProcAmpFlags.Manual);

videoDevice.SetVideoProperty(
    VideoProcAmpProperty.Sharpness,
    sharpnessValue,
    VideoProcAmpFlags.Manual);

videoDevice.SetVideoProperty(
    VideoProcAmpProperty.WhiteBalance,
    whiteBalanceValue,
    VideoProcAmpFlags.Manual);

videoDevice.SetVideoProperty(
    VideoProcAmpProperty.BacklightCompensation,
    backlightCompensationValue,
    VideoProcAmpFlags.Manual);
like image 42
Hassan Rahman Avatar answered Nov 14 '22 02:11

Hassan Rahman