# np-overflow/openhouse-ecd-cv architecture

> Architecture diagram of the GitHub repository np-overflow/openhouse-ecd-cv, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/np-overflow/openhouse-ecd-cv
- Repository: https://github.com/np-overflow/openhouse-ecd-cv

## Overview

Eye Can Drive’s Python computer-vision component turns webcam facial movement into driving values and exposes them to Unity over a WebSocket. The main path is camera capture, face-landmark analysis, EAR/MAR calculation, expression-state updates, and WebSocket transmission; Unity can also request a frame capture. The tree includes a separate controller/command-mapper design, but its detector dependency is absent and the Unity sender is an empty stub, so it is shown as a separate, incomplete path. Relationships reflect the excerpts and README, not uninspected runtime behavior.

Main entry points: [`detection/main.py`](https://github.com/np-overflow/openhouse-ecd-cv/blob/main/detection/main.py) (Vision loop), [`control/controller.py`](https://github.com/np-overflow/openhouse-ecd-cv/blob/main/control/controller.py) (Controller loop), [`detection/ratios.py`](https://github.com/np-overflow/openhouse-ecd-cv/blob/main/detection/ratios.py) (EAR / MAR), [`photocounter.txt`](https://github.com/np-overflow/openhouse-ecd-cv/blob/main/photocounter.txt) (Photo counter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_vision["Vision processing"]
  node_vision_loop["Vision loop<br/>[main.py]"]
  node_face_mesh["Face landmarks<br/>[main.py]"]
  node_ratios["EAR / MAR<br/>[ratios.py]"]
  node_expression_state["Driving state<br/>[main.py]"]
  node_image_capture["Frame capture<br/>[main.py]"]
  node_counter_file["Photo counter<br/>[photocounter.txt]"]
end

subgraph group_transport["Unity transport"]
  node_ws_server["WebSocket server<br/>[main.py]"]
end

subgraph group_control["Control mapping"]
  node_controller["Controller loop<br/>[controller.py]"]
  node_mapper["Command mapper<br/>[command_mapper.py]"]
  node_sender["Unity sender<br/>[unity_sender.py]"]
end

node_camera(("Webcam"))
node_unity(("Unity game"))

node_camera -->|"provides frames"| node_vision_loop
node_vision_loop -->|"processes frames"| node_face_mesh
node_face_mesh -->|"calculates ratios"| node_ratios
node_ratios -->|"supplies measurements"| node_expression_state
node_expression_state -->|"serves state"| node_ws_server
node_unity -->|"requests capture"| node_ws_server
node_ws_server -->|"sends state"| node_unity
node_ws_server -->|"handles request"| node_image_capture
node_vision_loop -->|"captures frame"| node_image_capture
node_vision_loop -->|"writes count"| node_counter_file
node_controller -->|"maps detection"| node_mapper
node_controller -->|"sends commands"| node_sender

click node_vision_loop "https://github.com/np-overflow/openhouse-ecd-cv/blob/main/detection/main.py"
click node_face_mesh "https://github.com/np-overflow/openhouse-ecd-cv/blob/main/detection/main.py"
click node_ratios "https://github.com/np-overflow/openhouse-ecd-cv/blob/main/detection/ratios.py"
click node_expression_state "https://github.com/np-overflow/openhouse-ecd-cv/blob/main/detection/main.py"
click node_image_capture "https://github.com/np-overflow/openhouse-ecd-cv/blob/main/detection/main.py"
click node_counter_file "https://github.com/np-overflow/openhouse-ecd-cv/blob/main/photocounter.txt"
click node_ws_server "https://github.com/np-overflow/openhouse-ecd-cv/blob/main/detection/main.py"
click node_controller "https://github.com/np-overflow/openhouse-ecd-cv/blob/main/control/controller.py"
click node_mapper "https://github.com/np-overflow/openhouse-ecd-cv/blob/main/control/command_mapper.py"
click node_sender "https://github.com/np-overflow/openhouse-ecd-cv/blob/main/control/unity_sender.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_vision_loop,node_face_mesh,node_ratios,node_expression_state,node_image_capture,node_counter_file toneBlue
class node_ws_server toneAmber
class node_controller,node_mapper,node_sender toneMint
class node_camera,node_unity toneIndigo
```

## Components

### Vision processing

- [Vision loop](https://github.com/np-overflow/openhouse-ecd-cv/blob/main/detection/main.py): `detection/main.py`
- [Face landmarks](https://github.com/np-overflow/openhouse-ecd-cv/blob/main/detection/main.py): `detection/main.py`
- [EAR / MAR](https://github.com/np-overflow/openhouse-ecd-cv/blob/main/detection/ratios.py): `detection/ratios.py`
- [Driving state](https://github.com/np-overflow/openhouse-ecd-cv/blob/main/detection/main.py): `detection/main.py`
- [Frame capture](https://github.com/np-overflow/openhouse-ecd-cv/blob/main/detection/main.py): `detection/main.py`
- [Photo counter](https://github.com/np-overflow/openhouse-ecd-cv/blob/main/photocounter.txt): `photocounter.txt`

### Unity transport

- [WebSocket server](https://github.com/np-overflow/openhouse-ecd-cv/blob/main/detection/main.py): `detection/main.py`

### Control mapping

- [Controller loop](https://github.com/np-overflow/openhouse-ecd-cv/blob/main/control/controller.py): `control/controller.py`
- [Command mapper](https://github.com/np-overflow/openhouse-ecd-cv/blob/main/control/command_mapper.py): `control/command_mapper.py`
- [Unity sender](https://github.com/np-overflow/openhouse-ecd-cv/blob/main/control/unity_sender.py): `control/unity_sender.py`

### Other components

- **Webcam**
- **Unity game**

## Connections

- Webcam → Vision loop: provides frames (evidence: `detection/main.py`)
- Vision loop → Face landmarks: processes frames (evidence: `detection/main.py`)
- Face landmarks → EAR / MAR: calculates ratios (evidence: `detection/main.py`)
- EAR / MAR → Driving state: supplies measurements (evidence: `detection/main.py`)
- Driving state → WebSocket server: serves state (evidence: `detection/main.py`)
- Unity game → WebSocket server: requests capture (evidence: `detection/main.py`)
- WebSocket server → Unity game: sends state (evidence: `detection/main.py`)
- WebSocket server → Frame capture: handles request (evidence: `detection/main.py`)
- Vision loop → Frame capture: captures frame (evidence: `detection/main.py`)
- Vision loop → Photo counter: writes count (evidence: `detection/main.py`)
- Controller loop → Command mapper: maps detection (evidence: `control/controller.py`)
- Controller loop → Unity sender: sends commands (evidence: `control/controller.py`)
