Skip to content

Lane detection using OpenCV techniques such as edge detection, masking, filtering, and average slope-intercept. Written in Python 3.7x

License

Notifications You must be signed in to change notification settings

rahularepaka/lane-detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Real-time Lane Detection

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.

Screenshot 2022-05-31 025842

Requirements

To install all the dependencies in this project run

  pip install -r requirements.txt

Deploymnt

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

Libraries

  • OpenCV
  • Numpy
  • Tensorflow
  • Keras

Dataset

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

solidWhiteCurve

Computer Vision Techniques

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

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

edge

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

hsv

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

filtering

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])

mask

Current Progress on newer datasets

Testing with Simulators

  • CARLA Simulator image

  • lGSVL Simulator image

  • Udacity Car Simulator by Unity

  • image

Test Videos (Kinda Failed)

Testing Video on Udacity Simulator

test1_out.mp4

Testing on Indian Road

dashcam_video_trim_output.mp4

Ways to contribute

  1. Fork the repo on GitHub
  2. Clone the project to your own machine
  3. Commit changes to your own branch
  4. Push your work back up to your fork
  5. Submit a Pull request so that we can review your changes

Please abide by Contributing Guidelines and Code of Conduct.

Contributors

  • Rahul Arepaka
  • Avula Vijaya Koushik
  • Cherukuru Swaapnika Chowdary
  • Lohit Garje
  • Naga Tharun Makkena

References

Feedback

If you have any feedback, please reach out to us at rahul.arepaka@gmail.com

License

MIT

About

Lane detection using OpenCV techniques such as edge detection, masking, filtering, and average slope-intercept. Written in Python 3.7x

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages