Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: CI

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
frontend:
name: Frontend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm

- name: Install dependencies
run: npm ci

- name: Typecheck
run: npm run typecheck

rust:
name: Rust
runs-on: ubuntu-latest
defaults:
run:
working-directory: native
steps:
- uses: actions/checkout@v4

- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y libopencv-dev libclang-dev pkg-config

- uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt

- uses: Swatinem/rust-cache@v2
with:
workspaces: native -> target

- name: Check formatting
run: cargo fmt -- --check

- name: Clippy
run: cargo clippy -- -D warnings

- name: Build
run: cargo build

- name: Test
run: cargo test
21 changes: 19 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
*.pdf
node_modules/
*.jpeg

# IDE system files
.idea
.vscode
.vscode

# Dependencies
node_modules/

# Build output
out/
dist/
build/

# Rust / native
native/target/
*.node

# Electron-vite
.electron-vite/

# OS files
.DS_Store
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

The MIT License (MIT)

Copyright (c) 2018 Semen Shaplygin
Copyright (c) 2018 Sam Shaplygin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
89 changes: 67 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,79 @@
Face detecation
================
Desktop application face detection on web-cam flow
# Face Detection

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

## Usage
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.

```
git clone https://github.com/sshaplygin/face-detection.git
cd face-recog
npm install
npm start
## Prerequisites

```
- **Node.js** >= 20
- **Rust** stable toolchain
- **OpenCV 4** development libraries
- **libclang** (required by the `opencv` Rust crate)

### macOS

If you want tested opencv only command windows use:
```bash
brew install opencv llvm pkg-config
```
node webcam.js

### Ubuntu / Debian

```bash
sudo apt-get install -y libopencv-dev libclang-dev pkg-config
```

If you want pack, rebuild or run with debug use:
## Getting Started

```bash
git clone https://github.com/sshaplygin/face-detection.git
cd face-detection
npm install
npm run dev
```
"pack": "electron-builder --dir",
"rebuild": "electron-rebuild -f -w opencv4nodejs",
"dev": "electron . --debug"

## Scripts

| Script | Description |
| --- | --- |
| `npm run dev` | Build native module (debug) and start electron-vite dev server |
| `npm run build` | Build native module (release) and bundle the Electron app |
| `npm run pack` | Build and package into a directory (no installer) |
| `npm run dist` | Build and create a distributable installer |
| `npm run build:native` | Build the Rust native module (debug) |
| `npm run build:native:release` | Build the Rust native module (release, with LTO) |
| `npm run typecheck` | Run svelte-check TypeScript validation |

## Architecture

```text
src/
main/index.ts # Electron main process — loads native .node binary, handles IPC
preload/index.ts # Context bridge between main and renderer
renderer/
App.svelte # Svelte 5 UI — camera control, frame loop, recording
main.ts # Renderer entry point
native/
src/lib.rs # Rust NAPI module — Haar cascade face detection via OpenCV
Cargo.toml # Rust dependencies (opencv, napi, once_cell)
data/ # Haar cascade XML classifier
```

## Depencies
## CI

GitHub Actions runs on every push/PR to `master`:

- **Frontend** — `npm ci` + `npm run typecheck`
- **Rust** — `cargo fmt --check`, `cargo clippy -- -D warnings`, `cargo build`, `cargo test`

## Tech Stack

- [Electron](https://www.electronjs.org/) 34 — desktop shell
- [Svelte](https://svelte.dev/) 5 — renderer UI
- [electron-vite](https://electron-vite.org/) — build tooling
- [NAPI-RS](https://napi.rs/) — Rust ↔ Node.js bridge
- [OpenCV](https://opencv.org/) (Rust bindings) — face detection with Haar cascades

## License

* electron
* electron-builder
* electron-compilers
* electron-rebuild
* opencv
[MIT](LICENSE.md) — Sam Shaplygin
12 changes: 12 additions & 0 deletions build/entitlements.mac.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
<key>com.apple.security.device.camera</key>
<true/>
</dict>
</plist>
24 changes: 24 additions & 0 deletions electron.vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'

export default defineConfig({
main: {
plugins: [externalizeDepsPlugin({ exclude: [] })],
build: {
rollupOptions: {
external: [/\.node$/]
}
}
},
preload: {
plugins: [externalizeDepsPlugin()]
},
renderer: {
plugins: [svelte()],
build: {
rollupOptions: {
input: './src/renderer/index.html'
}
}
}
})
48 changes: 0 additions & 48 deletions index.html

This file was deleted.

102 changes: 0 additions & 102 deletions main.css

This file was deleted.

Loading
Loading