Create AR Face Filters With the Chrome Face Detection API

Rate this content
Bookmark

In the fast pacing space of social media apps, some functionality could also be used for web applications. I am going to show you how you could use the feature flagged Face Detection API in Chrome. With a demo, we will explore the possibilities to implement face filters in your future projects. With the webcam access of a device, we add glasses by processing a video feed and using it for fun, finding that sweet spot where fun and learning come together.

This talk has been presented at JSNation 2023, check out the latest edition of this JavaScript Conference.

FAQ

To enable the Chrome Face Detection API, you need to activate a feature flag in the Chrome browser. This involves accessing a specific URL in Chrome and enabling the experimental feature through the browser's settings.

The Chrome Face Detection API is part of the larger Shape Detection API that includes text detection and barcode detection. It focuses on detecting faces in media but does not recognize specific individuals. It identifies presence and location of a face without distinguishing personal identity.

The face detector can handle properties such as 'maxDetectedFaces' to set the maximum number of faces to detect, and 'fastMode', which when set to true, speeds up the detection process but provides less detailed data.

Yes, the Chrome Face Detection API can handle both still images and video streams. However, detecting multiple faces in a video stream can be challenging as it may randomly select faces in each frame depending on the movement and number of faces.

Practical uses of the Chrome Face Detection API include enhancing augmented reality (AR) applications, improving photo alignment by automatically centering faces in profile pictures, and security applications like monitoring areas for the presence of people.

The API can detect rotated faces to a certain threshold. If the rotation exceeds this threshold, the detection might fail. However, developers can programmatically adjust the source image or video to compensate for the rotation and improve detection accuracy.

Limitations include difficulty in handling multiple faces simultaneously, especially in video streams, and challenges associated with face detection in varying light conditions, angles, and rotations beyond certain thresholds.

Developers can customize the output by applying different filters or effects to detected faces, such as adding virtual glasses. They can also manipulate the landmarks detected (like eyes and nose) to introduce creative visual enhancements in applications.

Jorrik Klijnsma
Jorrik Klijnsma
30 min
01 Jun, 2023

Comments

Sign in or register to post your comment.
Video Summary and Transcription
The Chrome Face Detection API is part of the bigger shape detection API and includes text detection and barcode detection. Enabling the API is as simple as opening a specific URL and enabling the experimental feature. The API provides features like detecting faces and processing landmarks, rendering glasses on faces, and applying face filters. It can handle multiple faces and images in videos, but performance depends on hardware and device processing speed. The API is currently in progress and feedback is being requested for potential production capabilities.

1. Introduction to Chrome Face Detection API

Short description:

Welcome. My name is Jorrik Leijnsma. I'm a creative front-end developer and I'm going to share something about the Chrome face detection API. Developers come with some kind of image. Sometimes we are a bit nerdy, but we are also problem solvers. Code can be fun and what you create with code is often seen as fun. AI is introduced into the scene, and there are more demanding users expecting more features. The Chrome Face Detection API is part of the bigger shape detection API.

Welcome. My name is Jorrik Leijnsma. As Caroline said, I'm a creative front-end developer and I'm going to share something about the Chrome face detection API. It's a mouthful, but managed to say it okay.

So, I'm a front-end developer and I work for over six years as a front-end developer now. Last two years at a company called Ordina. And, what we have, we are developers. I think most of us are here. And developers come with some kind of image. Sometimes we are a bit, like, nerdy, and... But we are also problem solvers.

But there's also this shift changing where code can be fun, and also what you create with code is more and more often seen as fun. But the code part is still boring. And that's where sometimes there is this interesting thing where you also want to create no boring code. But also not the great end result. So maybe people can show hands if you have seen boring code somewhere in your life. Yeah. I think most of us have. Or have you seen code that's not boring and was more interesting? Maybe also raise hands. So maybe a few less, but still there. And the last question, maybe people have seen code that was not functional at all, but was purely for fun purposes. So also some hands over there.

With the recent years, these all kinds of developments, AI is introduced into the scene. There are more demanding users. They are expecting more and more features. And you have the problem of maybe not being noticed if you don't have these amazing features in your app or service or whatever. So you need to be divergent and show what you can do and what's possible. This Chrome Face Detection API, it's something that's behind the feature flag, meaning it's not usable right out of the box. There is a process for this shape detection API. The Chrome Face Detection API is part of that bigger shape detection API.

2. Enabling the Chrome Face Detection API

Short description:

The Chrome Face Detection API includes text detection and barcode detection. It's important to note that face detection does not mean face recognition. Enabling the Chrome feature flag is as simple as opening a specific URL and enabling the experimental feature. You can then use the face detector by calling a new face detector and setting the max detected faces and fast mode properties.

It includes text detection and also barcode detection. And the barcode detection is already done, it's ready to use for everyone. But that face detection and text detection are still being developed. For this, it's an important note that the face detection does not mean face recognition. So it detects your face, but is not able to recognize a face from this is this person or that's that user logging in. So it's only showing there is this face on this type of media.

So how do you enable the Chrome feature flag? So there's this link, when you open this, let me try if it works. No, that needs to open. Let me copy paste it in then. It's not not not a valid normal link, choose application and then show options. You're not seeing this. I have to select Chrome for it to open. Google Chrome browser. So over here, let me slide it over. So now it should be visible. This is the part if you open that URL. You're seeing this experimental feature thing. And you just need to enable it. It comes with some other features as well. So keep that in mind. I recently got some trouble with selecting, for example, text on GitHub, which is not showing properly, so that also seems to be part of this something buggy going on in this web platform stuff. So that's how you enable this feature. Like this. That was way easier. So now you have enabled in your browser and now you can use it.

To use it, you start to call a new face detector. It's as simple as that. It can handle two properties. It can handle the max detected faces, which can set to I think any number, but at a certain point, your machine is not going to be fast enough to detect all those faces. And there's this fast mode which can be true or false.

QnA

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Install Nothing: App UIs With Native Browser APIs
JSNation 2024JSNation 2024
31 min
Install Nothing: App UIs With Native Browser APIs
This Talk introduces real demos using HTML, CSS, and JavaScript to showcase new or underutilized browser APIs, with ship scores provided for each API. The dialogue element allows for the creation of modals with minimal JavaScript and is supported by 96% of browsers. The web animations API is a simple and well-supported solution for creating animations, while the view transitions API offers easy animation workarounds without CSS. The scroll snap API allows for swipers without JavaScript, providing a smooth scrolling experience.
Pushing the Limits of Video Encoding in Browsers With WebCodecs
JSNation 2023JSNation 2023
25 min
Pushing the Limits of Video Encoding in Browsers With WebCodecs
Top Content
Watch video: Pushing the Limits of Video Encoding in Browsers With WebCodecs
This Talk explores the challenges and solutions in video encoding with web codecs. It discusses drawing and recording video on the web, capturing and encoding video frames, and introduces the WebCodecs API. The Talk also covers configuring the video encoder, understanding codecs and containers, and the video encoding process with muxing using ffmpeg. The speaker shares their experience in building a video editing tool on the browser and showcases Slantit, a tool for making product videos.
WebHID API: Control Everything via USB
JSNation 2022JSNation 2022
23 min
WebHID API: Control Everything via USB
Today's Talk introduces the webHID API, which allows developers to control real devices from the browser via USB. The HID interface, including keyboards, mice, and gamepads, is explored. The Talk covers device enumeration, input reports, feature reports, and output reports. The use of HID in the browser, especially in Chrome, is highlighted. Various demos showcase working with different devices, including a DualShock controller, microphone, gamepad, and Stream Deck drum pad. The Talk concludes with recommendations and resources for further exploration.
Visualising Front-End Performance Bottlenecks
React Summit 2020React Summit 2020
34 min
Visualising Front-End Performance Bottlenecks
React's web-based tools allow for independent learning. Dazzone, a sports streaming service, faces challenges with low memory and CPU targets. Measuring, analyzing, and fixing performance issues is crucial. Virtualization improves rendering efficiency and performance. The application is now much faster with significantly less jank.
Automate the Browser With Workers Browser Rendering API
JSNation 2024JSNation 2024
20 min
Automate the Browser With Workers Browser Rendering API
The Talk discusses browser automation using the Worker's Browser Rendering API, which allows tasks like navigating websites, taking screenshots, and creating PDFs. Cloudflare integrated Puppeteer with their workers to automate browser tasks, and their browser rendering API combines remote browser isolation with Puppeteer. Use cases for the API include taking screenshots, generating PDFs, automating web applications, and gathering performance metrics. The Talk also covers extending sessions and performance metrics using Durable Objects. Thank you for attending!
MIDI in the Browser... Let's Rock the Web!
JSNation 2022JSNation 2022
28 min
MIDI in the Browser... Let's Rock the Web!
MIDI is a versatile communication protocol that extends beyond music and opens up exciting possibilities. The Web MIDI API allows remote access to synths and sound modules from web browsers, enabling various projects like music education systems and web audio-based instruments. Developers can connect and use MIDI devices easily, and the Web MIDI API provides raw MIDI messages without semantics. The WebMidi.js library simplifies working with the Web MIDI API and offers a user-friendly interface for musicians and web developers. MIDI on the web has generated significant interest, with potential for commercial growth and endless possibilities for web developers.

Workshops on related topic

Writing Universal Modules for Deno, Node and the Browser
Node Congress 2022Node Congress 2022
57 min
Writing Universal Modules for Deno, Node and the Browser
Workshop
Luca Casonato
Luca Casonato
This workshop will walk you through writing a module in TypeScript that can be consumed users of Deno, Node and the browsers. I will explain how to set up formatting, linting and testing in Deno, and then how to publish your module to deno.land/x and npm. We’ll start out with a quick introduction to what Deno is.