This sample project focuses on "Vechicle Detection, Tracking and Counting" using TensorFlow Object Counting API.
The TensorFlow Object Counting API is used as a base for object counting on this project, more info can be found on this repo.
The developing is on progress! This sample project will be updated soon, the more talented traffic analyzer app will be available in this repo!
This sample project has more than just counting vehicles, here are the additional capabilities of it;
- Recognition of approximate vehicle color
- Detection of vehicle's direction of travel
- Prediction the speed of the vehicle
- Prediction of approximate vehicle size
- The images of detected vehicles are cropped from video frame and they are saved as new images under "detected_vehicles" folder path
- The program gives a .csv file as an output (traffic_measurement.csv) which includes "Vehicle Type/Size", " Vehicle Color", " Vehicle Movement Direction", " Vehicle Speed (km/h)" rows, after the end of the process for the source video file.
The input video can be accessible by this link.
- Vehicle detection and classification have been developed using TensorFlow Object Detection API, see for more info.
- Vehicle speed prediction has been developed using OpenCV via image pixel manipulation and calculation, see for more info.
- Vehicle color prediction has been developed using OpenCV via K-Nearest Neighbors Machine Learning Classification Algorithm is Trained Color Histogram Features, see for more info.
TensorFlow™ is an open source software library for numerical computation using data flow graphs. Nodes in the graph represent mathematical operations, while the graph edges represent the multidimensional data arrays (tensors) communicated between them.
OpenCV (Open Source Computer Vision Library) is an open source computer vision and machine learning software library. OpenCV was built to provide a common infrastructure for computer vision applications and to accelerate the use of machine perception in the commercial products.
Source video is read frame by frame with OpenCV. Each frames is processed by "SSD with Mobilenet" model is developed on TensorFlow. This is a loop that continue working till reaching end of the video. The main pipeline of the tracker is given at the above Figure.
By default I use an "SSD with Mobilenet" model in this project. You can find more information about SSD in here. See the detection model zoo for a list of other models that can be run out-of-the-box with varying speeds and accuracies.
Demo video of the project is available on My YouTube Channel.
1.) Python and pip
Python is automatically installed on Ubuntu. Take a moment to confirm (by issuing a python -V command) that one of the following Python versions is already installed on your system:
- Python 3.3+
The pip or pip3 package manager is usually installed on Ubuntu. Take a moment to confirm (by issuing a pip -V or pip3 -V command) that pip or pip3 is installed. We strongly recommend version 8.1 or higher of pip or pip3. If Version 8.1 or later is not installed, issue the following command, which will either install or upgrade to the latest pip version:
$ sudo apt-get install python3-pip python3-dev # for Python 3.n
2.) OpenCV
See required commands to install OpenCV on Ubuntu in here.
3.) TensorFlow
Install TensorFlow by invoking one of the following commands:
$ pip3 install tensorflow # Python 3.n; CPU support (no GPU support)
$ pip3 install tensorflow-gpu # Python 3.n; GPU support
4.) TensorFlow Object Detection API
See required commands to install TensorFlow Object Detection API on Ubuntu in here.
If you are still getting problem about installation after completed the installation of the packet that are given above, please check that link out to get detailed info about installation.
-
After completing these 4 installation steps that are given at above, you can test the project by this command:
python3 vehicle_detection_main.py
This system is available under the MIT license. See the LICENSE file for more info.