Advanced Lane Finding Project

The goals / steps of this project are the following:

  • Compute the camera calibration matrix and distortion coefficients given a set of chessboard images.
  • Apply a distortion correction to raw images.
  • Use color transforms, gradients, etc., to create a thresholded binary image.
  • Apply a perspective transform to rectify binary image ("birds-eye view").
  • Detect lane pixels and fit to find the lane boundary.
  • Determine the curvature of the lane and vehicle position with respect to center.
  • Warp the detected lane boundaries back onto the original image.
  • Output visual display of the lane boundaries and numerical estimation of lane curvature and vehicle position.

In [1]:
import os
import cv2
import glob
import numpy as np
import glob
import matplotlib.image as mpimg
from moviepy.editor import VideoFileClip
import matplotlib.pyplot as plt
from AdvancedLaneLine import AdvancedLaneLine

In [2]:
# try against all test images
images = glob.glob('./test_images/t*.jpg')

for idx, fname in enumerate(images):
    print("processing image ({}) ...".format(fname))
    file_path_split = os.path.splitext(os.path.basename(fname))
    file_name = file_path_split[-2]

    advanced_lane_line = AdvancedLaneLine(session=file_name, debug=True)
    img = mpimg.imread(fname)
    out = advanced_lane_line.image_pipeline(img)
print("Done.")


processing image (./test_images/test5.jpg) ...
processing image (./test_images/test1.jpg) ...
processing image (./test_images/test6.jpg) ...
processing image (./test_images/test2.jpg) ...
processing image (./test_images/test4.jpg) ...
processing image (./test_images/test3.jpg) ...
Done.

In [3]:
print("processing project video ...")
# create an instance per video
advanced_lane_line_1 = AdvancedLaneLine(session="session1", debug=False)
input_video = VideoFileClip("./project_video.mp4")
outclip = input_video.fl_image(advanced_lane_line_1.image_pipeline)
outclip.write_videofile("./output/project_video_out.mp4", audio=False)
print("Number of frames using sliding windows : {}, from existing lane info : {}".format(advanced_lane_line_1.sliding_window_count, advanced_lane_line_1.from_existing_count))
print("Done.")


processing project video ...
[MoviePy] >>>> Building video ./output/project_video_out.mp4
[MoviePy] Writing video ./output/project_video_out.mp4
100%|█████████▉| 1260/1261 [04:51<00:00,  4.31it/s]
[MoviePy] Done.
[MoviePy] >>>> Video ready: ./output/project_video_out.mp4 

Number of frames using sliding windows : 29, from existing lane info : 1232
Done.

In [5]:
print("processing challenge video ...")
advanced_lane_line_2 = AdvancedLaneLine(session="session2", debug=False)
input_video = VideoFileClip("./challenge_video.mp4")
outclip = input_video.fl_image(advanced_lane_line_2.image_pipeline)
outclip.write_videofile("./output/challenge_video_out.mp4", audio=False)
print("Number of frames using sliding windows : {}, from existing lane info : {}".format(advanced_lane_line_2.sliding_window_count, advanced_lane_line_2.from_existing_count))
print("Done.")


processing challenge video ...
[MoviePy] >>>> Building video ./output/challenge_video_out.mp4
[MoviePy] Writing video ./output/challenge_video_out.mp4
100%|██████████| 485/485 [01:49<00:00,  4.51it/s]
[MoviePy] Done.
[MoviePy] >>>> Video ready: ./output/challenge_video_out.mp4 

Number of frames using sliding windows : 353, from existing lane info : 133
Done.