[mediacapture-image] Pull Request: Add face detection mode constraint

eehakkin has just submitted a new pull request for https://github.com/w3c/mediacapture-image:

== Add face detection mode constraint ==
This spec update allows face detection as descibed in #289.

The changes include a _new face detection mode_ constrainable property and a new _detectedFaces_ sequence which is accessible via a new asynchronous `getAttributes()` accessor.

This allows following kind of code to be used for face detection:
```js
<script>
// Check if face detection is supported by the browser.
const supports = navigator.mediaDevices.getSupportedConstraints();
if (supports.faceDetectionMode) {
    // Browser supports camera face detection.
} else {
    throw('Face detection is not supported');
}

// Open camera with face detection enabled and show to user.
const stream = await navigator.mediaDevices.getUserMedia({
    video: {faceDetectionMode: "simple"}
});
const video = document.querySelector("video");
video.srcObject = stream;

// Get face detection results for the latest frame
const videoTracks = stream.getVideoTracks();
const videoTrack = videoTracks[0];
const settings = videoTrack.getSettings();
if (settings.faceDetectionMode && settings.faceDetectionMode != "off") {
    const attributes = await videoTrack.getAttributes();
    for (const face of attributes.detectedFaces) {
        console.log(
         ` Face @ (${face.boundingBox.x}, ${face.boundingBox.y}),` +
         ` size ${face.boundingBox.width}x${face.boundingBox.height}`);
    }
}
</script>
```

See https://github.com/w3c/mediacapture-image/pull/292


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Friday, 15 October 2021 18:16:24 UTC