Path Detection based on Bird Eye view with OpenCV module

Path Detection based on Birds Eye view with OpenCV module  

Environment setup/ Project Requirements :
1)Python 
2)OpenCV, Numpy, Pickle libraries need to be installed on your computer/laptop
3) Pycharm/Visual studio/Atom must be installed
Note: You can't run this code in google-colab (or) in any online compiler/interpreter 

Work Flow: 
  1. We make a copy of the original image and Undistort the copied image
  2. Apply threshold and canny filter to the copied image.
  3. Apply warp perspective to get a birds-eye view of the image.
  4. Place virtual windows at the starting of the image, which reflects the shape of the curve.
  5. Using the center of the windows we generate a second-order polynomial function.
  6. We apply the entire process to the original image.
Step 1: Image Preprocessing

Firstly we have to undistort the image because, when a large amount of area is getting into the smaller area there will be some distortions in the image.
We use the undistort function to remove distortions in the image.

imgUndistort = utils.undistort(img)

After Undistorting the image, we apply thresholding to the image so that it'll be converted into a gray image. 
We apply a canny filter to the image to detect edges.

imgThres,imgCanny,imgColor = utils.thresholding(imgUndistort)

Step 2: Bird's Eye View

We apply a warp perspective on the image because our goal is to see the image from a top angle because we cannot detect edges if we are just looking forward.
When you see from the top of the image you notice that it gets a little more pixelated obviously, we can’t create a resolution that didn’t exist in the original image but there should be enough fidelity there to isolate those pixels from the surrounding image.
To apply warp perspective we need four points to set a region, We get those points using Trackbars.

if cameraFeed:intialTracbarVals = [24,55,12,100] # #wT,hT,wB,hB else:intialTracbarVals = [42,63,14,87] #wT,hT,wB,hB utils.initializeTrackbars(intialTracbarVals)

Now, let's draw warp points on the image with drawPoints function.

imgWarpPoints = utils.drawPoints(imgWarpPoints, src)


Step 3: Histogram of the image.

To find the lane lines in the grey image, we use the histogram, It gives the peak where ever it encounters white pixels(value-255), by following the peaks we can detect lane lines of image/video.

def get_hist(img): hist = np.sum(img[img.shape[0]//2:,:], axis=0) return hist


the y-axis is the sum of the pixels, x-axis position of the pixels.

Step 4: Curve Fitting

Now, we fit a rectangular window box on the lane lines, which are detected with the help of a histogram. We check window boxes one by one on both left and right boundaries. based on mean position, we recenter it. Now we get the center points of each window.


We use second-order polynomial to detect curve, We use the poly-fit function to fit the polynomial curve. 
We average all the parameters based on the new curve value to have a smooth curve.

curverad =utils.get_curve(imgFinal, curves[0], curves[1])
lane_curve = np.mean([curverad[0], curverad[1]])
imgFinal = utils.draw_lanes(img, curves[0], curves[1],frameWidth,frameHeight,src=src)


If you want to see the full code of this project, you can visit my Github and YouTube

Note: Special thanks to Ross kippenbrock for providing raw images.

Expected Viva:

1)Why we use warp perspective? and what is the warp perspective?
A) Warp perspective is a kind of thing that we look at the path in Birds Eye View means like we look path from the top view, not in the front view. Usually, when we see the path from the front view we cannot detect the curves so that we use the warp perspective.

2)How and where source points are located?
A) Source points are taken randomly on the image, using trackbars we can rearrange them according to the width of the road.

3)How do you think this project is useful to the world or for you?
A) This project may not be used to develop an autonomous vehicle but it can be used to build an autonomous robot like amazon deep racer.

4)What is the accuracy it can detect the path correctly?
A)Basically we are not using any machine learning or deep learning here, so there's no accuracy that can be measured. We are using just the OpenCV module and detecting the path through extracting features manually.

5)What are the challenges you faced in this project?
A) The main challenge is to make the vehicle move in its path without moving left or right. and for that, I used a radius of curvature formulae to overcome it.

made with 💓 by G. Sai Dheeraj


\


Comments

Popular posts from this blog

Object Detection Using OpenCV and Transfer Learning.

Traffic signs recognition with convolutional Neural networks