Hey Guys, get excited because in this tutorial we will look at how to use Computer Vision and Image Processing to detect if a car is changing lanes while the cars are on the road, so without further delay let’s start -

You must have heard that using OpenCV haar cascade files detection of faces, eyes, or objects like car, bus, etc. can be done but what then? So let’s use this simple detection method to build something cool.

1. Dataset

Video files of cars on a road are used as a dataset in this tutorial. Also, we can detect cars in an image using image datasets but here as the car is changing lanes we give an alert with a pop-up window, so for these dynamics, video input is more feasible.

2. Input

The first step is to give the inputs to be used in the tutorial — a haar cascade file of OpenCV to detect the coordinates of a car, a video file of cars on a road -

cascade_src = 'cascade/cars.xml'
	video_src = 'dataset/cars.mp4'

	cap = cv2.VideoCapture(video_src)
	car_cascade = cv2.CascadeClassifier(cascade_src)

cv2.VideoCapture() method is used for capturing the input video, a video is generally 25 images/frames per second (fps). After capturing the input, frames are extracted using a loop, and using the coordinates detected by the haar cascade file of a car, we draw a rectangle around the car in a loop to get consistency while performing other operations on the captured frame.

while(1):
	    ## Take each frame
	    _, frame = cap.read()
	    cars = car_cascade.detectMultiScale(frame, 1.1, 1)
	    for (x,y,w,h) in cars:
	        roi = cv2.rectangle(frame,(x,y),(x+w,y+h),(0,0,255),2)   #ROI is region of interest

In OpenCV BGR is used and not RGB, so (0,0,255) will draw a red rectangle over the car and not blue.

#image-processing #computer-vision #lane-change-detection #opencv #python

Lane Change Detection — Computer Vision at Next stage
3.35 GEEK