# alexisharara/raspberrypiefacialrecognition architecture

> Architecture diagram of the GitHub repository alexisharara/raspberrypiefacialrecognition, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alexisharara/raspberrypiefacialrecognition
- Repository: https://github.com/alexisharara/raspberrypiefacialrecognition
- Video tour (about a minute): https://gitdiagram.com/alexisharara/raspberrypiefacialrecognition/video

## Overview

This Raspberry Pi treasure box uses face recognition to decide whether to unlock a physical latch. The main workflow is a button press, image capture, face detection and normalization, model prediction, then a hardware lock action. Separate scripts collect positive samples and train the recognizer from positive and negative images. The README is brief; the sampled source shows the Pi-camera path and documents a webcam alternative. Edges reflect visible calls and reads/writes; optional webcam wiring is documented in config.py rather than verified at runtime.

Main entry points: [`config.py`](https://github.com/alexisharara/raspberrypiefacialrecognition/blob/master/config.py) (Runtime configuration), [`box.py`](https://github.com/alexisharara/raspberrypiefacialrecognition/blob/master/box.py) (Lock controller), [`train.py`](https://github.com/alexisharara/raspberrypiefacialrecognition/blob/master/train.py) (Model trainer), [`hardware.py`](https://github.com/alexisharara/raspberrypiefacialrecognition/blob/master/hardware.py) (Button and servo)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Box control"]
  node_box["Lock controller<br/>[box.py]"]
  node_config["Runtime configuration<br/>[config.py]"]
end

subgraph group_vision["Face recognition"]
  node_face["Face detection and crop<br/>[face.py]"]
  node_recognizer["Eigenface recognizer"]
end

subgraph group_capture["Capture and hardware"]
  node_camera["Pi camera capture<br/>[picam.py]"]
  node_webcam["USB webcam capture<br/>[webcam.py]"]
  node_hardware["Button and servo<br/>[hardware.py]"]
end

subgraph group_training["Training data"]
  node_positive_capture["Positive image capture"]
  node_usb_capture["USB positive capture"]
  node_positive_data[("Positive face images")]
  node_negative_data[("Negative face images")]
  node_trainer["Model trainer<br/>[train.py]"]
  node_model_file["Saved model file"]
end

node_operator(("User"))
node_gpio["GPIO and servo hardware"]

node_operator -->|"presses button"| node_hardware
node_box -->|"loads settings"| node_config
node_box -->|"checks and actuates"| node_hardware
node_box -->|"loads and predicts"| node_recognizer
node_box -->|"detects and crops"| node_face
node_config -->|"creates camera"| node_camera
node_config -.->|"selects alternative"| node_webcam
node_hardware -->|"reads and drives"| node_gpio
node_positive_capture -->|"gets settings"| node_config
node_positive_capture -->|"checks button"| node_hardware
node_positive_capture -->|"detects and crops"| node_face
node_positive_capture -->|"writes images"| node_positive_data
node_usb_capture -->|"gets settings"| node_config
node_usb_capture -->|"checks button"| node_hardware
node_usb_capture -->|"detects and crops"| node_face
node_usb_capture -->|"writes images"| node_positive_data
node_trainer -->|"reads settings"| node_config
node_trainer -->|"resizes images"| node_face
node_trainer -->|"reads images"| node_positive_data
node_trainer -->|"reads images"| node_negative_data
node_trainer -->|"saves model"| node_model_file
node_box -->|"loads model"| node_model_file

click node_box "https://github.com/alexisharara/raspberrypiefacialrecognition/blob/master/box.py"
click node_config "https://github.com/alexisharara/raspberrypiefacialrecognition/blob/master/config.py"
click node_face "https://github.com/alexisharara/raspberrypiefacialrecognition/blob/master/face.py"
click node_camera "https://github.com/alexisharara/raspberrypiefacialrecognition/blob/master/picam.py"
click node_webcam "https://github.com/alexisharara/raspberrypiefacialrecognition/blob/master/webcam.py"
click node_hardware "https://github.com/alexisharara/raspberrypiefacialrecognition/blob/master/hardware.py"
click node_positive_capture "https://github.com/alexisharara/raspberrypiefacialrecognition/blob/master/capture-positives.py"
click node_usb_capture "https://github.com/alexisharara/raspberrypiefacialrecognition/blob/master/capture-positives_usbcam.py"
click node_positive_data "https://github.com/alexisharara/raspberrypiefacialrecognition/tree/master/training"
click node_negative_data "https://github.com/alexisharara/raspberrypiefacialrecognition/tree/master/training/negative"
click node_trainer "https://github.com/alexisharara/raspberrypiefacialrecognition/blob/master/train.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_box,node_config,node_operator toneBlue
class node_face,node_recognizer toneAmber
class node_camera,node_webcam,node_hardware toneMint
class node_positive_capture,node_usb_capture,node_positive_data,node_negative_data,node_trainer,node_model_file toneRose
class node_gpio toneIndigo
```

## Components

### Box control

- [Lock controller](https://github.com/alexisharara/raspberrypiefacialrecognition/blob/master/box.py): `box.py`
- [Runtime configuration](https://github.com/alexisharara/raspberrypiefacialrecognition/blob/master/config.py): `config.py`

### Face recognition

- [Face detection and crop](https://github.com/alexisharara/raspberrypiefacialrecognition/blob/master/face.py): `face.py`
- **Eigenface recognizer**

### Capture and hardware

- [Pi camera capture](https://github.com/alexisharara/raspberrypiefacialrecognition/blob/master/picam.py): `picam.py`
- [USB webcam capture](https://github.com/alexisharara/raspberrypiefacialrecognition/blob/master/webcam.py): `webcam.py`
- [Button and servo](https://github.com/alexisharara/raspberrypiefacialrecognition/blob/master/hardware.py): `hardware.py`

### Training data

- [Positive image capture](https://github.com/alexisharara/raspberrypiefacialrecognition/blob/master/capture-positives.py): `capture-positives.py`
- [USB positive capture](https://github.com/alexisharara/raspberrypiefacialrecognition/blob/master/capture-positives_usbcam.py): `capture-positives_usbcam.py`
- [Positive face images](https://github.com/alexisharara/raspberrypiefacialrecognition/tree/master/training): `training`
- [Negative face images](https://github.com/alexisharara/raspberrypiefacialrecognition/tree/master/training/negative): `training/negative`
- [Model trainer](https://github.com/alexisharara/raspberrypiefacialrecognition/blob/master/train.py): `train.py`
- **Saved model file**

### Other components

- **User**
- **GPIO and servo hardware**

## Connections

- User → Button and servo: presses button (evidence: `hardware.py`)
- Lock controller → Runtime configuration: loads settings (evidence: `box.py`)
- Lock controller → Button and servo: checks and actuates (evidence: `box.py`)
- Lock controller → Eigenface recognizer: loads and predicts (evidence: `box.py`)
- Lock controller → Face detection and crop: detects and crops (evidence: `box.py`)
- Runtime configuration → Pi camera capture: creates camera (evidence: `config.py`)
- Runtime configuration → USB webcam capture: selects alternative (evidence: `config.py`)
- Button and servo → GPIO and servo hardware: reads and drives (evidence: `hardware.py`)
- Positive image capture → Runtime configuration: gets settings (evidence: `capture-positives.py`)
- Positive image capture → Button and servo: checks button (evidence: `capture-positives.py`)
- Positive image capture → Face detection and crop: detects and crops (evidence: `capture-positives.py`)
- Positive image capture → Positive face images: writes images (evidence: `capture-positives.py`)
- USB positive capture → Runtime configuration: gets settings (evidence: `capture-positives_usbcam.py`)
- USB positive capture → Button and servo: checks button (evidence: `capture-positives_usbcam.py`)
- USB positive capture → Face detection and crop: detects and crops (evidence: `capture-positives_usbcam.py`)
- USB positive capture → Positive face images: writes images (evidence: `capture-positives_usbcam.py`)
- Model trainer → Runtime configuration: reads settings (evidence: `train.py`)
- Model trainer → Face detection and crop: resizes images (evidence: `train.py`)
- Model trainer → Positive face images: reads images (evidence: `train.py`)
- Model trainer → Negative face images: reads images (evidence: `train.py`)
- Model trainer → Saved model file: saves model (evidence: `train.py`)
- Lock controller → Saved model file: loads model (evidence: `box.py`)
