# hwarinn66/dense-object-counter architecture

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

- Interactive diagram: https://gitdiagram.com/hwarinn66/dense-object-counter
- Repository: https://github.com/hwarinn66/dense-object-counter

## Overview

This is a local FastAPI dense-object counter: a camera preview feeds a dashboard, motion detection triggers a full-resolution snapshot, ROI cropping and detection produce a numbered count, and images/results can be retained. The README also documents dataset preparation, model training, and count evaluation as distinct workflows. Edges are limited to relationships shown in excerpts, the SOURCE INDEX, or README; several training and UI details are documented but their runtime wiring was not sampled.

Main entry points: [`app.py`](https://github.com/hwarinn66/dense-object-counter/blob/main/app.py) (FastAPI App), [`counting/counter.py`](https://github.com/hwarinn66/dense-object-counter/blob/main/counting/counter.py) (Snapshot Counter), [`counting/auto_trigger.py`](https://github.com/hwarinn66/dense-object-counter/blob/main/counting/auto_trigger.py) (Stillness Trigger), [`detection/factory.py`](https://github.com/hwarinn66/dense-object-counter/blob/main/detection/factory.py) (Detector Factory)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Capture and Web"]
  node_dashboard["Dashboard UI<br/>[index.html]"]
  node_browser_logic["Browser Controls<br/>[app.js]"]
  node_api["FastAPI App<br/>[app.py]"]
  node_camera["Camera Manager<br/>[camera_manager.py]"]
  node_config["Runtime Settings<br/>[config.py]"]
end

subgraph group_counting["Counting Pipeline"]
  node_auto["Stillness Trigger<br/>[auto_trigger.py]"]
  node_roi["ROI Policy<br/>[roi.py]"]
  node_counter["Snapshot Counter<br/>[counter.py]"]
  node_output[("Saved Results")]
end

subgraph group_models["Detection"]
  node_detector_factory["Detector Factory<br/>[factory.py]"]
  node_detector_contract["Detector Contract<br/>[base_detector.py]"]
  node_opencv["OpenCV Baseline<br/>[opencv_detector.py]"]
  node_yolo["YOLO Detector<br/>[yolo_detector.py]"]
  node_tiling["Tiled Inference<br/>[tiled_inference.py]"]
end

subgraph group_ml["Dataset and Training"]
  node_dataset[("Dataset Files")]
  node_dataset_utils["Dataset Validation<br/>[dataset_utils.py]"]
  node_tile_prep["Training Tiles<br/>[prepare_tiles.py]"]
  node_training["Model Training<br/>[train.py]"]
  node_evaluation["Count Evaluation"]
end

node_operator(("Operator"))
node_camera_source(("Camera Source"))

node_operator -->|"uses"| node_dashboard
node_dashboard -->|"loads"| node_browser_logic
node_browser_logic -->|"polls and controls"| node_api
node_api -->|"serves"| node_dashboard
node_camera_source -->|"provides frames"| node_camera
node_api -->|"starts"| node_camera
node_api -->|"configures"| node_config
node_api -->|"creates detector"| node_detector_factory
node_api -->|"manages"| node_auto
node_api -->|"manages"| node_counter
node_auto -->|"samples frames"| node_camera
node_auto -->|"triggers count"| node_counter
node_auto -->|"checks scene ROI"| node_roi
node_counter -->|"takes snapshot"| node_camera
node_counter -->|"crops snapshot"| node_roi
node_counter -->|"runs inference"| node_tiling
node_counter -->|"saves images"| node_output
node_detector_factory -->|"selects"| node_opencv
node_detector_factory -->|"selects"| node_yolo
node_opencv -->|"implements"| node_detector_contract
node_yolo -->|"implements"| node_detector_contract
node_tiling -->|"calls detector"| node_detector_contract
node_dataset_utils -->|"validates labels"| node_dataset
node_tile_prep -->|"uses dataset tools"| node_dataset_utils
node_training -->|"validates dataset"| node_dataset_utils
node_evaluation -->|"loads annotations"| node_dataset_utils
node_evaluation -->|"creates detector"| node_detector_factory
node_evaluation -->|"evaluates pipeline"| node_tiling

click node_dashboard "https://github.com/hwarinn66/dense-object-counter/blob/main/templates/index.html"
click node_browser_logic "https://github.com/hwarinn66/dense-object-counter/blob/main/static/app.js"
click node_api "https://github.com/hwarinn66/dense-object-counter/blob/main/app.py"
click node_camera "https://github.com/hwarinn66/dense-object-counter/blob/main/camera/camera_manager.py"
click node_config "https://github.com/hwarinn66/dense-object-counter/blob/main/config.py"
click node_auto "https://github.com/hwarinn66/dense-object-counter/blob/main/counting/auto_trigger.py"
click node_roi "https://github.com/hwarinn66/dense-object-counter/blob/main/counting/roi.py"
click node_counter "https://github.com/hwarinn66/dense-object-counter/blob/main/counting/counter.py"
click node_output "https://github.com/hwarinn66/dense-object-counter/tree/main/output"
click node_detector_factory "https://github.com/hwarinn66/dense-object-counter/blob/main/detection/factory.py"
click node_detector_contract "https://github.com/hwarinn66/dense-object-counter/blob/main/detection/base_detector.py"
click node_opencv "https://github.com/hwarinn66/dense-object-counter/blob/main/detection/opencv_detector.py"
click node_yolo "https://github.com/hwarinn66/dense-object-counter/blob/main/detection/yolo_detector.py"
click node_tiling "https://github.com/hwarinn66/dense-object-counter/blob/main/detection/tiled_inference.py"
click node_dataset "https://github.com/hwarinn66/dense-object-counter/tree/main/dataset"
click node_dataset_utils "https://github.com/hwarinn66/dense-object-counter/blob/main/training/dataset_utils.py"
click node_tile_prep "https://github.com/hwarinn66/dense-object-counter/blob/main/training/prepare_tiles.py"
click node_training "https://github.com/hwarinn66/dense-object-counter/blob/main/training/train.py"
click node_evaluation "https://github.com/hwarinn66/dense-object-counter/blob/main/training/evaluate_counting.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_dashboard,node_browser_logic,node_api,node_camera,node_config toneBlue
class node_auto,node_roi,node_counter,node_output toneAmber
class node_detector_factory,node_detector_contract,node_opencv,node_yolo,node_tiling toneMint
class node_dataset,node_dataset_utils,node_tile_prep,node_training,node_evaluation toneRose
class node_operator,node_camera_source toneIndigo
```

## Components

### Capture and Web

- [Dashboard UI](https://github.com/hwarinn66/dense-object-counter/blob/main/templates/index.html): `templates/index.html`
- [Browser Controls](https://github.com/hwarinn66/dense-object-counter/blob/main/static/app.js): `static/app.js`
- [FastAPI App](https://github.com/hwarinn66/dense-object-counter/blob/main/app.py): `app.py`
- [Camera Manager](https://github.com/hwarinn66/dense-object-counter/blob/main/camera/camera_manager.py): `camera/camera_manager.py`
- [Runtime Settings](https://github.com/hwarinn66/dense-object-counter/blob/main/config.py): `config.py`

### Counting Pipeline

- [Stillness Trigger](https://github.com/hwarinn66/dense-object-counter/blob/main/counting/auto_trigger.py): `counting/auto_trigger.py`
- [ROI Policy](https://github.com/hwarinn66/dense-object-counter/blob/main/counting/roi.py): `counting/roi.py`
- [Snapshot Counter](https://github.com/hwarinn66/dense-object-counter/blob/main/counting/counter.py): `counting/counter.py`
- [Saved Results](https://github.com/hwarinn66/dense-object-counter/tree/main/output): `output`

### Detection

- [Detector Factory](https://github.com/hwarinn66/dense-object-counter/blob/main/detection/factory.py): `detection/factory.py`
- [Detector Contract](https://github.com/hwarinn66/dense-object-counter/blob/main/detection/base_detector.py): `detection/base_detector.py`
- [OpenCV Baseline](https://github.com/hwarinn66/dense-object-counter/blob/main/detection/opencv_detector.py): `detection/opencv_detector.py`
- [YOLO Detector](https://github.com/hwarinn66/dense-object-counter/blob/main/detection/yolo_detector.py): `detection/yolo_detector.py`
- [Tiled Inference](https://github.com/hwarinn66/dense-object-counter/blob/main/detection/tiled_inference.py): `detection/tiled_inference.py`

### Dataset and Training

- [Dataset Files](https://github.com/hwarinn66/dense-object-counter/tree/main/dataset): `dataset`
- [Dataset Validation](https://github.com/hwarinn66/dense-object-counter/blob/main/training/dataset_utils.py): `training/dataset_utils.py`
- [Training Tiles](https://github.com/hwarinn66/dense-object-counter/blob/main/training/prepare_tiles.py): `training/prepare_tiles.py`
- [Model Training](https://github.com/hwarinn66/dense-object-counter/blob/main/training/train.py): `training/train.py`
- [Count Evaluation](https://github.com/hwarinn66/dense-object-counter/blob/main/training/evaluate_counting.py): `training/evaluate_counting.py`

### Other components

- **Operator**
- **Camera Source**

## Connections

- Operator → Dashboard UI: uses (evidence: `README.md`)
- Dashboard UI → Browser Controls: loads (evidence: `README.md`)
- Browser Controls → FastAPI App: polls and controls (evidence: `README.md`)
- FastAPI App → Dashboard UI: serves (evidence: `app.py`)
- Camera Source → Camera Manager: provides frames (evidence: `README.md`)
- FastAPI App → Camera Manager: starts (evidence: `app.py`)
- FastAPI App → Runtime Settings: configures (evidence: `app.py`)
- FastAPI App → Detector Factory: creates detector (evidence: `app.py`)
- FastAPI App → Stillness Trigger: manages (evidence: `app.py`)
- FastAPI App → Snapshot Counter: manages (evidence: `app.py`)
- Stillness Trigger → Camera Manager: samples frames (evidence: `counting/auto_trigger.py`)
- Stillness Trigger → Snapshot Counter: triggers count (evidence: `counting/auto_trigger.py`)
- Stillness Trigger → ROI Policy: checks scene ROI (evidence: `counting/auto_trigger.py`)
- Snapshot Counter → Camera Manager: takes snapshot (evidence: `counting/counter.py`)
- Snapshot Counter → ROI Policy: crops snapshot (evidence: `counting/counter.py`)
- Snapshot Counter → Tiled Inference: runs inference (evidence: `counting/counter.py`)
- Snapshot Counter → Saved Results: saves images (evidence: `counting/counter.py`)
- Detector Factory → OpenCV Baseline: selects (evidence: `detection/factory.py`)
- Detector Factory → YOLO Detector: selects (evidence: `detection/factory.py`)
- OpenCV Baseline → Detector Contract: implements (evidence: `detection/opencv_detector.py`)
- YOLO Detector → Detector Contract: implements (evidence: `detection/yolo_detector.py`)
- Tiled Inference → Detector Contract: calls detector (evidence: `detection/tiled_inference.py`)
- Dataset Validation → Dataset Files: validates labels (evidence: `training/dataset_utils.py`)
- Training Tiles → Dataset Validation: uses dataset tools (evidence: `README.md`)
- Model Training → Dataset Validation: validates dataset (evidence: `README.md`)
- Count Evaluation → Dataset Validation: loads annotations (evidence: `training/evaluate_counting.py`)
- Count Evaluation → Detector Factory: creates detector (evidence: `training/evaluate_counting.py`)
- Count Evaluation → Tiled Inference: evaluates pipeline (evidence: `training/evaluate_counting.py`)
