Skip to content

Traffic Monitor built with edge ML for object detection and radar for speed monitoring

License

Notifications You must be signed in to change notification settings

glossyio/traffic-monitor

Repository files navigation

Traffic Monitor

GitHub Release GitHub License Static Badge

The Traffic Monitor is an open source smart city traffic monitoring software built with commodity hardware to capture holistic roadway usage. Utilizing edge machine learning object detection and Doppler radar, it counts pedestrians, bicycles, and cars and measures vehicle speeds.

Traffic Monitor Roadway Graphic

Highlights and capabilities

  • 🧮 Reporting roadway utilization - counting cars 🚗, bicycles 🚲, pedestrians 🚶, and more! 🐕🐈🏍️🚜
  • 🚨 Capturing roadway users' speeds - measuring speeds, capturing image and video of event.
  • 📷 Privacy-focused, local inferencing (no cloud required) only collects and sends data you specify.
  • 🐘 Permanent, long-term deployment on roadways to monitor roadway usage.
  • 🐜 Temporary, remote deployments utilizing the low-power footprint and batteries.
  • 💡 Extensible with any Raspberry Pi-compatible senosrs and components; e.g. Air Quality sensor for analog gas: RED, OX, NH3, noise, light, proximity, temperature, pressure, humidty and Particulate Matter (PM 5, 2.5, 1).

Documentation 📚

Coming soon.

Build your own device (DIY) 🧑‍🔬

Getting Started

  1. Assemble your device (see hardware components ⚒️).
  2. Install Raspberry Pi OS (Full Install) Bookworm (latest).
    • Full Install required for all components to run properly. Lite is missing H.264 codec for libcamera.
    • Recommend to Install using Imager instructions and follow the OS customization to set up your Wi-Fi credentials and username and password to access the device headless (no monitor or keyboard).
  3. Insert the microSD card and start your device
    • First boot may take a few minutes before it is fully online
  4. Remotely access your device (recommend using SSH) and login to your Raspberry Pi
    • Recommend use IP Address in case your router doesn't recognize the hostname you set during setup.
  5. Run git clone https://github.com/glossyio/traffic-monitor into your home folder (or any folder)
  6. Run cd traffic-monitor
  7. Run sudo chmod +x script/* to enable scripts
  8. Run ./script/bootstrap to fulfill dependencies. Note: System will reboot after this script.
  9. After reboot, log into the device and cd traffic-monitor to continue.
  10. Run ./script/setup to set up project in an initial state
  11. Run ./script/server to start the application
    • ./script/update is not required on initial setup but may be used if you change Docker configurations. This does not yet automatically update the traffic monitor.
  12. Access the application at the following URLs (check container status with docker ps):
    1. http://<device_ip_address>:1880/ui is your primary device dashboard, use it to ensure it is capturing events (Node-Red dashboard)
    2. http://<device_ip_address>:5000 to view the Frigate interface and make any configuration changes specific to your deployment
  13. Mount your device in a place it can capture the entire roadway in the mounting guide (coming soon).
  14. Configure your device
  15. Start capturing roadway usage data!

Hardware Components 🛠️

This setup uses commidity, consumer hardware to enable object detection and speed/direction measurement:

We are not affiliated with any of the stores or companies linked in this section. These are just suggestions that have been used or tested. If you have used or tested more, submit a PR to add them!

Configuration ✅

Access configuration at http://<device_ip_address>:1880/ui > Configuration/Setup Tab

  1. Set up Frigate zones by entering the Frigate UI at http://<device_ip_address>:5000, clicking the primary camera, selecting Debug > Show Options > Mask & Zone creator. For dashboard and data capture to work properly, you should set up the following 4 named zones:
    1. zone_capture - Set to capture the entire roadway, including sidewalks that are clearly in view for counting objects through them. Avoid edges where poles and trees may occlude a clear view of objects.
    2. zone_far - Paired with zone_near, this will determine if an object moves "outbound" or "inbound". Set this to be roughly the further half of the zone_capture region.
    3. zone_near - Paired with zone_far, this will determine if an object moves "outbound" or "inbound". Set this to be roughly the closer half of the zone_capture region.
    4. zone_radar - This should correspond to the field of view for the radar (where it can pick up accurate measurements) on the street. It will roughly make a rectangle in the center of the camera field of view from curb to curb.
  2. Set up the deployment location at at http://<device_ip_address>:1880/ui > Configuration/Setup Tab > Deployment Location Entry Details

User Interfaces (UI) / port numbers references 🖥️

  • http://<device_ip_address>:1880/ui is the Node-RED dashboard and your primary device dashboard, use it to ensure it is capturing events, see the latest events, and see summarized stats.
  • http://<device_ip_address>:5000 to view the Frigate interface and make any configuration changes specific to your deployment
  • http://<device_ip_address>:1984 shows the go2rtc configured camera settings on the Raspberri Pi. Use this if your cameras are giving errors in Frigate.
  • http://<device_ip_address>:1880 is the Node-RED flow editor used to develop the logic to connect events to speeds, create event records, capture radar readings, and more. This is primarily used by developers. The default admin login is admin/password.

Troubleshooting ⚠️

More documentation coming soon.

If the Frigate camera shows nothing, check the configuration, review the Frigate Camera Setup documentation.

  • In Frigate --> Configuration Editor:
    • Enable camera(s) (cameras --> enabled: True)
    • Enable detection (detect --> enabled: True)

Screenshots

Device dashboard available at http://<device_ip_address>:1880/ui.

Cumulative events by object for the day (resets daily). events-counts-daily

Last 5 events detected and confirmed by radar. events-zone_radar-last5

Car object speed statistics for the day (resets daily). event-car-speed-stats-daily

Hourly events count by object for the last 24-hours. events-hourly-24-hours

Daily events count by object for the last 10-days. events-daily-10-day

Dashboard sample, using the granular backend data dashboard-sample