We will train and construct a model that helps detect lanes on straight and curved roads based on the raw pixels captured by the single front-facing camera.
To install all the dependencies in this project run
pip install -r requirements.txt
To run this project, you will need to add the following command
git clone https://github.com/rahularepaka/lane-detection.git
cd lane-detection
python main.python
- OpenCV
- Numpy
- Tensorflow
- Keras
This project demonstrates lane detection using a single image from a road dataset. The lanes are marked by a solid white line (on the right) and alternating short line segments with dots (on the left).
Link to Dataset : Lane Line Detection : Kaggle
Canny Edge Detection
def canny(img):
if img is None:
cap.release()
cv.destroyAllWindows()
exit()
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
kernel = 5
blur = cv.GaussianBlur(gray, (kernel, kernel), 0)
canny = cv.Canny(gray, 50, 150)
return canny
def edge_detection(image):
edges = cv.Canny(image, 80, 200)
cv.namedWindow("edges", cv.WINDOW_NORMAL)
cv.resizeWindow("edges", 500, 500)
cv.imshow('edges', edges)
return edges
Masking using HSV Channel
def red_white_masking(image):
hsv = cv.cvtColor(image, cv.COLOR_BGR2HSV)
lower_y = np.array([10, 130, 120], np.uint8)
upper_y = np.array([40, 255, 255], np.uint8)
mask_y = cv.inRange(hsv, lower_y, upper_y)
cv.namedWindow("mask_y", cv.WINDOW_NORMAL)
cv.resizeWindow("mask_y", 500, 500)
cv.imshow('mask_y', mask_y)
lower_w = np.array([0, 0, 212], np.uint8)
upper_w = np.array([170, 200, 255], np.uint8)
mask_w = cv.inRange(hsv, lower_w, upper_w)
cv.namedWindow("mask_w", cv.WINDOW_NORMAL)
cv.resizeWindow("mask_w", 500, 500)
cv.imshow('mask_w', mask_w)
mask = cv.bitwise_or(mask_w, mask_y)
cv.namedWindow("mask", cv.WINDOW_NORMAL)
cv.resizeWindow("mask", 500, 500)
cv.imshow('mask', mask)
masked_bgr = cv.bitwise_and(image, image, mask=mask)
cv.namedWindow("masked_bgr", cv.WINDOW_NORMAL)
cv.resizeWindow("masked_bgr", 500, 500)
cv.imshow('masked_bgr', masked_bgr)
return masked_bgr
Image Filtering
def filtered(image):
kernel = np.array([[-1, 0, 1], [-1, 0, 1], [-1, 0, 1]])
filtered_image = cv.filter2D(image, -1, kernel)
cv.namedWindow("filtered_image", cv.WINDOW_NORMAL)
cv.resizeWindow("filtered_image", 500, 500)
cv.imshow('filtered_image', filtered_image)
return filtered_image
Average slope intercept
def average_slope_intercept(image, lines):
left_fit = [] # list for all multiple lines found in left lane
right_fit = [] # list for all multiple lines found in right lane
global l
global r
for line in lines:
x1, y1, x2, y2 = line.reshape(4)
parameters = np.polyfit((x1, x2), (y1, y2), 1)
slope = parameters[0]
intercept = parameters[1]
if slope < 0:
left_fit.append((slope, intercept))
else:
right_fit.append((slope, intercept))
if left_fit != []:
left_fit_average = np.average(left_fit, axis=0)
left_line = create_coordinates(image, left_fit_average)
l = left_fit_average
else:
left_line = create_coordinates(image, l)
if right_fit != []:
right_fit_average = np.average(right_fit, axis=0)
right_line = create_coordinates(image, right_fit_average)
r = right_fit_average
else:
right_line = create_coordinates(image, r)
return np.array([left_line, right_line])
Testing with Simulators
Test Videos (Kinda Failed)
Testing Video on Udacity Simulator
test1_out.mp4
Testing on Indian Road
dashcam_video_trim_output.mp4
- Fork the repo on GitHub
- Clone the project to your own machine
- Commit changes to your own branch
- Push your work back up to your fork
- Submit a Pull request so that we can review your changes
- Rahul Arepaka
- Avula Vijaya Koushik
- Cherukuru Swaapnika Chowdary
- Lohit Garje
- Naga Tharun Makkena
- Canny Edge Detection
- Building a lane detection system
- Advanced Lane Detection
- Road Lane Detection using OpenCV (Hough Lines Transform Explained)
If you have any feedback, please reach out to us at rahul.arepaka@gmail.com