9

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?

Shadlan
  • 254
  • 1
  • 2
  • 9

3 Answers3

11

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

Gray
  • 6,606
  • 2
  • 26
  • 49
Shadlan
  • 254
  • 1
  • 2
  • 9
  • @Darshana The edit you made was too minor. That should not have been approved, so I rolled it back. Please put more effort into your edits. [Read this](http://stackoverflow.com/help/editing) if you are not sure how to properly edit posts. – Gray Nov 14 '13 at 13:34
7

You can access camera setting directly without call the method DisplayPropertyPage()

FilterInfoCollection videoDevices = 
    new FilterInfoCollection(FilterCategory.VideoInputDevice);

VideoCaptureDevice videoDevice = 
    new VideoCaptureDevice(videoDevices[camDevice].MonikerString);

videoDevice.SetCameraProperty(
    CameraControlProperty.Zoom,
    zoomValue,
    CameraControlFlags.Manual);

videoDevice.SetCameraProperty(
    CameraControlProperty.Focus,
    focusValue,
    CameraControlFlags.Manual);

videoDevice.SetCameraProperty(
    CameraControlProperty.Exposure,
    exposureValue,
    CameraControlFlags.Manual);
Hassan Rahman
  • 3,808
  • 1
  • 29
  • 25
1

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);
Hassan Rahman
  • 3,808
  • 1
  • 29
  • 25
  • 1
    Thank you for the reply. You have added valuable information to my initial idea: that it was possible to set these using the IAMVideoProcAmp. It's a couple of years since my first post, but the information may still be relevant to some users. – Shadlan Oct 06 '14 at 16:13
  • The code.google.com reference no longer exists. Luckily this github project cloned Aforge and brought the changes in: https://github.com/lanpa/AForge.NET – Max Aug 21 '20 at 14:43