Пример #1
0
def process_video(img):
    start = time.time()

    history = deque(maxlen=30)

    skimage.io.imsave('c2.PNG', img)
    im2, boxes = test_image('c2.PNG', False)

    skimage.io.imsave('c1.PNG', im2)

    img_lanes = laneDetection('c1.PNG')

    # Iterate through all detected cars

    for b in range(1, boxes[1] + 1):
        # Find pixels with each car_number label value
        nonzero = (boxes[0] == b).nonzero()
        # Identify x and y values of those pixels
        nonzeroy = np.array(nonzero[0])
        nonzerox = np.array(nonzero[1])
        # Append current boxe to history

        history.append([
            np.min(nonzerox),
            np.min(nonzeroy),
            np.max(nonzerox),
            np.max(nonzeroy)
        ])

    # Get recent boxes for the last 30 fps
    r_boxes = np.array(history).tolist()

    # Groups the object candidate rectangles with difference of 10%
    boxes = cv2.groupRectangles(r_boxes, 10, .1)

    # Draw rectangles if found
    if len(boxes[0]) != 0:
        for box in boxes[0]:
            cv2.rectangle(img_lanes, (box[0], box[1]), (box[2], box[3]),
                          (0, 0, 255), 6)

    # Return image with found cars and lanes
    end = time.time()
    elapsed = end - start
    times.append(elapsed)
    return img_lanes
Пример #2
0
#Training the model, uncomment the following 2 lines to train the model from scratch

#model.fit(X_train, Y_train, batch_size=256, epochs=1, verbose=2, validation_data=(X_test, Y_test))
#model.save_weights('./dataset/model1.h5')

#Loading the pretrained weights , approx 2 MB of data
model.load_weights('./dataset/model.h5')

#Testing the model on randon validation images that were splitted from the dataset(10%)
#Keep the function call commented if there is no dataset folder

#test_random(X_test, Y_test, model)

#Testing the model for a bigger image(1280x720) from the folder test_images
img = './test_images/test4.jpg'
cars_img, B = test_image(img, True)
skimage.io.imsave('cars_detected.PNG', cars_img)

lanes_img = laneDetection(img)

plot_img(lanes_img)

#Combining the results of both pipelines by passing the image with cars to lanes function
combined_image = laneDetection('cars_detected.PNG')
plot_img(combined_image)

#This call creats the Video by processing the test video frame by frame
#Comment this line for avoiding the video creation
create_video()

#print('Showing the results from HOG pipeline -- Classical Vision-- \n')
#model.fit(X_train, Y_train, batch_size=256, epochs=1, verbose=2, validation_data=(X_test, Y_test))
#model.save_weights('./dataset/model1.h5')

#Loading the pretrained weights , approx 2 MB of data
model.load_weights('./dataset/model.h5')

#Testing the model on randon validation images that were splitted from the dataset(10%)
#Keep the function call commented if there is no dataset folder

#test_random(X_test, Y_test, model)

#Testing the model for a bigger image(1280x720) from the folder test_images

img = './test_images/test4.jpg'
cars_img, B = test_image(img, False)
#skimage.io.imsave('cars_detected.PNG', cars_img)

#lanes_img = laneDetection(img)

#plot_img(lanes_img)

#Combining the results of both pipelines by passing the image with cars to lanes function
combined_image = laneDetection('cars_detected.PNG')
plot_img(combined_image)

#This call creats the Video by processing the test video frame by frame
#Comment this line for avoiding the video creation
start = time.time()
create_video()
end = time.time()