rust-road-traffic icon indicating copy to clipboard operation
rust-road-traffic copied to clipboard

Vehicle counting/tracking and speed estimation

W.I.P

Rust toy utility for monitoring road traffic

Table of Contents

  • W.I.P
  • Rust toy utility for monitoring road traffic
    • Table of Contents
    • About
    • Installation and usage
    • Screenshots
  • ROADMAP
    • Support

About

Vehicle detection/tracking and speed estimation via next instruments:

  1. Rust programming language - https://www.rust-lang.org/
  2. OpenCV bindings - https://github.com/twistedfall/opencv-rust#rust-opencv-bindings. I'm using OpenCV 4.7.0 + v0.66.0 for bindings
  3. Linear algebra - https://github.com/dimforge/nalgebra
  4. Traditional YOLO v3 / v4 / v7 via OpenCV's DNN module - https://arxiv.org/abs/1804.02767 / https://arxiv.org/abs/2004.10934 / https://arxiv.org/abs/2207.02696
  5. YOLO v8 via ONNX + OpenCV's DNN module - https://github.com/ultralytics/ultralytics
  6. actix-web for web part - https://actix.rs/

Notice:

UI is developed in seprate repository: https://github.com/LdDl/rust-road-traffic-ui. Prepared static directory after npm run build is here'

Screenshots

  • imshow() output:

    Legacy screenshots |
  • Web-UI for configuration:

Installation and usage

  1. You need installed Rust compiler obviously. Follow instruction of official site: https://www.rust-lang.org/tools/install

  2. You need installed OpenCV and its contributors modules. I'm using OpenCV 4.7.0. I'd highly recommend to use OpenCV with CUDA. Here is Makefile adopted from this one if you want build it from sources (it's targeted for Linux user obviously).

    sudo make install_cuda
    

    Be aware: OpenCV < 4.7.0 probably wont work with YOLOv8 (even with ONNX opset12) if you need those.

  3. OpenCV's bindings have already meant as dependencies in Cargo.toml

  4. Clone the repo

    git clone https://github.com/LdDl/rust-road-traffic.git
    

    Well, actually I provide yolov4-tiny configuration and weights file from official repository (authors of YOLOv4), but you are free to use yours. I provide video file as sample also.

  5. Сhange parameters for this utility by using template of configuration file. There is detailed explanation of each parameter.

  6. Download weights and configuration files (optional)

  7. Run

    cargo run path-to-toml-file
    

    If you want to use some Rust's optimizations then call build and run

    cargo build --release && ./target/release/rust-road-traffic path-to-toml-file
    

    If you want both optimized in term of perfomance and stripped executable binary (thanks to https://github.com/rust-lang/cargo/issues/3483)

    export RUSTFLAGS='-C link-arg=-s' && cargo build --release && ./target/release/rust-road-traffic path-to-toml-file
    

    If you want to do some REST calls you can do following (based on rest_api field in TOML configuration files)

    # Get polygons (GeoJSON) in which road traffic monitoring is requested
    curl -XGET 'http://localhost:42001/api/polygons/geojson'
    # Get statistics info for each polygon and each vehicle type in that polygon
    curl -XGET 'http://localhost:42001/api/stats/all'
    

    If you enabled MJPEG streaming and you want to adjust parameters for velocity estimation you could open http://localhost:42001/ in your browser and adjust polygons as you need (this UI still needs to be debugged and polished):

ROADMAP

Please see this file

Support

If you have troubles or questions please open an issue.