# mzgl222/traffic-threat-detection-msc architecture

> Architecture diagram of the GitHub repository mzgl222/traffic-threat-detection-msc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mzgl222/traffic-threat-detection-msc
- Repository: https://github.com/mzgl222/traffic-threat-detection-msc

## Overview

This repository is a video-based traffic-safety analysis application. Its main workflow processes video frames into tracked objects, derives world positions, zones, motion and crossing-risk metrics, evaluates pedestrian–vehicle risk, and writes tabular results. The source also includes standalone track, risk-event, risk-timeline, homography-point and VQA-to-CSV tools. The README provides no further capability detail; relationships for the sampled pipeline are grounded in its source, while some runner wiring is only partially excerpted.

Main entry points: [`traffic_safety/pipeline.py`](https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/traffic_safety/pipeline.py) (Frame pipeline), [`run.py`](https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/run.py) (Frame runner), [`traffic_safety/detector.py`](https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/traffic_safety/detector.py) (Detection and tracking), [`traffic_safety/homography.py`](https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/traffic_safety/homography.py) (World calibration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Video processing"]
  node_runner["Frame runner<br/>[run.py]"]
  node_pipeline["Frame pipeline<br/>[pipeline.py]"]
end

subgraph group_analysis["Object analysis"]
  node_tracker["Detection and tracking<br/>[detector.py]"]
  node_homography["World calibration<br/>[homography.py]"]
  node_zones["Zone classification<br/>[zones.py]"]
  node_trajectory["Track histories<br/>[trajectory.py]"]
  node_speed["Speed estimation<br/>[speed.py]"]
  node_state["Object state<br/>[state.py]"]
end

subgraph group_risk["Safety assessment"]
  node_riskmetrics["Crosswalk metrics<br/>[risk_metrics.py]"]
  node_rules["Safety rules<br/>[safety_rules.py]"]
end

subgraph group_outputs["Results and tools"]
  node_objectcsv["Object results CSV<br/>[csv_writer.py]"]
  node_eventcsv["Risk events CSV"]
  node_timelinecsv["Risk timeline CSV"]
  node_trackanalysis["Track analysis<br/>[analyze_tracks.py]"]
  node_eventanalysis["Risk event analysis"]
  node_timelineanalysis["Risk timeline analysis"]
  node_calibrationtool["Calibration point tool"]
  node_vqatool["VQA CSV conversion<br/>[vqa2csv.py]"]
end

node_operator(("Operator"))
node_video["Input video"]
node_outputvideo["Annotated video"]

node_operator -->|"starts"| node_runner
node_video -->|"provides frames"| node_runner
node_runner -->|"processes frames"| node_pipeline
node_pipeline -->|"tracks objects"| node_tracker
node_pipeline -->|"projects positions"| node_homography
node_pipeline -->|"classifies zones"| node_zones
node_pipeline -->|"updates histories"| node_trajectory
node_pipeline -->|"estimates speed"| node_speed
node_pipeline -->|"estimates state"| node_state
node_pipeline -->|"estimates TTC"| node_riskmetrics
node_runner -->|"evaluates objects"| node_rules
node_runner -->|"writes objects"| node_objectcsv
node_runner -->|"writes events"| node_eventcsv
node_runner -.->|"configures output"| node_timelinecsv
node_runner -->|"renders video"| node_outputvideo
node_operator -.->|"runs analysis"| node_trackanalysis
node_operator -.->|"runs analysis"| node_eventanalysis
node_operator -.->|"runs analysis"| node_timelineanalysis
node_operator -.->|"selects points"| node_calibrationtool
node_operator -.->|"converts data"| node_vqatool

click node_runner "https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/run.py"
click node_pipeline "https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/traffic_safety/pipeline.py"
click node_tracker "https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/traffic_safety/detector.py"
click node_homography "https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/traffic_safety/homography.py"
click node_zones "https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/traffic_safety/zones.py"
click node_trajectory "https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/traffic_safety/trajectory.py"
click node_speed "https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/traffic_safety/speed.py"
click node_state "https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/traffic_safety/state.py"
click node_riskmetrics "https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/traffic_safety/risk_metrics.py"
click node_rules "https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/traffic_safety/safety_rules.py"
click node_objectcsv "https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/traffic_safety/csv_writer.py"
click node_eventcsv "https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/traffic_safety/risk_event_writer.py"
click node_timelinecsv "https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/traffic_safety/risk_timeline_writer.py"
click node_trackanalysis "https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/scripts/analyze_tracks.py"
click node_eventanalysis "https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/scripts/analyze_risk_events.py"
click node_timelineanalysis "https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/scripts/analyze_risk_timeline.py"
click node_calibrationtool "https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/scripts/select_homography_points.py"
click node_vqatool "https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/scripts/vqa2csv.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_runner,node_pipeline toneBlue
class node_tracker,node_homography,node_zones,node_trajectory,node_speed,node_state toneAmber
class node_riskmetrics,node_rules toneMint
class node_objectcsv,node_eventcsv,node_timelinecsv,node_trackanalysis,node_eventanalysis,node_timelineanalysis,node_calibrationtool,node_vqatool toneRose
class node_operator,node_video,node_outputvideo toneIndigo
```

## Components

### Video processing

- [Frame runner](https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/run.py): `run.py`
- [Frame pipeline](https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/traffic_safety/pipeline.py): `traffic_safety/pipeline.py`

### Object analysis

- [Detection and tracking](https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/traffic_safety/detector.py): `traffic_safety/detector.py`
- [World calibration](https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/traffic_safety/homography.py): `traffic_safety/homography.py`
- [Zone classification](https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/traffic_safety/zones.py): `traffic_safety/zones.py`
- [Track histories](https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/traffic_safety/trajectory.py): `traffic_safety/trajectory.py`
- [Speed estimation](https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/traffic_safety/speed.py): `traffic_safety/speed.py`
- [Object state](https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/traffic_safety/state.py): `traffic_safety/state.py`

### Safety assessment

- [Crosswalk metrics](https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/traffic_safety/risk_metrics.py): `traffic_safety/risk_metrics.py`
- [Safety rules](https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/traffic_safety/safety_rules.py): `traffic_safety/safety_rules.py`

### Results and tools

- [Object results CSV](https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/traffic_safety/csv_writer.py): `traffic_safety/csv_writer.py`
- [Risk events CSV](https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/traffic_safety/risk_event_writer.py): `traffic_safety/risk_event_writer.py`
- [Risk timeline CSV](https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/traffic_safety/risk_timeline_writer.py): `traffic_safety/risk_timeline_writer.py`
- [Track analysis](https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/scripts/analyze_tracks.py): `scripts/analyze_tracks.py`
- [Risk event analysis](https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/scripts/analyze_risk_events.py): `scripts/analyze_risk_events.py`
- [Risk timeline analysis](https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/scripts/analyze_risk_timeline.py): `scripts/analyze_risk_timeline.py`
- [Calibration point tool](https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/scripts/select_homography_points.py): `scripts/select_homography_points.py`
- [VQA CSV conversion](https://github.com/mzgl222/traffic-threat-detection-msc/blob/main/scripts/vqa2csv.py): `scripts/vqa2csv.py`

### Other components

- **Operator**
- **Input video**
- **Annotated video**

## Connections

- Operator → Frame runner: starts (evidence: `run.py`)
- Input video → Frame runner: provides frames (evidence: `run.py`)
- Frame runner → Frame pipeline: processes frames (evidence: `run.py`)
- Frame pipeline → Detection and tracking: tracks objects (evidence: `traffic_safety/pipeline.py`)
- Frame pipeline → World calibration: projects positions (evidence: `traffic_safety/pipeline.py`)
- Frame pipeline → Zone classification: classifies zones (evidence: `traffic_safety/pipeline.py`)
- Frame pipeline → Track histories: updates histories (evidence: `traffic_safety/pipeline.py`)
- Frame pipeline → Speed estimation: estimates speed (evidence: `traffic_safety/pipeline.py`)
- Frame pipeline → Object state: estimates state (evidence: `traffic_safety/pipeline.py`)
- Frame pipeline → Crosswalk metrics: estimates TTC (evidence: `traffic_safety/pipeline.py`)
- Frame runner → Safety rules: evaluates objects (evidence: `run.py`)
- Frame runner → Object results CSV: writes objects (evidence: `run.py`)
- Frame runner → Risk events CSV: writes events (evidence: `run.py`)
- Frame runner → Risk timeline CSV: configures output (evidence: `run.py`)
- Frame runner → Annotated video: renders video (evidence: `run.py`)
- Operator → Track analysis: runs analysis
- Operator → Risk event analysis: runs analysis
- Operator → Risk timeline analysis: runs analysis
- Operator → Calibration point tool: selects points
- Operator → VQA CSV conversion: converts data
