# mmm1712/esp32-cam-ai-object-tracking architecture

> Architecture diagram of the GitHub repository mmm1712/esp32-cam-ai-object-tracking, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mmm1712/esp32-cam-ai-object-tracking
- Repository: https://github.com/mmm1712/esp32-cam-ai-object-tracking

## Overview

This is a prototype camera-tracking system: the ESP32-CAM streams video to a laptop, Python detects and tracks the target with YOLO, and serial movement commands drive pan/tilt servos through a second ESP32 and PCA9685. Separate Python utilities capture images and prepare labeled datasets; the README documents a custom trained model and printable, editable mount parts. The camera server and tracking script are excerpted, but the servo-controller implementation and several documented subsystems were not sampled, so their connections rely on the README.

Main entry points: [`arduino/esp32_cam_stream/app_httpd.cpp`](https://github.com/mmm1712/esp32-cam-ai-object-tracking/blob/main/arduino/esp32_cam_stream/app_httpd.cpp) (Stream Server), [`python/ai_tracking.py`](https://github.com/mmm1712/esp32-cam-ai-object-tracking/blob/main/python/ai_tracking.py) (AI Tracking), [`python/capture_images.py`](https://github.com/mmm1712/esp32-cam-ai-object-tracking/blob/main/python/capture_images.py) (Image Capture), [`python/prepare_dataset.py`](https://github.com/mmm1712/esp32-cam-ai-object-tracking/blob/main/python/prepare_dataset.py) (Dataset Preparation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_vision["Video and Tracking"]
  node_camera["ESP32-CAM"]
  node_cam_setup["Camera Startup"]
  node_http_server["Stream Server<br/>[app_httpd.cpp]"]
  node_camera_ui["Camera UI Assets<br/>[camera_index.h]"]
  node_camera_pins["Camera Pin Map<br/>[camera_pins.h]"]
  node_laptop(("Laptop"))
  node_tracking["AI Tracking<br/>[ai_tracking.py]"]
  node_yolo["YOLO Model<br/>[best.pt]"]
end

subgraph group_data["Dataset Preparation"]
  node_capture["Image Capture<br/>[capture_images.py]"]
  node_raw_images["Raw Images"]
  node_labels["Target Labels"]
  node_prepare["Dataset Preparation<br/>[prepare_dataset.py]"]
  node_dataset["YOLO Dataset"]
end

subgraph group_motion["Motion Hardware"]
  node_second_esp["Second ESP32"]
  node_pca["PCA9685 Driver"]
  node_servos["Pan Tilt Servos"]
end

subgraph group_mechanical["Mechanical Design"]
  node_mount_source["Mount Design"]
  node_printed_parts["Printed Parts"]
end

node_operator(("Operator"))

node_operator -->|"captures images"| node_capture
node_camera -->|"supplies frames"| node_http_server
node_cam_setup -.->|"starts server"| node_http_server
node_cam_setup -.->|"configures pins"| node_camera_pins
node_http_server -->|"serves assets"| node_camera_ui
node_http_server -->|"streams video"| node_laptop
node_laptop -->|"runs capture"| node_capture
node_capture -->|"saves frames"| node_raw_images
node_operator -.->|"annotates images"| node_labels
node_raw_images -->|"provides images"| node_prepare
node_labels -->|"provides labels"| node_prepare
node_prepare -->|"writes dataset"| node_dataset
node_laptop -->|"runs tracking"| node_tracking
node_http_server -->|"provides stream"| node_tracking
node_yolo -->|"loads model"| node_tracking
node_tracking -->|"sends serial commands"| node_second_esp
node_second_esp -->|"controls over I2C"| node_pca
node_pca -->|"drives servos"| node_servos
node_mount_source -->|"defines parts"| node_printed_parts

click node_cam_setup "https://github.com/mmm1712/esp32-cam-ai-object-tracking/blob/main/arduino/esp32_cam_stream/esp32_cam_stream.ino"
click node_http_server "https://github.com/mmm1712/esp32-cam-ai-object-tracking/blob/main/arduino/esp32_cam_stream/app_httpd.cpp"
click node_camera_ui "https://github.com/mmm1712/esp32-cam-ai-object-tracking/blob/main/arduino/esp32_cam_stream/camera_index.h"
click node_camera_pins "https://github.com/mmm1712/esp32-cam-ai-object-tracking/blob/main/arduino/esp32_cam_stream/camera_pins.h"
click node_capture "https://github.com/mmm1712/esp32-cam-ai-object-tracking/blob/main/python/capture_images.py"
click node_prepare "https://github.com/mmm1712/esp32-cam-ai-object-tracking/blob/main/python/prepare_dataset.py"
click node_tracking "https://github.com/mmm1712/esp32-cam-ai-object-tracking/blob/main/python/ai_tracking.py"
click node_yolo "https://github.com/mmm1712/esp32-cam-ai-object-tracking/blob/main/models/best.pt"
click node_second_esp "https://github.com/mmm1712/esp32-cam-ai-object-tracking/blob/main/arduino/servo_controller/servo_controller.ino"
click node_mount_source "https://github.com/mmm1712/esp32-cam-ai-object-tracking/blob/main/openscad/camera_mount_parts.scad"
click node_printed_parts "https://github.com/mmm1712/esp32-cam-ai-object-tracking/tree/main/stl"

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_camera,node_cam_setup,node_http_server,node_camera_ui,node_camera_pins,node_laptop,node_tracking,node_yolo toneBlue
class node_capture,node_raw_images,node_labels,node_prepare,node_dataset toneAmber
class node_second_esp,node_pca,node_servos toneMint
class node_mount_source,node_printed_parts toneRose
class node_operator toneIndigo
```

## Components

### Video and Tracking

- **ESP32-CAM**
- [Camera Startup](https://github.com/mmm1712/esp32-cam-ai-object-tracking/blob/main/arduino/esp32_cam_stream/esp32_cam_stream.ino): `arduino/esp32_cam_stream/esp32_cam_stream.ino`
- [Stream Server](https://github.com/mmm1712/esp32-cam-ai-object-tracking/blob/main/arduino/esp32_cam_stream/app_httpd.cpp): `arduino/esp32_cam_stream/app_httpd.cpp`
- [Camera UI Assets](https://github.com/mmm1712/esp32-cam-ai-object-tracking/blob/main/arduino/esp32_cam_stream/camera_index.h): `arduino/esp32_cam_stream/camera_index.h`
- [Camera Pin Map](https://github.com/mmm1712/esp32-cam-ai-object-tracking/blob/main/arduino/esp32_cam_stream/camera_pins.h): `arduino/esp32_cam_stream/camera_pins.h`
- **Laptop**
- [AI Tracking](https://github.com/mmm1712/esp32-cam-ai-object-tracking/blob/main/python/ai_tracking.py): `python/ai_tracking.py`
- [YOLO Model](https://github.com/mmm1712/esp32-cam-ai-object-tracking/blob/main/models/best.pt): `models/best.pt`

### Dataset Preparation

- [Image Capture](https://github.com/mmm1712/esp32-cam-ai-object-tracking/blob/main/python/capture_images.py): `python/capture_images.py`
- **Raw Images**
- **Target Labels**
- [Dataset Preparation](https://github.com/mmm1712/esp32-cam-ai-object-tracking/blob/main/python/prepare_dataset.py): `python/prepare_dataset.py`
- **YOLO Dataset**

### Motion Hardware

- [Second ESP32](https://github.com/mmm1712/esp32-cam-ai-object-tracking/blob/main/arduino/servo_controller/servo_controller.ino): `arduino/servo_controller/servo_controller.ino`
- **PCA9685 Driver**
- **Pan Tilt Servos**

### Mechanical Design

- [Mount Design](https://github.com/mmm1712/esp32-cam-ai-object-tracking/blob/main/openscad/camera_mount_parts.scad): `openscad/camera_mount_parts.scad`
- [Printed Parts](https://github.com/mmm1712/esp32-cam-ai-object-tracking/tree/main/stl): `stl`

### Other components

- **Operator**

## Connections

- Operator → Image Capture: captures images (evidence: `python/capture_images.py`)
- ESP32-CAM → Stream Server: supplies frames (evidence: `README.md`)
- Camera Startup → Stream Server: starts server
- Camera Startup → Camera Pin Map: configures pins
- Stream Server → Camera UI Assets: serves assets (evidence: `arduino/esp32_cam_stream/app_httpd.cpp`)
- Stream Server → Laptop: streams video (evidence: `README.md`)
- Laptop → Image Capture: runs capture (evidence: `README.md`)
- Image Capture → Raw Images: saves frames (evidence: `python/capture_images.py`)
- Operator → Target Labels: annotates images
- Raw Images → Dataset Preparation: provides images (evidence: `python/prepare_dataset.py`)
- Target Labels → Dataset Preparation: provides labels (evidence: `python/prepare_dataset.py`)
- Dataset Preparation → YOLO Dataset: writes dataset (evidence: `python/prepare_dataset.py`)
- Laptop → AI Tracking: runs tracking (evidence: `README.md`)
- Stream Server → AI Tracking: provides stream (evidence: `README.md`)
- YOLO Model → AI Tracking: loads model (evidence: `python/ai_tracking.py`)
- AI Tracking → Second ESP32: sends serial commands (evidence: `README.md`)
- Second ESP32 → PCA9685 Driver: controls over I2C (evidence: `README.md`)
- PCA9685 Driver → Pan Tilt Servos: drives servos (evidence: `README.md`)
- Mount Design → Printed Parts: defines parts (evidence: `README.md`)
