A computer vision based vehicle detection and counting system – AI Project

In many cities around the world, traffic issues are an important concern. The traffic problem has many big causes. Due to better health care, better education, better job opportunities, and well-built houses people migrate from rural to urban areas. And the number of residents moving to urban areas has increased dramatically, resulting in a drastic rise in the number of vehicles. Due to increasing the number of residents, the capacity of the roadway has become inadequate and has grown relatively slow. In large cities, this causes roads and the number of vehicles to be imbalanced which results in road congestion. Similarly, public transportation causes the same problem. Another factor, due to the lack of real-time traffic information causes inadequate traffic management. So, in an intelligent transportation system, especially for traffic management, vehicle detection and counting system plays an important role.

Note: In the future, the traffic problem causes a serious problem if not addressed appropriately.

This tutorial proposes a video-based approach based on computer vision technologies for vehicle detection and counting. To find foreground objects in a sequence of video, the suggested method uses a technique called background subtraction technique. Several computer vision techniques, including thresholding, hole filling, and adaptive morphology operations, are then applied in order to track moving vehicles more accurately and precisely. Finally, with the use of a virtual(simulated) detection zone, vehicle counting and tracking is conducted.

Single Vehicle Detection Flow Chart

Single Vehicle Detection flow chart
Figure 1: Single Vehicle Counting Flow Chart

Multi-object tracking

Multi Vehicles Detection Flow Chart
Figure 2: Multi Vehicle Counting Flow Chart


A digital camera on a house was set up to collect the dataset of road videos which is recorded during the afternoon(from 12 P.M. to 2.30 P.M.). Six input videos of the road around four to seven minutes were taken. The resolution of the video was 1280×720 pixels with a time resolution of 30 frames per second.

Requirement to run this project

  • a. Python 3.7

  • b. OpenCV

  • c. Intel(R) Core i5 (1.7-2.4 GHz) CPU or above

  • d. 4 GB RAM or above

  • e. Camera

Based on the input videos, the accuracy of proposed vehicle detection and counting ranged from 95 percent to 99 percent. And what we have found is that the proposed algorithm and method tested quite well for every tested video. The experimental results for vehicle counting are shown below:

Video NumberTotal number of vehiclesNumber of counted vehiclesAccuracy(%)
Table 1: Experimental Results

Note: In total, it was possible to identify 534 vehicles out of 554 in all six input videos which give an accuracy of 96.54 5percent.

Future Escalation 

  • a. Localize the number plates

  • b. Segment the character

  • c. Store character in database


A computer vision-based vehicle detection and counting system – AI Project
Figure 3: A computer vision-based vehicle detection and counting system

My View

Vehicle counting and detecting system can be used to trace vehicles, traffic monitoring and controlling, payment on highway troll. We can also detect the speed of the vehicle on the lane. People will get knowledge about the types of vehicles entering and exiting and also will be able to get accurate information on the flow of traffic.

Computer vision and machine learning have really started to take off, but for most people, the whole idea of what a computer is seeing when it’s looking at an image is relatively obscure.

 – Mike Kreiger

Thanks for your time ☺

What do you think of this computer vision-based vehicle detection and counting system? Let us know by leaving a comment below. (Appreciation, Suggestions, and Questions are highly appreciated).

3 thoughts on “A computer vision based vehicle detection and counting system – AI Project

Leave a Reply

Your email address will not be published. Required fields are marked *