Esempio n. 1
0
def demo_mask():
    # Read in a thresholded image
    #warped = mpimg.imread('warped_example.jpg')
    image = mpimg.imread('test_images/test1.jpg')
    undist = undistort(image)
    warped, M, M_inverse = warp(undist)
    binary_warped = threshold_image(warped)
    #plt.imshow(binary_warped)
    #plt.show()
    #warped = mpimg.imread('output_images/straight_lines1_warped.jpg')
    # window settings
    convolution = createConvolution()
    lane = convolution.find_lane(binary_warped)
    window_width = convolution.window_width
    window_height = convolution.window_height
    # If we found any window centers
    if lane is not None:

        # Points used to draw all the left and right windows
        l_points = np.zeros_like(binary_warped)
        r_points = np.zeros_like(binary_warped)

        # Go through each level and draw the windows
        for level in range(0, len(lane.leftx)):
            # Window_mask is a function to draw window areas
            l_mask = window_mask(window_width, window_height, binary_warped,
                                 lane.leftx[level], level)
            r_mask = window_mask(window_width, window_height, binary_warped,
                                 lane.rightx[level], level)
            # Add graphic points from window mask here to total pixels found
            l_points[(l_points == 255) | ((l_mask == 1))] = 255
            r_points[(r_points == 255) | ((r_mask == 1))] = 255

        # Draw the results
        template = np.array(
            r_points + l_points,
            np.uint8)  # add both left and right window pixels together
        zero_channel = np.zeros_like(template)  # create a zero color channel
        template = np.array(cv2.merge((zero_channel, template, zero_channel)),
                            np.uint8)  # make window pixels green
        warpage = np.array(
            cv2.merge((binary_warped, binary_warped, binary_warped)),
            np.uint8)  # making the original road pixels 3 color channels
        output = cv2.addWeighted(
            warpage, 1, template, 0.5,
            0.0)  # overlay the orignal road image with window results

    # If no window centers found, just display orginal road image
    else:
        output = np.array(
            cv2.merge((binary_warped, binary_warped, binary_warped)), np.uint8)

    # Display the final results
    side_by_side_plot(binary_warped,
                      output,
                      im1_title="Binary Warped",
                      im2_title="Conv Search",
                      im1_cmap='gray',
                      im2_cmap='gray')
def demo():
    image = mpimg.imread('test_images/straight_lines2.jpg')
    undist_image = undistort(image)

    warped, M, M_inverse = warp(undist_image)
    side_by_side_plot(image,
                      warped,
                      im1_title="Image",
                      im2_title="Warped Image")
Esempio n. 3
0
def demo_spatial_binning():
    # Read a color image
    img = read_image("test_images/000275.png")
    img_small = cv2.resize(img, (32, 32))
    side_by_side_plot(im1=img,
                      im2=img_small,
                      im1_title="Example Image",
                      im2_title="Spatial Binning",
                      fontsize=16)


#demo_spatial_binning()
Esempio n. 4
0
def demo_prediction2():
    image = read_image("test_images/test1.jpg")
    model = create_model((260, 1280, 3))
    model.load_weights("model_-11-0.01.h5")
    hot_windows = search_cars(model, image)
    heatmap = heatmap_filter(image, hot_windows, 3)

    # Find final boxes from heatmap using label function
    labels = label(heatmap)
    draw_img = draw_labeled_bboxes(np.copy(image), labels)
    side_by_side_plot(im1=image, im2=draw_img)
    # Temporary fix - AttributeError: 'NoneType' object has no attribute 'TF_NewStatus
    K.clear_session()
def demo():
    vehicle_detection = VehicleDetection()

    image = read_image('test_images/test1.jpg')
    #image = read_image('test_images/screen2.png')
    draw_image = vehicle_detection.detect(image)

    side_by_side_plot(im1=image,
                      im2=draw_image,
                      im2_cmap='hot',
                      im1_title="Example Image",
                      im2_title="Bounding Boxes",
                      fontsize=16)
Esempio n. 6
0
def demo_threshold_image():
    image = mpimg.imread('test_images/straight_lines1.jpg')
    undist = undistort(image)
    warped, M, M_inverse = warp(undist)

    binary_warped = threshold_image(warped)
    side_by_side_plot(image,
                      binary_warped,
                      im1_title='Image',
                      im2_title='Binary Warped',
                      im2_cmap='gray')
    #plt.imshow(binary_image, cmap = 'gray')
    #plt.show()


#demo_threshold_image()
Esempio n. 7
0
def demo_smallset():
    cars, notcars = load_smallset()
    data_info = data_look(cars, notcars)

    print('Your function returned a count of',
          data_info["n_cars"], ' cars and',
          data_info["n_notcars"], ' non-cars')
    print('of size: ',data_info["image_shape"], ' and data type:',
          data_info["data_type"])
    # Just for fun choose random car / not-car indices and plot example images
    car_ind = np.random.randint(0, len(cars))
    notcar_ind = np.random.randint(0, len(notcars))

    # Read in car / not-car images
    car_image = mpimg.imread(cars[car_ind])
    notcar_image = mpimg.imread(notcars[notcar_ind])

    side_by_side_plot(im1=car_image, im2=notcar_image, im1_title="Example Car Image", im2_title="Example Not-car Image", fontsize=16)
Esempio n. 8
0
    def detect(self, rgb_image):
        undist_image = undistort(rgb_image)
        warped, M, M_inverse = warp(undist_image)
        binary_warped = threshold_image(warped)

        lane = None
        if self.best_lane is not None:
            lane = self.convolution.find_lane_with_hint(self.best_lane.midx(), binary_warped)
        if lane is None:
            lane = self.convolution.find_lane(binary_warped)
        self.add_lane(lane)

        lane_selected = None
        if self.best_lane is not None:
            lane_selected = self.best_lane
            self.n_best_lane_used += 1
        elif (lane is not None) and lane.good_confidence():
            lane_selected = lane
            self.n_lane_used += 1
        else:
            lane_selected = self.last_good_lane
            self.n_last_good_lane_used += 1

        if (lane is not None) and lane.good_confidence():
            self.last_good_lane = lane

        if lane_selected is not None:
            left_curverad, right_curverad = self.measure_curvature(lane_selected)
            center_offset = self.center_offset(lane_selected)
            lane_drawn = self.convolution.draw_lane(lane_selected, M_inverse = M_inverse)
            out_image = cv2.addWeighted(undist_image, 1, lane_drawn, 0.3, 0)
            cv2.putText(out_image, 'Left, Right Curvature: {:.2f}m, {:.2f}m'.format(left_curverad, right_curverad),
                        (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)
            cv2.putText(out_image, 'Center Lane Offset: {:.2f}m'.format(center_offset),
                    (50, 100), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)
            return out_image
        else:
            if lane is not None:
                print(lane.confidence)
            side_by_side_plot(undist_image, binary_warped)
            self.n_no_lane_used += 1
            return undist_image
Esempio n. 9
0
def demo_prediction():
    model = load_model("model_-14-0.04.h5")
    cars, notcars = load_smallset()
    # Just for fun choose random car / not-car indices and plot example images
    car_ind = np.random.randint(0, len(cars))
    notcar_ind = np.random.randint(0, len(notcars))

    # Read in car / not-car images
    car_image = read_image(cars[car_ind])
    notcar_image = read_image(notcars[notcar_ind])

    car_prediction = model.predict(np.reshape(car_image, (1, 64, 64, 3)))
    notcar_prediction = model.predict(np.reshape(notcar_image, (1, 64, 64, 3)))
    side_by_side_plot(im1=car_image,
                      im2=notcar_image,
                      im1_title="prediction: {}".format(car_prediction),
                      im2_title="prediction: {}".format(notcar_prediction),
                      fontsize=16)
    # Temporary fix - AttributeError: 'NoneType' object has no attribute 'TF_NewStatus
    K.clear_session()
def demo():
    # Read in our vehicles and non-vehicles
    cars, notcars = load_smallset()

    # Generate a random index to look at a car image
    ind = np.random.randint(0, len(cars))
    # Read in the image
    image = mpimg.imread(cars[ind])
    image_YCrCb = convert_color(image, "YCrCb")
    channel1 = image_YCrCb[:, :, 0]
    # Define HOG parameters
    orient = 9
    pix_per_cell = 8
    cell_per_block = 2
    # Call our function with vis=True to see an image output
    features, hog_image = channel_hog_features(channel1, orient,
                                           pix_per_cell, cell_per_block,
                                           vis=True, feature_vec=False)

    side_by_side_plot(im1=image, im2=hog_image, im1_title="Example Car Image", im2_title="HOG Visualization", fontsize=16)

#demo()
Esempio n. 11
0
def demo_undist():
    image = mpimg.imread('test_images/straight_lines1.jpg')
    #image = mpimg.imread('camera_cal/calibration1.jpg')
    undist_image = undistort(image)
    side_by_side_plot(im1=image, im2=undist_image, im1_title="Original Image", im2_title="Undistorted Image")