Code Monkey home page Code Monkey logo

open-traffic-detector's Introduction




About

This repository contains the Open Traffic Detector source code. It is a simple Python solution to track, count and estimate the speed, direction and classes of vehicles. Its main objective is to gather real-time data about traffic behaviour.

Introduction

Open Traffic Detector (OTD) is a use case for edge computing applications. It is meant to run in a Raspberry Pi 4B alongside the Coral USB accelerator to perform almost real-time vehicle detection and tracking. It is designed for general tracking applications so it can be adapted to track other types of objects by fine-tunning or modifying the detector model. It uses the TensorFlow Lite library, a lightweight implementation of TensorFlow that achieves faster inference time and require less processing power. On the other hand, OpenCV is used for video processing as well as estimating the speed and direction of vehicles based on the same technique employed by VASCAR systems. This means that certain points in the image are used as references points to measure a vehicle position at a certain time to perform different calculations.


Built with

Installation

Hardware Requirements

As previously mentioned, OTD has been designed to run in edge computing devices. It has been successfully tested with the following hardware:

  1. Ideally the Raspberry Pi Model 4B. Previous versions can also be used at some performance cost.
  2. Coral USB Accelerator. This is not really mandatory but highly recommended for real-time detections.
  3. A video source. This software was tested using a RTSP connection from a wireless security camera but the Raspberry Pi Camera or other USB camera can also be used.

Dependencies

OTD has been designed in Python 3, so it has to be install in your system as well as the pip packet manager. After that, installation of required system packages can continue.

First, Numpy software package has to be installed.

$ apt-get install python3-numpy

After that OpenCV package must be installed using the following command:

$ apt-get install python3-opencv

The Eclipse Paho MQTT client library is also required to publish generated data to a server.

$ pip3 install paho-mqtt

At this point, the TensorFlow Lite runtime has to be installed as per the Python Quickstart. Assuming you are running Debian Linux on a Raspberry Pi, then a new package repository has to be added and then install as follows:

$ echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list
$ curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
$ sudo apt-get update
$ sudo apt-get install python3-tflite-runtime

NOTE: In the near future this application will be dockerized to ease the installation process.

How to use

To setup this software correctly a config.yml file is included which is shown below. You should modify it to meet your needs.

input:
    source:             # This can be a video path, a RTSP server IP or USB port number in case of a webcam.
    model:              # Path to the .tflite data model.
    labels:             # Labels file path.
detector:
    threshold: 0.5      # TensorFlow accuracy threshold. Detections below this value will not be considered.
tracker:
    max_age: 3          # Count of frames that need to pass for each track to be considered as lost.
    min_hits: 5         # Minimum amount of detections required for a track to be assigned.
    iou_threshold: 0.3  # Intersection over Union used by the SORT library.
result:
    output: true        # Show OpenCV video output. Boolean.
    logs:               # Folder to save log files to.
    verbose:            # Verbose terminal output. Boolean.
mqtt:
    broker:             # MQTT broker IP.
    port:               # Broker port number.
    topic:              # Topic to publish to.

Once the configuration file is completed, simply run it like every other Python script:

$ python3 open-traffic-detector.py

A sample terminal output for the video included in this files is shown below:

user@computer:~$ python3 open-traffic-detector.py
[INFO]    The following file has been created.: ./logs/12-05-2021-21-03-20.csv
[WARNING] Could not connect to MQTT server.
[INFO]    Object class: 2
[INFO]    Direction: <-----
[INFO]    Speed: 31.76 km/h
[INFO]    Counted objects: 1
[INFO]    Object class: 2
[INFO]    Direction: ----->
[INFO]    Speed: 43.22 km/h
[INFO]    Counted objects: 1
[INFO]    Exiting gracefully. Bye!

Acknowledgements

open-traffic-detector's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

ivancf kailushan

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.