PAS7 Studio
Abstract illustration of an AI and browser camera experiment
Technology30 Aug 2026·5 min read·Updated 30 Aug 2026

How to Build Browser Camera Depth and Liveness Checks with Canvas and Face Landmarker

A practical guide to building a browser camera sandbox with live video, depth-like visualization, AI preprocessing, MediaPipe Face Landmarker and head-pose challenges.

Frontend developersAI engineersProduct teamsSecurity prototypers

A browser camera sandbox follows capture → pixels → landmarks → decision. getUserMedia provides the stream, Canvas lets you inspect pixels, and Face Landmarker provides face landmarks for approximate head-pose checks. A real anti-spoof system still needs additional liveness signals because landmarks alone do not prove a physical person is in front of the camera.

The frame can be processed locally without uploading camera images.
A depth-like map from one RGB camera is a visual proxy, not a metric distance measurement.
Random challenges are stronger than a fixed sequence but do not replace an anti-spoof model.
Xin
What we built

A visible path from live video to a useful signal

The point of a sandbox is to make inference understandable. Every layer can be switched on and inspected.

Camera mode shows the original stream.
Depth mode maps brightness and local contrast to a depth-like palette.
Edges mode exposes local image boundaries.
For AI mode shows conditional normalization, quantization and feature enhancement.
Liveness mode uses Face Landmarker for a guided head-pose challenge.
Architecture

Capture, pixels, landmarks, decision

01

Get the stream

Request getUserMedia after a user action, handle permission errors and stop every track during cleanup.

02

Draw the frame

Copy video into Canvas with drawImage. From there you can inspect ImageData and build visual filters.

03

Find structure

Face Landmarker returns face landmarks. The nose position relative to the eyes gives a simple normalized yaw signal.

04

Check the challenge

Hold each expected pose briefly, advance only after it is detected and show an explicit final result.

Code

The smallest useful camera loop

Start with a local MediaStream. The browser should ask for permission only after a clear user action and should always release tracks when the component unmounts.

TYPESCRIPT
const stream = await navigator.mediaDevices.getUserMedia({
  video: { facingMode: "user" },
  audio: false,
});

video.srcObject = stream;
await video.play();

const ctx = canvas.getContext("2d");
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);

The same Canvas frame can feed visualization, pixel analysis and a vision model without a server round trip.

Face Landmarker

Checking left, right and up

For a gesture challenge, compare stable face landmarks instead of trying to identify a person. Normalize the nose position by eye distance so the signal is less sensitive to how close the user sits to the camera.

TYPESCRIPT
const eyeDistance = Math.max(Math.abs(rightEye.x - leftEye.x), 0.01);
const eyeMidX = (leftEye.x + rightEye.x) / 2;
const yaw = (nose.x - eyeMidX) / eyeDistance;

const isLeft = yaw > 0.1;
const isRight = yaw < -0.1;

For an upward look, an absolute threshold can match a neutral face. Save a baseline at the beginning of the step and compare the change instead:

TYPESCRIPT
const pitchDelta = currentPitch - baselinePitch;
const isUp = pitchDelta < -0.08;
Security boundary

What this result does and does not prove

What it sees

A face, approximate landmarks and whether the observed pose matches the requested gesture.

What it does not prove

Landmarks do not prove a physical person is present. Replay video, screen recapture or deepfake content may still pass a simple challenge.

Production additions

Randomized challenges, blink cues, texture and screen-reflection analysis, temporal consistency, depth signals and a dedicated anti-spoof model.

Use cases

Where a camera liveness flow is useful

This is not only about login. Pose challenges can become a UX and risk signal wherever a product needs an active camera session.

Onboarding and KYC

Check a stable pose before selfie or document capture. This supports UX but does not replace regulated identity verification.

Remote proctoring

Ask for a random pose and notice when a session has become a static recording.

Sensitive actions

Add a short challenge before changing recovery details or confirming a high-impact action.

Vision research

Compare RGB, edge maps, depth-like color and landmarks on one frame without hiding behavior behind a black box.

Replay test

How to test a tablet video honestly

This red-team exercise shows the boundary between gesture detection and real anti-spoofing.

01

Record an honest session

Film yourself on a second device while completing each prompt in order.

02

Replay it to the camera

Place the tablet in front of the webcam and see whether landmarks remain stable.

03

Change the order

If a fixed sequence still passes, the challenge is too predictable.

04

Add randomness

Generate commands and a nonce per session instead of using one script for everyone.

05

Do not call it proof of a person

Landmarks confirm pose, not physical presence. Add screen, texture and depth signals plus an anti-spoof model.

FAQ

FAQ

Can one webcam provide true depth?

Not as a precise physical distance. The depth mode is a visual proxy based on brightness and contrast. Metric depth requires stereo, LiDAR or a dedicated monocular depth model.

Can liveness detection run fully in a browser?

Landmarks and some preprocessing can run locally. Production anti-spoof quality depends on the model and testing against replay, screen recapture, masks and synthetic media.

Is Face Landmarker face recognition?

No. It returns face geometry and helps estimate pose. It does not identify a person or prove that a live human is present.

Why randomize the challenge?

A fixed sequence is easier to replay. Randomized commands make a pre-recorded response harder, but they still need additional anti-spoof signals.

Where is the working demo?

Try the [Camera / Depth Sandbox](/sandbox/camera-depth), with the live demo on top and the pipeline, tutorial and starter code below it.

Sources

Documentation

Reviewed: 30 Aug 2026Applies to: Next.js 16Applies to: React 19Applies to: modern browsersApplies to: localhost or HTTPSTested with: MediaPipe Tasks VisionTested with: Canvas APITested with: navigator.mediaDevices.getUserMedia

Try the experiment yourself

Open the Camera / Depth Sandbox to switch between the live frame, depth-like map, AI preprocessing and liveness challenge. The demo is designed to make the pipeline visible and easy to extend.

Related Articles

AI Assistant Development Cost in 2026: RAG Chatbots, CRM Integrations, Guardrails, and Support
ai-assistants

AI Assistant Development Cost in 2026: RAG Chatbots, CRM Integrations, Guardrails, and Support

A practical buyer guide to AI assistant development cost in 2026: prototypes, RAG chatbots, knowledge-base assistants, CRM and website integrations, guardrails, evaluations, monitoring, and support.

AI Can Make More. Not Better: What Game Development Research Actually Says
blogs

AI Can Make More. Not Better: What Game Development Research Actually Says

Generative AI is entering game production, but the evidence is more nuanced than the hype. We examine developer adoption, player reception, quality risks, and a practical production model for using AI without outsourcing taste.

AI for landing page development: where it speeds up launches and where it hurts conversion
blogs

AI for landing page development: where it speeds up launches and where it hurts conversion

A practical research piece on using AI for landing page development: v0, Webflow AI, Builder.io, Framer-like builders, UX generation, copy, SEO, personalization, A/B testing, template risk, accessibility, security and technical debt.

AI SEO / GEO in 2026: Your Next Customers Aren’t Humans — They’re Agents
growth

AI SEO / GEO in 2026: Your Next Customers Aren’t Humans — They’re Agents

Search is shifting from clicks to answers. Bots and AI agents crawl, cite, recommend, and increasingly buy. Learn what AI SEO / GEO means, why classic SEO is no longer enough, and how PAS7 Studio helps brands win visibility in the agentic web.

Professional development for your business

We create modern web solutions and bots for businesses. Learn how we can help you achieve your goals.