1

I'm working on a UWP app that needs to scan QR codes from a laptop webcam. I'm using the Windows.Media.Capture.MediaCapture class for this. Everything works well, except for when using qr code on a smartphone with it's brightness set too high for the limited dynamic range of built-in webcams. The auto-exposure of the webcam is active, but the screen can still be too bright compared to the environment.

I'm looking for a way to control or override the brightness or exposure either manually or by using some kind of exposure compensation mode.

The only properties to do with brightness/exposure that are enabled/working on my regular built-in webcam are Brightness and Contrast, and those change the image accordingly, but look like they are post-processing effects. They don't change the exposure of the camera itself, thus not fixing the issue.

mediaCapture.VideoDeviceController.ExposureCompensationControl.Supported;
mediaCapture.VideoDeviceController.ExposureControl.Supported;
mediaCapture.VideoDeviceController.ExposurePriorityVideoControl.Supported;
mediaCapture.VideoDeviceController.Exposure.Capabilities.Supported;

all return false

mediaCapture.VideoDeviceController.Brightness.TrySetValue(10);

changes the image, but highlights are still washed out and have no detail for the scanner to pickup

  • Have you checked if the smartphone camera supports scanning QR code? – Bite Jul 19 '19 at 11:54
  • @Bite, sorry, but this does not answer my question or help in any way really... I need the scanning to happen on the laptop itself. – Matthias Duyck Jul 20 '19 at 10:30
  • You said it wroks on laptop, except on a smartphone. – Bite Jul 22 '19 at 09:16
  • @Bite I believe you have not fully understood my setup: I am trying to scan a QR code from a laptop webcam, never from a smartphone. The app is only designed for laptops/desktops and will never run on smartphones. The QR code itself, an image essentially, can be printed onto paper, but will more likely be displayed on a smartphone display, held up to the webcam of a laptop. If that display is set too bright, the webcam does not change the exposure enough and cannot scan it. This is the issue I am trying to solve. – Matthias Duyck Jul 23 '19 at 11:48
  • Try [ZXing.NET](https://github.com/Redth/ZXing.Net.Mobile/tree/master/Samples/WindowsUniversal/Sample.WindowsUniversal). – Bite Jul 24 '19 at 15:26
  • I am using ZXing.NET... The problem is not the decoding of the QR code itself, it is that the image coming in is overexposed where the QR code is... – Matthias Duyck Jul 25 '19 at 16:03
  • @MatthiasDuyck I have created a project using the MediaCapture API with the ZXing library, but I can not reproduce your issue, if I use this method: mediaCapture.VideoDeviceController.Brightness.TrySetValue() to change the Brightness, I can see that brightness that is used for scanning the QR image is also changing as well. So I am not sure if I have misunderstood you, could you please share your reproduced code and reproduced steps in here? – Amy Peng - MSFT Aug 08 '19 at 09:19
  • Hey @AmyPeng-MSFT I have tried setting the Brightness in this way, and it does definitely change the image to be 'brighter' or 'darker'. The problem with this, is that the processing seems to occur after the capture and exposure of the camera is already done. It just shifts the already captured data. Extreme highlights(like a smartphone screen) are not recoverable. Exposure is still decided automatically. What is needed is a way to control the camera's inherent exposure properties like ISO shutter speed and f-stop. Alternatively a relative control like exposure compensation could also work. – Matthias Duyck Aug 08 '19 at 09:57
  • @MatthiasDuyck Have you tried the ExposureControl(https://learn.microsoft.com/en-us/uwp/api/Windows.Media.Devices.ExposureControl) which allows you to set the shutter speed used during photo or video capture? For the detailed information, please check this article: https://learn.microsoft.com/en-us/windows/uwp/audio-video-camera/capture-device-controls-for-photo-and-video-capture. – Amy Peng - MSFT Aug 15 '19 at 06:53
  • Hey @AmyPeng-MSFT I have tried all of those, but it seems these are disabled/not available on the small cheap built-in webcams on normal laptops. I'm assuming those are only available on the more fancy non-fixed focus and higher than 2MP style camera's in tablets and convertibles. – Matthias Duyck Aug 16 '19 at 07:53

2 Answers2

2

With respect to programmatically controlling the camera exposure via a windows driver, you are considering the correct interface. Using the MS Surface Pro 4, I have successfully modified the exposure using this interface:

mediaCapture.VideoDeviceController.ExposureControl

As well, MS has provided some nice examples and documentation for how to get this to work. Keep in mind, the examples (and the MS camera app) will hide the controls if the exposure feature is not supported by your HW.

https://learn.microsoft.com/en-us/windows/uwp/audio-video-camera/capture-device-controls-for-photo-and-video-capture

https://github.com/microsoft/Windows-universal-samples/tree/master/Samples/CameraManualControls

The lack of access to imaging controls (such as exposure) really has nothing to do with quality. It has more to do with completeness of the camera solution. Camera sensors have a control interface (for example i2c) which is separate from the data interface which drives image. Most third party camera modules will not implement the HW/SW required to enable these controls.

TedG
  • 21
  • 3
1

The Supported property of the VideoDeviceController's control objects (ExposureCompensationControl.Supported, for example) doesn't always give accurate information unless the camera is active. So, be sure to get the preview or frame capture started before asking whether the camera controls are supported.

From VideoDeviceController

Some drivers may require that the camera device preview to be in a running state before it can determine which controls are supported by the VideoDeviceController. If you check whether a certain control is supported by the VideoDeviceController before the preview stream is running, the control may be described as unsupported even though it is supported by the video device.

Joel Lyons
  • 11
  • 4