Lane Detection with OpenCV
[WIP]
Lane Detection with OpenCV
[Intro]
[Try list] Get Lane Image -> Preprocessing -> Canny Edge Detection -> Hough Line Detection -> Find Lane Lines -> Calculate Steering angle.
Preprocessing The goal of the preprocessing step is to prepare the image for the rest of the steps.
Change to Grayscale [why]
Gaussian Blur to and remove noise, the lane lines will stand out but any noise that was there will get blurred away.
Cropping is used to select the region we want to run the lane detection on (ex. Selecting the bottom half of the image) In my case im using just the bottom 1/4 of the image. This makes processing much faster since Canny Edge Detection and Hough Line Detection gets run on a smaller image.
(Code Block)
Canny Edge Detection This algorithm will find all edges in the image. The goal of this step is to get edges drawn around the lane lines. Adjusting the threshold parameters allow you to adjust how on sensitive it is to detecting an edge. (Images)
Hough Line Detection This algorithm will get the most distinct lines in an image. Hough is needed because Canny Edge detection just gets all edges including ones that do not correspond to lane lines and edges that are curved. Hough Line detection is used to find all the straight lines and will filter everything else out. Parameters to the Hough Line Detection allow you to set a [TODO or remove]
Post Processing After getting lines. Hough Line Detection returns all straight lines, usually this includes lines that do not correspond to a lane line. In order to filter through the lines properly I use slope to classify each line into one of the following categories, Left Lane Line, Right Lane Line, or Throw away.
After I average all the Left lane lines and Right lane lines, I end up with 1 line representing the left line and 1 line representing the right line.
Calculating Steering angle Steering angle is calculated based on the midpoint of where the 2 lane lines hit the bottom edge of the frame. Wherever this midpoint is relative to the center of the frame is what the steering angle becomes.
Steering Angle = (Lane Lines Midpoint - Frame Center) * Proportional Constant
Demo Video Below Orange = Midpoint of the lane lines Pink = Center of frame Red = Steering Angle