Skip to content

Commit 8b715ae

Browse files
authored
Merge pull request #28 from sshaplygin/migrate-to-rust
Major updates
2 parents ef16e96 + c7fd5e6 commit 8b715ae

29 files changed

Lines changed: 42230 additions & 3383 deletions

.github/workflows/ci.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
frontend:
11+
name: Frontend
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- uses: actions/setup-node@v4
17+
with:
18+
node-version: 20
19+
cache: npm
20+
21+
- name: Install dependencies
22+
run: npm ci
23+
24+
- name: Typecheck
25+
run: npm run typecheck
26+
27+
rust:
28+
name: Rust
29+
runs-on: ubuntu-latest
30+
defaults:
31+
run:
32+
working-directory: native
33+
steps:
34+
- uses: actions/checkout@v4
35+
36+
- name: Install system dependencies
37+
run: |
38+
sudo apt-get update
39+
sudo apt-get install -y libopencv-dev libclang-dev pkg-config
40+
41+
- uses: dtolnay/rust-toolchain@stable
42+
with:
43+
components: clippy, rustfmt
44+
45+
- uses: Swatinem/rust-cache@v2
46+
with:
47+
workspaces: native -> target
48+
49+
- name: Check formatting
50+
run: cargo fmt -- --check
51+
52+
- name: Clippy
53+
run: cargo clippy -- -D warnings
54+
55+
- name: Build
56+
run: cargo build
57+
58+
- name: Test
59+
run: cargo test

.gitignore

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
*.pdf
2-
node_modules/
32
*.jpeg
43

54
# IDE system files
65
.idea
7-
.vscode
6+
.vscode
7+
8+
# Dependencies
9+
node_modules/
10+
11+
# Build output
12+
out/
13+
dist/
14+
build/
15+
16+
# Rust / native
17+
native/target/
18+
*.node
19+
20+
# Electron-vite
21+
.electron-vite/
22+
23+
# OS files
24+
.DS_Store

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
The MIT License (MIT)
33

4-
Copyright (c) 2018 Semen Shaplygin
4+
Copyright (c) 2018 Sam Shaplygin
55

66
Permission is hereby granted, free of charge, to any person obtaining a copy
77
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 67 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,79 @@
1-
Face detecation
2-
================
3-
Desktop application face detection on web-cam flow
1+
# Face Detection
42

3+
Desktop application for real-time face detection on a webcam stream, built with Electron, Svelte 5, Rust and OpenCV.
54

6-
## 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.
76

8-
```
9-
git clone https://github.com/sshaplygin/face-detection.git
10-
cd face-recog
11-
npm install
12-
npm start
7+
## Prerequisites
138

14-
```
9+
- **Node.js** >= 20
10+
- **Rust** stable toolchain
11+
- **OpenCV 4** development libraries
12+
- **libclang** (required by the `opencv` Rust crate)
13+
14+
### macOS
1515

16-
If you want tested opencv only command windows use:
16+
```bash
17+
brew install opencv llvm pkg-config
1718
```
18-
node webcam.js
19+
20+
### Ubuntu / Debian
21+
22+
```bash
23+
sudo apt-get install -y libopencv-dev libclang-dev pkg-config
1924
```
2025

21-
If you want pack, rebuild or run with debug use:
26+
## Getting Started
27+
28+
```bash
29+
git clone https://github.com/sshaplygin/face-detection.git
30+
cd face-detection
31+
npm install
32+
npm run dev
2233
```
23-
"pack": "electron-builder --dir",
24-
"rebuild": "electron-rebuild -f -w opencv4nodejs",
25-
"dev": "electron . --debug"
34+
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
2660
```
2761

28-
## Depencies
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
2978

30-
* electron
31-
* electron-builder
32-
* electron-compilers
33-
* electron-rebuild
34-
* opencv
79+
[MIT](LICENSE.md) — Sam Shaplygin

build/entitlements.mac.plist

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.security.cs.allow-jit</key>
6+
<true/>
7+
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
8+
<true/>
9+
<key>com.apple.security.device.camera</key>
10+
<true/>
11+
</dict>
12+
</plist>

electron.vite.config.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
2+
import { svelte } from '@sveltejs/vite-plugin-svelte'
3+
4+
export default defineConfig({
5+
main: {
6+
plugins: [externalizeDepsPlugin({ exclude: [] })],
7+
build: {
8+
rollupOptions: {
9+
external: [/\.node$/]
10+
}
11+
}
12+
},
13+
preload: {
14+
plugins: [externalizeDepsPlugin()]
15+
},
16+
renderer: {
17+
plugins: [svelte()],
18+
build: {
19+
rollupOptions: {
20+
input: './src/renderer/index.html'
21+
}
22+
}
23+
}
24+
})

index.html

Lines changed: 0 additions & 48 deletions
This file was deleted.

main.css

Lines changed: 0 additions & 102 deletions
This file was deleted.

0 commit comments

Comments
 (0)