Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add face detection mode constraint #292

Closed
wants to merge 1 commit into from

Conversation

eehakkin
Copy link
Contributor

@eehakkin eehakkin commented Oct 15, 2021

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:

<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>

Preview | Diff

@eehakkin
Copy link
Contributor Author

Closing in favor of w3c/mediacapture-extensions#48.

@eehakkin eehakkin closed this Jan 11, 2022
@eehakkin eehakkin deleted the feature/face-detection-mode branch June 28, 2023 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant