Beispiel #1
0
def exploratory_pipeline():
    '''
    The pipeline to calculate the lane lines in an exploratory mode that produces
    plots of the various stages along the way.
    
    Notes:
    - Calibration shall be performed at least once before using the pipeline
    - This pipeline works with for a single image
    '''
    # Read in an image
    image = mpimg.imread(test_image)

    # Undistort the image before processing and plot an example
    mtx, dist = Camera.getCalibrationData()
    undist = Camera.undistort(image, mtx, dist)

    # Process the undistorted image with thresholding to get a binary mask
    binary_mask = Thresholding.lane_detection_mask(undist, KERNEL)

    # Plot the undistorted and binary mask images
    Plotting.plotResult(undist, binary_mask)

    # Perspective transform
    warped, M, M_inv = Image_processing.perspectiveTransform(binary_mask)
    Plotting.plotResult(binary_mask, warped)

    # Get the position of the left and right lanes
    leftx_base, rightx_base = Image_processing.histogramPeaks(warped,
                                                              plot=True)

    # Get the lane line equations using the sliding window
    left_fit, right_fit = Image_processing.slidingWindowInit(warped, plot=True)

    # Calculate the sliding window of a successive image, using the lane line
    # equations that are already known from the previous image analysis
    left_fit, right_fit = Image_processing.slidingWindowFollowing(warped,
                                                                  left_fit,
                                                                  right_fit,
                                                                  plot=True)

    # Calculate the curvature of the left and right lanes
    left_curv, right_curv, curv_string = Image_processing.curvature(
        warped, left_fit, right_fit)

    # Calculate the offset of the car from the center of the lane line
    offset_m, offset_string = Image_processing.offsetFromCenter(
        undist, leftx_base, rightx_base)

    # Overlay the lane area to the undistorted image
    Image_processing.laneArea(warped,
                              undist,
                              M_inv,
                              left_fit,
                              right_fit,
                              offset_string,
                              plot=True)
Beispiel #2
0
def pipeline(image):
    '''
    The lane detection pipeline
    
    Notes:
    - Calibration shall be performed at least once before using the pipeline
    - This pipeline worlks with a video
    '''
    global left_lane
    global right_lane
    global initiate_sw
    global initiate_sw_counter
    global initiate_sw_limit

    # Undistort the image before processing and plot an example
    mtx, dist = Camera.getCalibrationData()
    undist = Camera.undistort(image, mtx, dist)

    # Process the undistorted image with thresholding to get a binary mask
    binary_mask = Thresholding.lane_detection_mask(undist, KERNEL)

    # Perspective transform
    warped, M, M_inv = Image_processing.perspectiveTransform(binary_mask)

    # Get the position of the left and right lanes
    leftx_base, rightx_base = Image_processing.histogramPeaks(warped)

    # Apply the appropriate slidinig window technique
    # Note:
    # - If there are more than a few bad frames, a fresh sliding window full
    #   search is forced to take place
    if initiate_sw:
        # Get the lane line equations using the sliding window
        left_fit, right_fit = Image_processing.slidingWindowInit(warped)

        # Reset the sliding window control variables
        initiate_sw = False
        initiate_sw_counter = 0

    else:
        # Calculate the sliding window of a successive image, using the lane line
        # equations that are already known from the previous image analysis
        left_fit, right_fit = Image_processing.slidingWindowFollowing(warped, \
                                    left_lane.current_fit, \
                                    right_lane.current_fit)

        # Update the sliding window control variables
        initiate_sw_counter = initiate_sw_counter + 1
        if initiate_sw_counter >= 5:
            initiate_sw = True

    # Sanity checks and update globals accordingly
    if Image_processing.sanityChecks(warped, left_fit, right_fit):
        # If sanity ok then update the globals with the new line equations
        left_lane.current_fit = left_fit
        right_lane.current_fit = right_fit
    else:
        # If sanity fails use the previously set globals for calculations
        left_fit = left_lane.current_fit
        right_fit = right_lane.current_fit

        # And start a fresh sliding window search
        initiate_sw = True

    # Calculate the curvature of the left and right lanes
    left_curv, right_curv, curv_string = Image_processing.curvature(
        warped, left_fit, right_fit)

    # Calculate the offset of the car from the center of the lane line
    offset_m, offset_string = Image_processing.offsetFromCenter(
        undist, leftx_base, rightx_base)

    # Overlay the lane area to the undistorted image
    result = Image_processing.laneArea(warped, undist, M_inv, left_fit,
                                       right_fit, offset_string)

    # Return processed image
    return result