File size: 2,289 Bytes
9e89884
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
---
title: Reachy Mini Face Detection
emoji: πŸ€–
colorFrom: blue
colorTo: indigo
sdk: static
pinned: false
tags:
  - reachy_mini
  - reachy_mini_python_app
---

# Reachy Mini β€” Face & Expression Detection

A small [Reachy Mini](https://huggingface.co/docs/reachy_mini) app that watches
the camera, detects a face and a simple facial expression, and replies with a
random expressive movement (head + antennas + body).

- **Happy** (a smile is detected) β†’ quick nods, antenna wiggles, cheerful bobs.
- **Neutral** (a face, no smile) β†’ curious tilts, gentle look-arounds.
- **No face** β†’ a slow idle "breathing" motion.

The design keeps the detection and behaviour logic completely separate from the
robot SDK, so you can develop and test the whole thing on your laptop.

## Project layout

```
face_detection/
β”œβ”€β”€ detector.py        # Face + expression detection (OpenCV Haar cascades)
β”œβ”€β”€ behavior.py        # Expression -> random Movement (pure logic, no SDK)
β”œβ”€β”€ main.py            # ReachyMiniApp glue + daemon entry point
└── local_preview.py   # Run on a laptop webcam, no robot required
index.html             # Boilerplate for Hugging Face Space
style.css              # Boilerplate for Hugging Face Space
tests/                 # Unit tests for detector + behaviour
```

## Requirements

- Python 3.12+
- [`uv`](https://docs.astral.sh/uv/) for environments and packaging

## Quick start (local, no robot)

```bash
uv venv --python 3.12
uv pip install -e ".[dev]"

# Run the test suite (TDD)
uv run pytest

# Try it live on your webcam β€” prints the detected expression and the
# movement the robot *would* perform. Press 'q' to quit.
uv run face-detection-preview
```

## Running on the robot

See [PUBLISHING.md](PUBLISHING.md) for packaging, installing and publishing the
app to a Reachy Mini via Hugging Face Spaces.

## How it works

1. The daemon launches the app and hands it a connected `ReachyMini` instance.
2. Each loop iteration grabs a camera frame (`mini.media.get_frame()`).
3. `FaceDetector` finds the largest face and classifies its expression.
4. `MovementPlanner` picks a random movement for that expression.
5. The app sends it to the robot with `goto_target(...)`.
6. On stop, the daemon returns the robot to its default pose.