rust-road-traffic
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:
- Rust programming language - https://www.rust-lang.org/
- OpenCV bindings - https://github.com/twistedfall/opencv-rust#rust-opencv-bindings. I'm using OpenCV 4.7.0 + v0.66.0 for bindings
- Linear algebra - https://github.com/dimforge/nalgebra
- 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
- YOLO v8 via ONNX + OpenCV's DNN module - https://github.com/ultralytics/ultralytics
- 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
-
You need installed Rust compiler obviously. Follow instruction of official site: https://www.rust-lang.org/tools/install
-
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.
-
OpenCV's bindings have already meant as dependencies in Cargo.toml
-
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.
-
Сhange parameters for this utility by using template of configuration file. There is detailed explanation of each parameter.
-
Download weights and configuration files (optional)
-
YOLO v4 tiny - yolov4-tiny-vehicles-rect_best.weights + yolov4-tiny-vehicles-rect.cfg. It has been trained on filtered COCO dataset; classes are: "car", "motorbike", "bus", "train", "truck"
-
YOLO v3 tiny - tinyv3-vehicles_best.weights + tinyv3-vehicles.cfg. It has been trained on AIC HCMC 2020 challenge data; classes are: "car", "motorbike", "bus", "truck". More information here: https://github.com/LdDl/yolo_vehicles . I like it more personally.
-
-
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.