8000 GitHub - avrtt/traffic-observer: Real-time traffic analysis, a small yet tricky pet project
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

avrtt/traffic-observer

Repository files navigation

This project implements a complete traffic analysis system for roundabouts using SOTA computer vision techniques. It supports real-time processing from multiple cameras, integration with Kafka for messaging, InfluxDB for time series storage and Grafana for interactive dashboards.

The project was done for educational purposes as part of my learning of advanced computer vision practices. It's basically a revision of this project by Dmitry Kolesnikov with some cuts and minor improvements. Please refer to the original repository for more details, and star the original author.

Features

  • Real-time Video Processing: Processes RTSP streams or local MP4 files.
  • Vehicle Detection & Tracking: Uses detection and tracking nodes to count vehicles and update track information.
  • Traffic Statistics Calculation: Computes per-road vehicle count and intensity (vehicles per minute).
  • Message Brokering: Publishes analytics to Kafka topics.
  • Time-Series Storage: Uses InfluxDB (with Telegraf) for storing real-time statistics.
  • Dashboard Visualization: Displays analytics in Grafana dashboards.
  • Multiprocessing Optimized Mode: Option to run the analysis in parallel to achieve high frame rates.
  • Flask Server: Provides a web interface to view processed video streams.
  • Dockerized Environment: Easily deploy all components with Docker Compose.

Installation

Clone & navigate:

git clone git@github.com:avrtt/traffic-observer.git && cd traffic-observer

Configure environment variables. In the root directory, create a file named .env with the following content (adjust credentials as needed):

INFLUXDB_ADMIN_USER=admin
INFLUXDB_ADMIN_PASSWORD=admin
GRAFANA_ADMIN_USER=admin
GRAFANA_ADMIN_PASSWORD=admin
KAFKA_USERNAME=traffic
KAFKA_PASSWORD=traffic-secret

Running with Docker Compose

Build and start the entire system using:

docker compose -p traffic_observer up -d --build

After startup, access the Grafana dashboard at http://localhost:3111 using the credentials provided in your .env file.

Running locally w/o Docker

Install dependencies. Make sure you have Python 3.9+ installed and then run:

python -m pip install --upgrade pip
pip install -r requirements.txt

For the basic processing pipeline, run:

python -m src.main --send-kafka false

For the optimized multiprocessing version:

python -m src.main_optimized --send-kafka false

Open your browser and go to http://127.0.0.1:8100 to view the processed video stream if the Flask server is enabled.

Architecture

The project architecture is modular. The main processing pipeline is as follows:

graph TD;
    A["VideoReader<br/>(reads frames from video/stream)"] --> B["Detection & Tracking<br/>(detects vehicles and tracks them)"];
    B --> C["Tracker Update<br/>(updates active tracks)"];
    C --> D["Statistics Calculator<br/>(computes road occupancy and flow)"];
    D --send-to-kafka==False--> F["Visualizer<br/>(displays results)"];
    D --send-to-kafka==True--> E["Kafka Producer<br/>(publishes analytics)"];
    E --> F;
    F --save-video==True--> H["Video Saver<br/>(saves processed frames)"];
    F --web-stream==True--> L["Flask Server<br/>(streams video via web)"];
    H --web-stream==True--> L;
Loading

Key components

  1. VideoReader: Reads frames from a video file or RTSP stream.
  2. Detection & Tracking: Detects vehicles and maintains track IDs.
  3. Tracker Update: Updates vehicle track information.
  4. Statistics Calculator: Calculates traffic statistics (e.g., vehicles per minute).
  5. Kafka Producer: Sends analytics to Kafka.
  6. Visualizer: Displays real-time results with overlays.
  7. Video Saver: Optionally saves processed video.
  8. Flask Server: Provides a web endpoint to view the output.

For detailed explanations and tutorials, please refer to the original repository.

License

MIT.

0