Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getUserMedia lock focus/exposure

I am using navigator.getUserMedia with constraints to access the user's webcam, using the feed as the source of an HTML <video> and then copying its stream to drawImage a <canvas> context. I'm doing all this so I can take a snapshot at intervals.

What I would like to do is, once the page starts taking snapshots, lock the getUserMedia camera's focus/exposure, so that in between snapshot intervals the environment can change without the light balance changing or the camera refocusing.

Does anyone know if this is possible on the JS side?

like image 513
Jody Heavener Avatar asked Mar 29 '15 01:03

Jody Heavener


1 Answers

Flagged as duplicate of: Take photo when the camera is automatically focused

Firsly - though perhaps bad practice here - I will link to why MediaCapture might be blurry or grainy than expected:

Why the difference in native camera resolution -vs- getUserMedia on iPad / iOS?

In short: MediaCapture does a lot of transformations on the media source which may cause blury or grainy images.

To solve this use ImageCapture:

The ImageCapture API enables control over camera features such as zoom, brightness, contrast, ISO and white balance. Best of all, Image Capture allows you to access the full resolution capabilities of any available device camera or webcam. Previous techniques for taking photos on the Web have used video snapshots, which are lower resolution than that available for still images.

To solve your problem:

You can solve this via UX and a zoom slider. Below is information on how to achieve this with ImageCapture (still images). MediaCapture (video feed) does not allow this functionality. You could use MediaCapture and have a button such as "Manual Mode" and allow a user to pick the correct zoom to take the photo.

You could also "emulate" a camera by having an update loop doing n ImageCaptures per update and have a zoom slider.

https://developers.google.com/web/updates/2016/12/imagecapture

And here is an example on how to use it/polyfill: https://github.com/GoogleChromeLabs/imagecapture-polyfill

Makesure you use the latest getUserMedia polyfills which handle crossplatform support: https://www.npmjs.com/package/webrtc-adapter

Hope this helps

like image 118
Marcus Avatar answered Nov 11 '22 21:11

Marcus