IKH

Saving Blobs

Now that you have seen tracking of the vehicles, we will crop the valid blobs at every 5th frame and store them in the disk.

In the above video, we are basically doing two things. First is to draw a red rectangle around the tracked vehicle. This is done through cv2. rectangle(). Second is cropping and saving the vehicles and this will be used for classification through deep learning. cv2.imwrite() will save the image in the disk. As Anand said, vehicles are only saved at every 5th frame as saving the vehicle at every frame will create a lot of redundant data. We will also resize all the vehicles to a fixed dimension to make the training and inference faster when using deep learning.

In the next video, you will see that if the centre point of a vehicle crosses the line, we increase the count of the tracked vehicles in the lane by 1. Note that we are counting the vehicle only once when it crosses the yellow imaginary line. This will give the total number of vehicles which crossed the lane.

A question that arises here is: How does one know when a vehicle has crossed the imaginary yellow line?

If the vehicle crosses a line, its central position on the previous and current timeframe lies in opposite directions of the line.

Let’s continue with the lecture. So, you have learnt to track the vehicle using OpenCV. In the next segment, you will see the final output video.

Report an error