> ## Documentation Index
> Fetch the complete documentation index at: https://docs.elata.bio/llms.txt
> Use this file to discover all available pages before exploring further.

# Camera Integration

> Add camera-based heart rate to a browser app with the Elata rPPG Web SDK.

> [!NOTE]
>
> Use this guide when you want lower-level control over camera-based heart rate in a browser app. For the recommended high-level API, start with [rPPG in a browser app](https://docs.elata.bio/sdk/guides/rppg-browser.md).

## What this guide covers

This guide shows how to:

* capture webcam frames in the browser
* detect a face and extract a face region
* feed samples into the rPPG processor
* read live BPM and signal quality
* improve estimates with Muse PPG when available

## Before you start

You need:

* `@elata-biosciences/rppg-web`
* a browser with camera access (`getUserMedia`) and WebAssembly support
* `https://` or `localhost`

```bash npm theme={null}
npm install @elata-biosciences/rppg-web
```

```bash pnpm theme={null}
pnpm add @elata-biosciences/rppg-web
```

> [!NOTE]
>
> rPPG works best when the face is well lit, mostly still, and fully visible in frame.

> [!TIP]
>
> Most apps should use `createRppgSession()`, which wraps everything on this page (WASM init, frame capture, ROI selection, diagnostics, cleanup). See [rPPG in a browser app](https://docs.elata.bio/sdk/guides/rppg-browser.md). Use the lower-level pieces below only when you need custom orchestration.

## Choose a starting point

> [card] [Start from a demo](https://docs.elata.bio/sdk/create-elata-demo.md)
>
> Scaffold a working browser app if you want the fastest path to a reference implementation.

> [card] [rPPG Web getting started](https://docs.elata.bio/sdk/rppg-web/getting-started.md)
>
> Learn the package entry points and the higher-level browser API.

> [card] [Frame sources](https://docs.elata.bio/sdk/rppg-web/frame-sources.md)
>
> See the lower-level camera and face-detection primitives used in this guide.

> [card] [Calibration and fusion](https://docs.elata.bio/sdk/rppg-web/calibration.md)
>
> Add Muse-based calibration when you want stronger estimates.

## Quick integration with DemoRunner

`DemoRunner` handles frame capture, face detection, ROI extraction, and processing in one flow, while leaving you in control of the processor.

```ts theme={null}
import {
  RppgProcessor,
  MediaPipeFrameSource,
  DemoRunner,
  loadWasmBackend,
} from "@elata-biosciences/rppg-web";

const video = document.querySelector("video")!; // a playing camera <video>
const backend = await loadWasmBackend(); // null if the packaged WASM can't be loaded
if (!backend) throw new Error("rPPG WASM backend unavailable");
const source = new MediaPipeFrameSource(video);
const processor = new RppgProcessor(backend, 30);

const runner = new DemoRunner(source, processor, {
  useSkinMask: true,
  onStats: () => {
    const metrics = processor.getMetrics();

    document.getElementById("bpm")!.textContent =
      metrics.bpm?.toFixed(0) ?? "--";

    document.getElementById("quality")!.textContent =
      `${(metrics.confidence * 100).toFixed(0)}%`;
  },
});

await runner.start();
```

> [!TIP]
>
> Show BPM only when `metrics.confidence` is above your app's threshold. A threshold around `0.5` is a practical starting point.

## Manual pipeline

Use the manual path when you want tighter control over face tracking, sampling, or how your app renders intermediate results.

**1. Load the face model and create a frame source**

```ts theme={null}
import {
  MediaPipeFaceFrameSource,
  loadFaceLandmarker,
} from "@elata-biosciences/rppg-web";

// Loads MediaPipe FaceLandmarker from a CDN; returns null if unavailable.
const faceLandmarker = await loadFaceLandmarker();
if (!faceLandmarker) throw new Error("Face tracking unavailable");
const source = new MediaPipeFaceFrameSource(video, faceLandmarker);
```

**2. Create the processor**

```ts theme={null}
import { RppgProcessor, loadWasmBackend } from "@elata-biosciences/rppg-web";

const backend = await loadWasmBackend();
if (!backend) throw new Error("rPPG WASM backend unavailable");
const processor = new RppgProcessor(backend, 30, 10);
```

The third argument sets a 10-second analysis window.

**3. Push samples from the face ROI**

```ts theme={null}
import { averageGreenInROI } from "@elata-biosciences/rppg-web";

source.onFrame = (frame) => {
  if (!frame.roi) return;

  const { x, y, w, h } = frame.roi;
  const green = averageGreenInROI(frame, x, y, w, h);

  processor.pushSample(
    frame.timestampMs ?? performance.now(),
    green,
  );
};
```

**4. Start the camera and read metrics**

```ts theme={null}
await source.start();

setInterval(() => {
  const metrics = processor.getMetrics();
  console.log("BPM:", metrics.bpm, "confidence:", metrics.confidence);
}, 1000);
```

## Add Muse calibration

If a Muse device is available, you can use its PPG as a reference signal to improve camera-based estimates.

```ts theme={null}
// `processor` is the RppgProcessor created above
processor.updateMuseMetrics(museBpm, 0.9, performance.now());
```

> [!NOTE]
>
> For a fuller fusion workflow, including `MuseFusionCalibrator` and calibration models, continue to [/sdk/rppg-web/calibration](https://docs.elata.bio/sdk/rppg-web/calibration.md).

## Quality checklist

Use this checklist before debugging the pipeline:

* keep lighting even across the face
* reduce head movement
* wait 5 to 10 seconds before trusting early BPM output
* make sure a face ROI is actually being detected
* enable `useSkinMask` when you use `DemoRunner`

## Where to go next

> [card] [rPPG Web getting started](https://docs.elata.bio/sdk/rppg-web/getting-started.md)
>
> Learn the package surface and the higher-level browser session API.

> [card] [Frame sources](https://docs.elata.bio/sdk/rppg-web/frame-sources.md)
>
> Understand the camera and face-detection primitives in more detail.

> [card] [Calibration and fusion](https://docs.elata.bio/sdk/rppg-web/calibration.md)
>
> Improve estimates with Muse-based calibration and multi-source fusion.

> [card] [create-elata-demo](https://docs.elata.bio/sdk/create-elata-demo.md)
>
> Start from a working reference app if you want a faster onboarding path.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.