lane/line.py
def illustrate_driving_lane_with_topdownview(image, left_line, right_line):
    """
    #---------------------
    # This function illustrates top down view of the car on the road.
    #
    """

    img = cv2.imread("lane/ferrari.png", -1)
    img = cv2.resize(img, (120, 246))

    rows, cols = image.shape[:2]
    window_img = np.zeros_like(image)

    window_margin = left_line.window_margin
    left_plotx, right_plotx = left_line.allx, right_line.allx
    ploty = left_line.ally
    lane_width = right_line.startx - left_line.startx
    lane_center = (right_line.startx + left_line.startx) / 2
    lane_offset = cols / 2 - (2 * left_line.startx + lane_width) / 2
    car_offset = int(lane_center - 360)

    # Generate a polygon to illustrate the search window area
    # And recast the x and y points into usable format for cv2.fillPoly()
    left_line_window1 = np.array(
        [
            np.transpose(
                np.vstack(
                    [right_plotx + lane_offset - lane_width - window_margin / 4, ploty]
                )
            )
        ]
    )
    left_line_window2 = np.array(
        [
            np.flipud(
                np.transpose(
                    np.vstack(
                        [
                            right_plotx + lane_offset - lane_width + window_margin / 4,
                            ploty,
                        ]
                    )
                )
            )
        ]
    )
    left_line_pts = np.hstack((left_line_window1, left_line_window2))
    right_line_window1 = np.array(
        [
            np.transpose(
                np.vstack([right_plotx + lane_offset - window_margin / 4, ploty])
            )
        ]
    )
    right_line_window2 = np.array(
        [
            np.flipud(
                np.transpose(
                    np.vstack([right_plotx + lane_offset + window_margin / 4, ploty])
                )
            )
        ]
    )
    right_line_pts = np.hstack((right_line_window1, right_line_window2))

    # Draw the lane onto the warped blank image
    cv2.fillPoly(window_img, np.int_([left_line_pts]), (140, 0, 170))
    cv2.fillPoly(window_img, np.int_([right_line_pts]), (140, 0, 170))

    # Recast the x and y points into usable format for cv2.fillPoly()
    pts_left = np.array(
        [
            np.transpose(
                np.vstack(
                    [right_plotx + lane_offset - lane_width + window_margin / 4, ploty]
                )
            )
        ]
    )
    pts_right = np.array(
        [
            np.flipud(
                np.transpose(
                    np.vstack([right_plotx + lane_offset - window_margin / 4, ploty])
                )
            )
        ]
    )
    pts = np.hstack((pts_left, pts_right))

    # Draw the lane onto the warped blank image
    cv2.fillPoly(window_img, np.int_([pts]), (0, 160, 0))

    # window_img[10:133,300:360] = img
    road_map = Image.new("RGBA", image.shape[:2], (0, 0, 0, 0))
    window_img = Image.fromarray(window_img)
    img = Image.fromarray(img)
    road_map.paste(window_img, (0, 0))
    road_map.paste(img, (300 - car_offset, 590), mask=img)
    road_map = np.array(road_map)
    road_map = cv2.resize(road_map, (95, 95))
    road_map = cv2.cvtColor(road_map, cv2.COLOR_BGRA2BGR)

    return road_map

    #---------------------
    # This function illustrates top down view of the car on the road.
    #
    
This function illustrates top down view of the car on the road.
This function illustrates top down view of the car on the road .
def illustrate_driving_lane_with_topdownview(image, left_line, right_line):
    img = cv2.imread("lane/ferrari.png", -1)
    img = cv2.resize(img, (120, 246))
    rows, cols = image.shape[:2]
    window_img = np.zeros_like(image)
    window_margin = left_line.window_margin
    left_plotx, right_plotx = left_line.allx, right_line.allx
    ploty = left_line.ally
    lane_width = right_line.startx - left_line.startx
    lane_center = (right_line.startx + left_line.startx) / 2
    lane_offset = cols / 2 - (2 * left_line.startx + lane_width) / 2
    car_offset = int(lane_center - 360)
    left_line_window1 = np.array(
        [
            np.transpose(
                np.vstack(
                    [right_plotx + lane_offset - lane_width - window_margin / 4, ploty]
                )
            )
        ]
    )
    left_line_window2 = np.array(
        [
            np.flipud(
                np.transpose(
                    np.vstack(
                        [
                            right_plotx + lane_offset - lane_width + window_margin / 4,
                            ploty,
                        ]
                    )
                )
            )
        ]
    )
    left_line_pts = np.hstack((left_line_window1, left_line_window2))
    right_line_window1 = np.array(
        [
            np.transpose(
                np.vstack([right_plotx + lane_offset - window_margin / 4, ploty])
            )
        ]
    )
    right_line_window2 = np.array(
        [
            np.flipud(
                np.transpose(
                    np.vstack([right_plotx + lane_offset + window_margin / 4, ploty])
                )
            )
        ]
    )
    right_line_pts = np.hstack((right_line_window1, right_line_window2))
    cv2.fillPoly(window_img, np.int_([left_line_pts]), (140, 0, 170))
    cv2.fillPoly(window_img, np.int_([right_line_pts]), (140, 0, 170))
    pts_left = np.array(
        [
            np.transpose(
                np.vstack(
                    [right_plotx + lane_offset - lane_width + window_margin / 4, ploty]
                )
            )
        ]
    )
    pts_right = np.array(
        [
            np.flipud(
                np.transpose(
                    np.vstack([right_plotx + lane_offset - window_margin / 4, ploty])
                )
            )
        ]
    )
    pts = np.hstack((pts_left, pts_right))
    cv2.fillPoly(window_img, np.int_([pts]), (0, 160, 0))
    road_map = Image.new("RGBA", image.shape[:2], (0, 0, 0, 0))
    window_img = Image.fromarray(window_img)
    img = Image.fromarray(img)
    road_map.paste(window_img, (0, 0))
    road_map.paste(img, (300 - car_offset, 590), mask=img)
    road_map = np.array(road_map)
    road_map = cv2.resize(road_map, (95, 95))
    road_map = cv2.cvtColor(road_map, cv2.COLOR_BGRA2BGR)
    return road_map
def illustrate_driving_lane_with_topdownview ( image , left_line , right_line ) : img = cv2 . imread ( "lane/ferrari.png" , - 1 ) img = cv2 . resize ( img , ( 120 , 246 ) ) rows , cols = image . shape [ : 2 ] window_img = np . zeros_like ( image ) window_margin = left_line . window_margin left_plotx , right_plotx = left_line . allx , right_line . allx ploty = left_line . ally lane_width = right_line . startx - left_line . startx lane_center = ( right_line . startx + left_line . startx ) / 2 lane_offset = cols / 2 - ( 2 * left_line . startx + lane_width ) / 2 car_offset = int ( lane_center - 360 ) left_line_window1 = np . array ( [ np . transpose ( np . vstack ( [ right_plotx + lane_offset - lane_width - window_margin / 4 , ploty ] ) ) ] ) left_line_window2 = np . array ( [ np . flipud ( np . transpose ( np . vstack ( [ right_plotx + lane_offset - lane_width + window_margin / 4 , ploty , ] ) ) ) ] ) left_line_pts = np . hstack ( ( left_line_window1 , left_line_window2 ) ) right_line_window1 = np . array ( [ np . transpose ( np . vstack ( [ right_plotx + lane_offset - window_margin / 4 , ploty ] ) ) ] ) right_line_window2 = np . array ( [ np . flipud ( np . transpose ( np . vstack ( [ right_plotx + lane_offset + window_margin / 4 , ploty ] ) ) ) ] ) right_line_pts = np . hstack ( ( right_line_window1 , right_line_window2 ) ) cv2 . fillPoly ( window_img , np . int_ ( [ left_line_pts ] ) , ( 140 , 0 , 170 ) ) cv2 . fillPoly ( window_img , np . int_ ( [ right_line_pts ] ) , ( 140 , 0 , 170 ) ) pts_left = np . array ( [ np . transpose ( np . vstack ( [ right_plotx + lane_offset - lane_width + window_margin / 4 , ploty ] ) ) ] ) pts_right = np . array ( [ np . flipud ( np . transpose ( np . vstack ( [ right_plotx + lane_offset - window_margin / 4 , ploty ] ) ) ) ] ) pts = np . hstack ( ( pts_left , pts_right ) ) cv2 . fillPoly ( window_img , np . int_ ( [ pts ] ) , ( 0 , 160 , 0 ) ) road_map = Image . new ( "RGBA" , image . shape [ : 2 ] , ( 0 , 0 , 0 , 0 ) ) window_img = Image . fromarray ( window_img ) img = Image . fromarray ( img ) road_map . paste ( window_img , ( 0 , 0 ) ) road_map . paste ( img , ( 300 - car_offset , 590 ) , mask = img ) road_map = np . array ( road_map ) road_map = cv2 . resize ( road_map , ( 95 , 95 ) ) road_map = cv2 . cvtColor ( road_map , cv2 . COLOR_BGRA2BGR ) return road_map
This function illustrates top down view of the car on the road.
This function illustrates top down view of the car on the road .
"""
    #---------------------
    # This function illustrates top down view of the car on the road.
    #
    """ # Generate a polygon to illustrate the search window area # And recast the x and y points into usable format for cv2.fillPoly() # Draw the lane onto the warped blank image # Recast the x and y points into usable format for cv2.fillPoly() # Draw the lane onto the warped blank image # window_img[10:133,300:360] = img
image
left_line
right_line