Skip to content

onurrtosunn/Rtsp_Dynamic_Lanes_Traffic_Analytics

Repository files navigation

Real-time RTSP-based dynamic traffic analytics service

Real-time RTSP-based traffic analytics service that detects vehicles, performs lane-level counting, identifies stopped and wrong-way vehicles, provides a REST API for dynamic configuration of lanes/counting regions and camera sources with immediate on-stream updates, converts uploaded videos to RTSP for analysis, emits per-minute counts and instant alarms to an external service, and is designed to support parallel stream analysis.

Create RTSP Stream

./rtsp-simple-server
ffmpeg -re -stream_loop -1 -i Traffic.mp4 -c:v libx264 -preset ultrafast -tune zerolatency -g 30 -keyint_min 30 -f rtsp -rtsp_transport tcp rtsp://localhost:9090/mystream

Run Python Files

Firtly run flask_api.py and than run vehicle_counter.py.

python3 flask_api.py
python3 vehicle_counter.py

Default configurations are specified in flask_api.py. if you want to make changes with config you can use the following command

To change lanes information

curl -X PUT http://127.0.0.1:5001/update_config  -H "Content-Type: application/json"  -d '{"lane_index": {selected_lane}, "key": "{selected_line}", "value": [{x_value}, {y_value}]}'

For example

curl -X PUT http://127.0.0.1:5001/update_config  -H "Content-Type: application/json"  -d '{"lane_index": 5, "key": "line_1_start", "value": [830, 446]}'

To change rtsp source

curl -X PUT http://127.0.0.1:5001/update_video_url -H "Content-Type: application/json" -d '{"new_url":"{new_rtsp stream or video path}"}'

For example

curl -X PUT http://127.0.0.1:5001/update_video_url -H "Content-Type: application/json" -d '{"new_url":"rtsp://localhost:9090/mystream"}'

RTSP open ports

  • [RTSP] UDP/RTP listener opened on :8000

  • [RTSP] UDP/RTCP listener opened on :8001

  • [RTSP] TCP listener opened on :9090

  • [RTMP] listener opened on :1935

  • [HLS] listener opened on :8888

Notes

  • Stopped objects are coloured with a red rectangle and a threshold value is used to prevent false positives.
  • createBackgroundSubtractorMOG2 algorithm is used to detect non-moving objects
  • Sort algorith is used to track each objecet
  • Vehicle counts, stops and wrong-way vehicle information are sent immediately to the endpoint.
  • A demo version of the video has been uploaded to github repo
  • Parallel stream analysis is not supported by the code.

Docker

docker run --rm --name ayvos -it -p 9090:9090 -p 8555:8555 -p 8000:8000/udp -p 8001:8001/udp -p 1935:1935 -p 8888:8888 -w /Ayvos/ -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix onurrtosunn/ayvos_case_study:v1

Screenshots

image image

Reference

https://github.com/bluenviron/mediamtx

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages