# bamwani/car-counting-and-speed-estimation-yolo-sort-python architecture

> Architecture diagram of the GitHub repository bamwani/car-counting-and-speed-estimation-yolo-sort-python, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bamwani/car-counting-and-speed-estimation-yolo-sort-python
- Repository: https://github.com/bamwani/car-counting-and-speed-estimation-yolo-sort-python

## Overview

This repository is a video-based traffic analysis application. A user supplies a video and YOLO model directory; the main script detects vehicles, tracks them across frames, derives lane and speed information, annotates the frames, and exports results. The README documents vehicle counting, lane segmentation, lane-change detection, speed estimation, and CSV output. The sampled code confirms the SORT implementation and CSV write; some internal stages are documented but their complete implementation was not sampled.

Main entry points: [`code_and_output/main.py`](https://github.com/bamwani/car-counting-and-speed-estimation-yolo-sort-python/blob/master/code_and_output/main.py) (Video processor), [`code_and_output/sort.py`](https://github.com/bamwani/car-counting-and-speed-estimation-yolo-sort-python/blob/master/code_and_output/sort.py) (SORT tracking), [`code_and_output/final.csv`](https://github.com/bamwani/car-counting-and-speed-estimation-yolo-sort-python/blob/master/code_and_output/final.csv) (Analysis CSV), [`yolo/yolov3.cfg`](https://github.com/bamwani/car-counting-and-speed-estimation-yolo-sort-python/blob/master/yolo/yolov3.cfg) (YOLO configuration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Video Input"]
  node_main["Video processor<br/>[main.py]"]
end

subgraph group_analysis["Vehicle Analysis"]
  node_vehicle_detection["YOLO detection<br/>[main.py]"]
  node_vehicle_tracking["SORT tracking<br/>[sort.py]"]
  node_vehicle_counting["Vehicle counting<br/>[main.py]"]
  node_lane_segmentation["Lane segmentation<br/>[main.py]"]
  node_lane_change["Lane changes<br/>[main.py]"]
  node_speed_estimation["Speed estimation<br/>[main.py]"]
end

subgraph group_results["Outputs"]
  node_frame_annotation["Frame annotation<br/>[main.py]"]
  node_video_output["Annotated video"]
  node_csv_output["Analysis CSV<br/>[final.csv]"]
end

subgraph group_model["Model Resources"]
  node_yolo_config["YOLO configuration<br/>[yolov3.cfg]"]
  node_class_labels["COCO labels<br/>[coco.names]"]
end

node_user(("Video analyst"))

node_user -->|"runs with video"| node_main
node_main -->|"detects vehicles"| node_vehicle_detection
node_main -->|"uses tracker"| node_vehicle_tracking
node_main -->|"counts vehicles"| node_vehicle_counting
node_main -->|"segments lanes"| node_lane_segmentation
node_main -->|"detects changes"| node_lane_change
node_main -->|"estimates speed"| node_speed_estimation
node_main -.->|"annotates frames"| node_frame_annotation
node_main -->|"writes video"| node_video_output
node_main -->|"writes CSV"| node_csv_output
node_main -->|"loads model config"| node_yolo_config
node_main -.->|"uses class labels"| node_class_labels

click node_main "https://github.com/bamwani/car-counting-and-speed-estimation-yolo-sort-python/blob/master/code_and_output/main.py"
click node_vehicle_detection "https://github.com/bamwani/car-counting-and-speed-estimation-yolo-sort-python/blob/master/code_and_output/main.py"
click node_vehicle_tracking "https://github.com/bamwani/car-counting-and-speed-estimation-yolo-sort-python/blob/master/code_and_output/sort.py"
click node_vehicle_counting "https://github.com/bamwani/car-counting-and-speed-estimation-yolo-sort-python/blob/master/code_and_output/main.py"
click node_lane_segmentation "https://github.com/bamwani/car-counting-and-speed-estimation-yolo-sort-python/blob/master/code_and_output/main.py"
click node_lane_change "https://github.com/bamwani/car-counting-and-speed-estimation-yolo-sort-python/blob/master/code_and_output/main.py"
click node_speed_estimation "https://github.com/bamwani/car-counting-and-speed-estimation-yolo-sort-python/blob/master/code_and_output/main.py"
click node_frame_annotation "https://github.com/bamwani/car-counting-and-speed-estimation-yolo-sort-python/blob/master/code_and_output/main.py"
click node_csv_output "https://github.com/bamwani/car-counting-and-speed-estimation-yolo-sort-python/blob/master/code_and_output/final.csv"
click node_yolo_config "https://github.com/bamwani/car-counting-and-speed-estimation-yolo-sort-python/blob/master/yolo/yolov3.cfg"
click node_class_labels "https://github.com/bamwani/car-counting-and-speed-estimation-yolo-sort-python/blob/master/yolo/coco.names"

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_main toneBlue
class node_vehicle_detection,node_vehicle_tracking,node_vehicle_counting,node_lane_segmentation,node_lane_change,node_speed_estimation toneAmber
class node_frame_annotation,node_video_output,node_csv_output toneMint
class node_yolo_config,node_class_labels toneRose
class node_user toneIndigo
```

## Components

### Video Input

- [Video processor](https://github.com/bamwani/car-counting-and-speed-estimation-yolo-sort-python/blob/master/code_and_output/main.py): `code_and_output/main.py`

### Vehicle Analysis

- [YOLO detection](https://github.com/bamwani/car-counting-and-speed-estimation-yolo-sort-python/blob/master/code_and_output/main.py): `code_and_output/main.py`
- [SORT tracking](https://github.com/bamwani/car-counting-and-speed-estimation-yolo-sort-python/blob/master/code_and_output/sort.py): `code_and_output/sort.py`
- [Vehicle counting](https://github.com/bamwani/car-counting-and-speed-estimation-yolo-sort-python/blob/master/code_and_output/main.py): `code_and_output/main.py`
- [Lane segmentation](https://github.com/bamwani/car-counting-and-speed-estimation-yolo-sort-python/blob/master/code_and_output/main.py): `code_and_output/main.py`
- [Lane changes](https://github.com/bamwani/car-counting-and-speed-estimation-yolo-sort-python/blob/master/code_and_output/main.py): `code_and_output/main.py`
- [Speed estimation](https://github.com/bamwani/car-counting-and-speed-estimation-yolo-sort-python/blob/master/code_and_output/main.py): `code_and_output/main.py`

### Outputs

- [Frame annotation](https://github.com/bamwani/car-counting-and-speed-estimation-yolo-sort-python/blob/master/code_and_output/main.py): `code_and_output/main.py`
- **Annotated video**
- [Analysis CSV](https://github.com/bamwani/car-counting-and-speed-estimation-yolo-sort-python/blob/master/code_and_output/final.csv): `code_and_output/final.csv`

### Model Resources

- [YOLO configuration](https://github.com/bamwani/car-counting-and-speed-estimation-yolo-sort-python/blob/master/yolo/yolov3.cfg): `yolo/yolov3.cfg`
- [COCO labels](https://github.com/bamwani/car-counting-and-speed-estimation-yolo-sort-python/blob/master/yolo/coco.names): `yolo/coco.names`

### Other components

- **Video analyst**

## Connections

- Video analyst → Video processor: runs with video (evidence: `README.md`)
- Video processor → YOLO detection: detects vehicles (evidence: `README.md`)
- Video processor → SORT tracking: uses tracker (evidence: `README.md`)
- Video processor → Vehicle counting: counts vehicles (evidence: `README.md`)
- Video processor → Lane segmentation: segments lanes (evidence: `README.md`)
- Video processor → Lane changes: detects changes (evidence: `README.md`)
- Video processor → Speed estimation: estimates speed (evidence: `README.md`)
- Video processor → Frame annotation: annotates frames (evidence: `code_and_output/main.py`)
- Video processor → Annotated video: writes video (evidence: `README.md`)
- Video processor → Analysis CSV: writes CSV (evidence: `code_and_output/main.py`)
- Video processor → YOLO configuration: loads model config (evidence: `README.md`)
- Video processor → COCO labels: uses class labels
