def test():
    image = mpimg.imread('./test_images/test1.jpg')
    draw_image = np.copy(image)
    image = image.astype(np.float32)*255  
    windows = slide_window(image, x_start_stop=[None, None], y_start_stop=[350, None], 
                        xy_window=(96, 96), xy_overlap=(0.5, 0.5))
    hot_windows = search_windows(image, windows, svc, X_scaler, color_space=color_space, 
                            spatial_size=spatial_size, hist_bins=hist_bins, 
                            orient=orient, pix_per_cell=pix_per_cell, 
                            cell_per_block=cell_per_block, 
                            hog_channel=hog_channel, spatial_feat=spatial_feat, 
                            hist_feat=hist_feat, hog_feat=hog_feat)                       
    window_img = draw_boxes(draw_image, hot_windows, color=(0, 0, 255), thick=6)                    
    plt.imshow(window_img)
def test_image():
    
    
    img = mpimg.imread('./test_images/test6.jpg')
    rectangles = []
    
    scale = 1.0
    y_start_stop = [350, 700] 
    x_start_stop = [None, None] 
    rectangles.append(find_cars(img, x_start_stop, y_start_stop, scale ,color_space, svc, 
                                X_scaler, orient, pix_per_cell, cell_per_block, spatial_size, hist_bins ,show_all_rectangles=False))

    scale = 1.5
    y_start_stop = [400, None] 
    x_start_stop = [None, None]
    rectangles.append(find_cars(img, x_start_stop, y_start_stop, scale ,color_space, svc, 
                                X_scaler, orient, pix_per_cell, cell_per_block, spatial_size, hist_bins,show_all_rectangles=False))
    
    scale = 2.0
    y_start_stop = [450, None] 
    x_start_stop = [None, None]    
    rectangles.append(find_cars(img, x_start_stop, y_start_stop, scale ,color_space, svc, 
                                X_scaler, orient, pix_per_cell, cell_per_block, spatial_size, hist_bins,show_all_rectangles=False))    

    scale = 2.5
    y_start_stop = [500, None] 
    x_start_stop = [None, None]    
    rectangles.append(find_cars(img, x_start_stop, y_start_stop, scale ,color_space, svc, 
                                X_scaler, orient, pix_per_cell, cell_per_block, spatial_size, hist_bins,show_all_rectangles=False))
    
    # apparently this is the best way to flatten a list of lists
    rectangles = [item for sublist in rectangles for item in sublist] 
    test_img_rects = draw_boxes(img, rectangles, color=(0, 0, 255), thick=2)
    plt.figure(figsize=(10,10))
    plt.imshow(test_img_rects)
    
    heatmap_img = np.zeros_like(img[:,:,0])
    heatmap_img = add_heat(heatmap_img, rectangles)
    heatmap_img = apply_threshold(heatmap_img, 1)
    plt.figure(figsize=(10,10))
    plt.imshow(heatmap_img, cmap='hot')
    
    labels = label(heatmap_img)
    plt.figure(figsize=(10,10))
    plt.imshow(labels[0], cmap='gray')
    
    draw_img = draw_labeled_bboxes(img, labels)
    plt.figure(figsize=(10,10))
    plt.imshow(draw_img)
Beispiel #3
0
def decodeFrame(image, image_w, image_h, model, yhat, imageRead):
    
    boxes = list()
    for i in range(len(yhat)):

        boxes += dF.decode_netout(yhat[i][0], anchors[i], propability, input_h, input_w)


    dF.correct_yolo_boxes(boxes, image_h, image_w, input_h, input_w)

    dF.do_nms(boxes, 0.5) 
    
    v_boxes, v_labels, v_scores = f.get_boxes(boxes, labels, propability)

    imageFinal = f.draw_boxes(imageRead, v_boxes, v_labels, v_scores, 0.5)
    return imageFinal
Beispiel #4
0
def decodeFrame(image, image_w, image_h, model, yhat, imageFile):

    boxes = list()
    for i in range(len(yhat)):
        # Decodeer de bounding boxes (de rechthoekjes om het herkende heen)
        boxes += dF.decode_netout(yhat[i][0], anchors[i], propability, input_h,
                                  input_w)

    # Zet de shape en size van de boxes weer om naar het originele plaatje ipv het 416x416  plaatje
    dF.correct_yolo_boxes(boxes, image_h, image_w, input_h, input_w)

    dF.do_nms(
        boxes, 0.5
    )  # zorg ervoor dat overlappende bounding boxes weg gehaald worden( 0.5 staat voor bounding boxes die 50% over een komen)

    v_boxes, v_labels, v_scores = f.get_boxes(boxes, labels, propability)

    f.br()
    print("Die tensorflow error net:")
    print(
        "'WARNING:tensorflow:No training configuration found in the save file, so the model was *not* compiled. Compile it manually.'"
    )
    print("Is niks ergs, maak geen zorgen")
    f.br()

    # eventjes de aparte boxen printen
    for i in range(len(v_boxes)):

        print(v_labels[i], v_scores[i])

    imageFinal = f.draw_boxes(imageFile, v_boxes, v_labels, v_scores, 0.5)

    print(imageFinal)

    cv2.imshow("window", imageFinal)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

    cv2.imwrite(imageFile[:-4] + '_detected' + imageFile[-4:],
                (imageFinal).astype('uint8'))
Beispiel #5
0
cars = list()
fps = 1

try:
    while True:

        beginning = time.time()  #For FPS calculations

        _, frame = video_capture.read()
        if frame is None:
            sess.close()
            exit("End of video file!")

        frame2, boxes, scores = detect_objects(frame, sess, detection_graph)
        #boxes : [upper-y, upper-x, lower-y, lower-x] : float percentage of image resolution

        functions.track_cars(boxes, scores, cars, width, height, fps)

        if args.display == "y":
            functions.draw_boxes(cars, frame2)
            cv2.imshow('image', frame2)
            cv2.waitKey(1)

        num_cars = functions.persistence(cars, width, height)

        fps = 1 / (time.time() - beginning)
        print("FPS:", fps)

except KeyboardInterrupt:
    print('interrupted!')
Beispiel #6
0
                                           windows,
                                           svc,
                                           X_scaler,
                                           color_space=color_space,
                                           spatial_size=spatial_size,
                                           hist_bins=hist_bins,
                                           orient=orient,
                                           pix_per_cell=pix_per_cell,
                                           cell_per_block=cell_per_block,
                                           hog_channel=hog_channel,
                                           spatial_feat=spatial_feat,
                                           hist_feat=hist_feat,
                                           hog_feat=hog_feat)

    window_img = functions.draw_boxes(draw_img,
                                      hot_windows,
                                      color=(0, 0, 255),
                                      thick=6)
    images.append(window_img)
    titles.append('')
    print(round(time.time() - t1, 2), "seconds to process one image searching",
          len(windows), "windows.")

fig = plt.figure(figsize=(17, 18))  #, dpi=300)
functions.visualize(fig, 3, 2, images, titles)

# CALCULATE HOG FEATURES ONLY ONCE

out_images = []
out_maps = []
out_titles = []
out_boxes = []
Beispiel #7
0
        boxes = Predictor.boxes.get()
        edgearray = Predictor.boxes.get()
        video_frame = Predictor.boxes.get()

        if boxes is None:
            exit()
            #with open("fps.log", "a") as myfile: #Write fps to file for logging
            #    myfile.write(str(args.gen_threads)+
            #                 " "+str(args.pred_threads)+
            #                 " "+str(256/(time.time()-bbeginning))+
            #                 "\n")
            #exit(256/(time.time()-bbeginning))

        fps = 1 / (time.time() - beginning)
        print("FPS: ", int(fps))

        network.sendBoxes(video_frame, boxes)

        if args.visualize == 'y':
            frame = draw_boxes(boxes, edgearray)
            cv2.imshow('image', frame)
            cv2.imshow('edgemap', edgearray)
            cv2.imshow('original', video_frame)
            cv2.waitKey(10)

        frames = frames + 1
        total_fps = total_fps + fps

except KeyboardInterrupt:
    exit()
Beispiel #8
0
fig4.savefig('./examples/car_notcar_hog.jpg')

image = mpimg.imread('./test_images/test1.jpg')
window_size = 64
search_boxes = [(1, 0, 199, 400, 530), (1.5, 200, 399, 400, 600),
                (2, 400, 599, 400, 700), (2.5, 600, 799, 400, 700),
                (3, 800, 999, 400, 700)]
for scale, xstart, xstop, ystart, ystop in search_boxes:
    windows = slide_window(image,
                           x_start_stop=[xstart, xstop],
                           y_start_stop=[ystart, ystop],
                           xy_window=(int(scale * window_size),
                                      int(scale * window_size)),
                           xy_overlap=(0, 0))

    image = draw_boxes(image, windows, color=(0, 0, 255), thick=6)
plt.imsave('./examples/sliding_windows.jpg', image)

search_boxes = [(1, 400, 530), (1.5, 400, 600), (2, 400, 700), (2.5, 400, 700),
                (3, 400, 700)]
test_images = glob.glob('./test_images/test*.jpg')

fig1 = plt.figure(figsize=(8, 12))
fig2 = plt.figure(figsize=(8, 18))
fig3 = plt.figure(figsize=(8, 12))
for idx, file in enumerate(test_images):
    img = mpimg.imread(file)
    total_heat = np.zeros_like(img[:, :, 0]).astype(np.float)
    for scale, ystart, ystop in search_boxes:
        bbox_list = find_cars(img,
                              colorspace,
    hist_bins=for_pickle['hist_bins']
    orient=for_pickle['orient']
    pix_per_cell=for_pickle['pix_per_cell']
    cell_per_block=for_pickle['cell_per_block']
    hog_channel=for_pickle['hog_channel']
    spatial_feat=for_pickle['spatial_feat']
    hist_feat=for_pickle['hist_feat']
    hog_feat=for_pickle['hog_feat']
    
    show_scalar=True
    #test_img_bgr = cv2.imread('./test_images/test1.jpg')
    #
    #test_img = convert_color(test_img_bgr,color_space='RGB')
    ffc,axfc=plt.subplots(1,2)
    test_img = mpimg.imread('../test_images/test1.jpg')
    print("img shape",test_img.shape)
    ystart = 400
    ystop = 656
    scale = 1.5

    print("spatial enabled:",spatial_feat,"Hist enabled:",hist_feat)
    bbox = find_cars(test_img, ystart, ystop, scale, color_space, hog_channel, svc, 
                     X_scaler, orient, pix_per_cell, cell_per_block, spatial_size, hist_bins,spatial_feat,hist_feat,axfc=axfc,show_scalar=show_scalar)

    
    print(len(bbox), 'bboxes found in image')
    
    show_scalar=False
    im_bbox=draw_boxes(test_img, bbox, color=(0, 0, 255), thick=6)
    f,p=plt.subplots()
    p.imshow(im_bbox)
    # combine all heatmaps
    heatmap = heatmap_far + heatmap_middle + heatmap_near

    # apply threshold to the heatmap
    heatmap = functions.apply_threshold(heatmap, threshold)
    # apply labels to the heatmap
    labels = label(heatmap)
    # draw labels on an image copy
    labeled_image = functions.draw_labeled_bboxes(draw_img, labels)

    # Sum up all windows that were searched
    searched_windows = searched_windows_far + searched_windows_middle + searched_windows_near

    # Draw boxes in the image around all hot windows
    window_img = functions.draw_boxes(draw_img, windows, color=(0, 255, 0), thick=6)

    # Append titles for all 4 version of the image
    titles.append(img_src[-12:])
    titles.append(img_src[-12:])
    titles.append(img_src[-12:])
    titles.append(img_src[-12:])

    # Append Images with windows to image list
    images.append(window_img)
    # Append Images with windows to image list
    images.append(heatmap)
    # Append Images with labels to image list
    images.append(labels[0])
    # Append Images with labeled boxes to image list
    images.append(labeled_image)