Build Ai car and pedestrian tracking for beginners using Python

Time:2021-10-14

Author | Nidhi punj
Compile Flin
Source | medium

Step 1: get a lot of car pictures

Step 2: turn them all into black and white pictures

Grayscale images make the algorithm faster. Color increases the complexity of the model, or we can say that gray images are used to simplify mathematics. For example, we can talk about brightness, contrast, edge, shape, outline, texture, perspective, shadow, etc. instead of color.

Step 3: train the algorithm to detect the vehicle

Now the question comes: how do computers train algorithms?

We just found a match.

We can match the above functions to actually detect the rear bumper of the car, as shown below.

The idea of detecting pedestrians is the same

Everything is to match features or shapes. If an object matches the above features, the model will detect it as a pedestrian.

Let’s start writing detectors

Step 1: we first need to install the opencv library.

pip install opencv-python

If this does not work, try:

pip install opencv-python-headless

If you still can’t install. Try using Google search. How do I install opencv on my computer?

Step 2: download the machine learning file (Haar cascade XML file):

We have provided a pre trained car and human (pedestrian) classifier. We just need to download it.

Vehicle pre training classifierhttps://raw.githubusercontent.com/andrewssobral/vehicle_detection_haarcascades/master/cars.xml

Human pre training classifierhttps://raw.githubusercontent.com/opencv/opencv/master/data/haarcascades/haarcascade_fullbody.xml

Step 3: we only need to write 20 lines of code. You can understand it by reading the code.

GitHub code link:https://github.com/nidhipunj7/AI-Car-and-Pedestrian-Tracking

result

View video:

Recommended links:

Original link:https://medium.com/@nidhipunj7/build-ai-car-and-pedestrian-tracking-with-python-for-beginners-ac49a83eb5d2

Welcome to panchuang AI blog:
http://panchuang.net/

Official Chinese document of sklearn machine learning:
http://sklearn123.com/

Welcome to panchuang blog resources summary station:
http://docs.panchuang.net/