|
1 | | -# Face detection |
| 1 | +# Face Detection |
2 | 2 |
|
3 | | -Desktop application face detection on web-cam flow from Elector, OpenCV and Rust |
| 3 | +Desktop application for real-time face detection on a webcam stream, built with Electron, Svelte 5, Rust and OpenCV. |
4 | 4 |
|
5 | | -## Usage |
| 5 | +The renderer captures RGBA frames from the camera, sends them to the main process via IPC, where a Rust native module (NAPI-RS) runs Haar cascade face detection with OpenCV and draws bounding boxes. Processed frames are rendered back on a canvas. Video recording to WebM is also supported. |
| 6 | + |
| 7 | +## Prerequisites |
| 8 | + |
| 9 | +- **Node.js** >= 20 |
| 10 | +- **Rust** stable toolchain |
| 11 | +- **OpenCV 4** development libraries |
| 12 | +- **libclang** (required by the `opencv` Rust crate) |
| 13 | + |
| 14 | +### macOS |
| 15 | + |
| 16 | +```bash |
| 17 | +brew install opencv llvm pkg-config |
| 18 | +``` |
| 19 | + |
| 20 | +### Ubuntu / Debian |
| 21 | + |
| 22 | +```bash |
| 23 | +sudo apt-get install -y libopencv-dev libclang-dev pkg-config |
| 24 | +``` |
| 25 | + |
| 26 | +## Getting Started |
6 | 27 |
|
7 | 28 | ```bash |
8 | 29 | git clone https://github.com/sshaplygin/face-detection.git |
9 | 30 | cd face-detection |
10 | | -npm i && npm dev |
| 31 | +npm install |
| 32 | +npm run dev |
11 | 33 | ``` |
12 | 34 |
|
13 | | -## Depencies |
| 35 | +## Scripts |
| 36 | + |
| 37 | +| Script | Description | |
| 38 | +| --- | --- | |
| 39 | +| `npm run dev` | Build native module (debug) and start electron-vite dev server | |
| 40 | +| `npm run build` | Build native module (release) and bundle the Electron app | |
| 41 | +| `npm run pack` | Build and package into a directory (no installer) | |
| 42 | +| `npm run dist` | Build and create a distributable installer | |
| 43 | +| `npm run build:native` | Build the Rust native module (debug) | |
| 44 | +| `npm run build:native:release` | Build the Rust native module (release, with LTO) | |
| 45 | +| `npm run typecheck` | Run svelte-check TypeScript validation | |
| 46 | + |
| 47 | +## Architecture |
| 48 | + |
| 49 | +```text |
| 50 | +src/ |
| 51 | + main/index.ts # Electron main process — loads native .node binary, handles IPC |
| 52 | + preload/index.ts # Context bridge between main and renderer |
| 53 | + renderer/ |
| 54 | + App.svelte # Svelte 5 UI — camera control, frame loop, recording |
| 55 | + main.ts # Renderer entry point |
| 56 | +native/ |
| 57 | + src/lib.rs # Rust NAPI module — Haar cascade face detection via OpenCV |
| 58 | + Cargo.toml # Rust dependencies (opencv, napi, once_cell) |
| 59 | + data/ # Haar cascade XML classifier |
| 60 | +``` |
| 61 | + |
| 62 | +## CI |
| 63 | + |
| 64 | +GitHub Actions runs on every push/PR to `master`: |
| 65 | + |
| 66 | +- **Frontend** — `npm ci` + `npm run typecheck` |
| 67 | +- **Rust** — `cargo fmt --check`, `cargo clippy -- -D warnings`, `cargo build`, `cargo test` |
| 68 | + |
| 69 | +## Tech Stack |
| 70 | + |
| 71 | +- [Electron](https://www.electronjs.org/) 34 — desktop shell |
| 72 | +- [Svelte](https://svelte.dev/) 5 — renderer UI |
| 73 | +- [electron-vite](https://electron-vite.org/) — build tooling |
| 74 | +- [NAPI-RS](https://napi.rs/) — Rust ↔ Node.js bridge |
| 75 | +- [OpenCV](https://opencv.org/) (Rust bindings) — face detection with Haar cascades |
| 76 | + |
| 77 | +## License |
14 | 78 |
|
15 | | -* electron |
16 | | -* electron-builder |
17 | | -* electron-compilers |
18 | | -* electron-rebuild |
19 | | -* opencv |
| 79 | +[MIT](LICENSE.md) — Sam Shaplygin |
0 commit comments