Case study 05

Face Detection

Face and landmark detection that runs live in your browser, with nothing uploaded.

Loading model

YuNet / ONNX Runtime Web

Runs on your device. Images and video never leave the browser.

Overview

A real-time face detector that runs entirely on the visitor's device. It finds every face in a photo or webcam feed, scores it, and marks five facial landmarks: both eyes, the nose tip and the mouth corners.

It uses YuNet, OpenCV's lightweight face detection model, exported to ONNX. I wrote the whole inference pipeline for the browser: preprocessing, decoding the raw model outputs, non-maximum suppression and drawing. There is no server and no Python, so images never leave the device.

What it does

How it works

  1. 01Letterbox the image or video frame into a 640x640 canvas, keeping its aspect ratio.
  2. 02Pack the pixels into a planar BGR float tensor, the layout the model expects.
  3. 03Run YuNet with ONNX Runtime Web on WebAssembly.
  4. 04Decode class, objectness, box and landmark outputs at strides 8, 16 and 32.
  5. 05Drop overlapping boxes with non-maximum suppression and draw the results.

Stack

More projects

Work with me