Skip to content

Commit c7fd5e6

Browse files
committed
ref: clippy errros
1 parent 92c7455 commit c7fd5e6

2 files changed

Lines changed: 74 additions & 20 deletions

File tree

README.md

Lines changed: 70 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,79 @@
1-
# Face detection
1+
# Face Detection
22

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.
44

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
627

728
```bash
829
git clone https://github.com/sshaplygin/face-detection.git
930
cd face-detection
10-
npm i && npm dev
31+
npm install
32+
npm run dev
1133
```
1234

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
1478

15-
* electron
16-
* electron-builder
17-
* electron-compilers
18-
* electron-rebuild
19-
* opencv
79+
[MIT](LICENSE.md) — Sam Shaplygin

native/src/lib.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use napi::bindgen_prelude::*;
22
use napi_derive::napi;
3-
use opencv::core::{AlgorithmHint, Mat, Rect, Scalar, Size, CV_8UC4};
3+
use once_cell::sync::OnceCell;
4+
use opencv::core::{Mat, Rect, Scalar, Size, CV_8UC4};
45
use opencv::imgproc;
56
use opencv::objdetect::CascadeClassifier;
67
use opencv::prelude::*;
7-
use once_cell::sync::OnceCell;
88
use std::sync::Mutex;
99

1010
static CASCADE: OnceCell<Mutex<CascadeClassifier>> = OnceCell::new();
@@ -69,14 +69,8 @@ pub fn process_frame(input: Buffer, width: i32, height: i32) -> Result<Buffer> {
6969

7070
// RGBA → Grayscale for detection
7171
let mut gray = Mat::default();
72-
imgproc::cvt_color(
73-
&src,
74-
&mut gray,
75-
imgproc::COLOR_RGBA2GRAY,
76-
0,
77-
AlgorithmHint::ALGO_HINT_DEFAULT,
78-
)
79-
.map_err(|e| Error::from_reason(format!("cvtColor failed: {e}")))?;
72+
imgproc::cvt_color_def(&src, &mut gray, imgproc::COLOR_RGBA2GRAY)
73+
.map_err(|e| Error::from_reason(format!("cvtColor failed: {e}")))?;
8074

8175
// Equalize histogram to improve detection
8276
let mut eq = Mat::default();

0 commit comments

Comments
 (0)