Exemple #1
0
def scale():
    max_depth = 6.0
    cam = camera.Camera(max_depth = max_depth)
    source = './Camera/Sample_Data/random_stuff'
    d, c = getFramesFromSource(source)
    d_small = cam.reduceFrame(d, height_ratio = 1, sub_sample = 0.3, reduce_to = 'lower')
    print('Size of d_small = ({0}, {1})'.format(len(d_small), len(d_small[0])))

    # figsize = width, height
    figsize = (9, 2.5)

    fig = plt.figure(figsize = figsize)
    plt.subplot(1, 3, 1)
    plt.imshow(c)
    plt.title('Color Image')
    plt.grid()

    plt.subplot(1, 3, 2)
    plt.imshow(d, cmap='gist_rainbow')
    plt.title('Original Depth Matrix')
    plt.grid()

    plt.subplot(1, 3, 3)
    plt.imshow(d_small, cmap='gist_rainbow')
    # plt.colorbar(fraction = 0.046, pad = 0.04)
    plt.title('Scaled Depth Matrix (30%)')
    plt.grid()

    plt.subplots_adjust(wspace = 0.3)

    plt.show()
Exemple #2
0
    def __init__(self):

        self.model = face_model.FaceModel(
            args, ctx=mx.cpu()
        )  #face model initialization. when to use gpu, set ctx = mx.gpu(args.gpu)
        self.db = face_db.Database()  #Database initialization
        self.camera = camera.Camera(camera_address=0)  #Webcam initialization
        self.camera.run()  #start camera
        self.time = datetime.datetime.now().strftime('%Y%m%d-%H%M%S')
        print("current time is: ", self.time)  #print demo start time
    def __init__(self):

        self.model = face_model.FaceModel(args, ctx=mx.cpu())
        self.db = face_db.Database()
        self.camera = camera.Camera(
            url='http://aham_demo_raspi1.com.ngrok.io/?action=snapshot')
        self.camera.picam_run()
        #self.camera = camera.Camera(camera_address=0)
        #self.camera.run()
        self.time = datetime.datetime.now().strftime('%Y%m%d-%H%M%S')
        print("current time is: ", self.time)
def main():
    ######################### set up image processing
    max_depth = 6.0
    cam = camera.Camera(max_depth=max_depth)
    try:
        cam.connect()
        print('Connected to R200 camera')
    except:
        print('Cannot connect to camera')
        pass
    source = cam
    time.sleep(2.5)
    
    numFrames = 5
    # height_ratio of 1 keeps all rows of original image
    # default of h_r = 0.5, s_s = 0.3
    height_ratio = 1
    sub_sample = 1
    # reduce_to argFalseument can be: 'lower', 'middle_lower', 'middle', 'middle_upper', and 'upper'
    reduce_to = 'middle'
    # default of perc_samples = 0.01
    perc_samples = 0.05
    iters = 3
    min_dist = 1.0

    print('Program settings:')
    print('\tsource: ' + str(source))
    print('\tmax_depth: ' + str(max_depth))
    print('\tnumFrames: ' + str(numFrames))
    print('\theight_ratio: ' + str(height_ratio))
    print('\tsub_sample: ' + str(sub_sample))
    print('\treduce_to: ' + reduce_to)
    print('\tperc_samples: ' + str(perc_samples))
    print('\titers: ' + str(iters))
    print('\tmin_dist: ' + str(min_dist))

    #########################
    while True:
        avoidObs(cam, numFrames, height_ratio, sub_sample, reduce_to, perc_samples, iters, min_dist)
Exemple #5
0
def interp_comp():
    from Algorithms import create_samples
    from Algorithms import voronoi
    from Algorithms import rbf_interpolation

    max_depth = 6.0
    perc_samples = 0.01
    cam = camera.Camera(max_depth = max_depth)
    source = './Camera/Sample_Data/random_stuff'
    d, c = getFramesFromSource(source)
    d_small = cam.reduceFrame(d, height_ratio = 1, sub_sample = 0.3, reduce_to = 'lower')

    samples, vec = create_samples.createSamples(d_small, perc_samples)
    voronoi = voronoi.getVoronoi(d_small.shape, samples, vec)
    linear = rbf_interpolation.interpolate(d_small.shape, samples, vec, ftype='linear')

    figsize = (9, 2.5)
    plt.figure(figsize = figsize)

    plt.subplot(1, 3, 1)
    plt.title('Scaled Depth')
    plt.imshow(d_small, cmap='plasma')
    plt.colorbar(fraction = 0.046, pad = 0.04)

    plt.subplot(1, 3, 2)
    plt.title('Natural Neighbor')
    plt.imshow(voronoi, cmap='plasma')
    plt.colorbar(fraction = 0.046, pad = 0.04)

    plt.subplot(1, 3, 3)
    plt.title('Linear RBF')
    plt.imshow(linear, cmap='plasma')
    plt.colorbar(fraction = 0.046, pad = 0.04)

    plt.subplots_adjust(wspace = 0.45)
    plt.show()
Exemple #6
0
def gap_detection():
    import matplotlib.pyplot as plt
    from Algorithms import create_samples as cs
    from Algorithms import voronoi
    from Algorithms import discretize as disc
    from Algorithms import gap_detection as gd
    from Camera import camera
    import os
    
    # height_ratio of 1 keeps all rows of original image
    # default of h_r = 0.5, s_s = 0.3
    height_ratio = 1
    sub_sample = 0.3
    # reduce_to argument can be: 'lower', 'middle_lower', 'middle', 'middle_upper', and 'upper'
    reduce_to = 'middle'
    perc_samples = 0.05
    iters = 3
    min_dist = 1.0
    max_depth = 6.0
    cam = camera.Camera(max_depth = max_depth)

    depth = 0
    c = 0
    source = './Camera/Sample_Data/random_stuff'
    for i, file in enumerate(os.listdir(source)):
        path = os.path.join(source, file)
        frame = np.load(str(path))

        if 'c.npy' in file:
            c = frame
        elif 'd.npy' in file:
            depth = frame

    d_small = cam.reduceFrame(depth, height_ratio = height_ratio, sub_sample = sub_sample, reduce_to = reduce_to)
    samples, measured_vector = cs.createSamples(d_small, perc_samples)
    v = voronoi.getVoronoi(d_small.shape, samples, measured_vector)
    d = disc.depthCompletion(v, iters)

    x = gd.findLargestGap(d, min_dist)
    if x == None:
        print('no gap found')
        x = len(d[0]) // 2
    print('(frac, position) of gap: ({0}, {1})'.format(float(x)/len(d[0]), x))

    plt.figure()
    plt.subplot(1, 2, 1)
    plt.title('Scaled Depth Matrix (30%)')
    plt.imshow(d_small, cmap='plasma')

    plt.subplot(1, 2, 2)
    plt.title('Natural Neighbor')
    plt.imshow(v, cmap='plasma')
    plt.colorbar(fraction = 0.046, pad = 0.04)

    plt.subplots_adjust(wspace = 0.25)

    '''
    '''

    plt.figure()
    plt.subplot(1, 2, 1)
    plt.title('Natural Neighbor')
    plt.imshow(v, cmap='plasma')

    plt.subplot(1, 2, 2)
    plt.title('Discretization, iters = {0}'.format(iters))
    plt.imshow(d, cmap='plasma')
    plt.colorbar(fraction = 0.046, pad = 0.04)

    plt.subplots_adjust(wspace = 0.25)

    '''
    '''

    plt.figure()
    plt.subplot(1, 2, 1)
    plt.imshow(d > min_dist)
    plt.title('Obstacles (Shaded)')
    plt.grid()

    plt.subplot(1, 2, 2)
    plt.imshow(d, cmap='plasma')
    plt.title('Gap Detection')
    plt.colorbar(fraction = 0.046, pad = 0.04)
    plt.plot([x, x], [len(d)-1, 0], 'r-', LineWidth=5)
    plt.plot([x, x], [len(d)-1, 0], 'w-', LineWidth=2)
    
    plt.subplots_adjust(wspace = 0.25)

    '''
    '''

    plt.show()
Exemple #7
0
def main():
    '''
    Tests each algorithm one by one.
    '''
    import sys
    from Camera import camera
    from Algorithms import discretize as disc
    from Algorithms import rbf_interpolation as rbfi
    from Algorithms import voronoi as voro
    from Algorithms import create_samples as cs

    argv = sys.argv
    if len(argv) == 1:
        print('Usage: python {0} [cam|data]'.format(argv[0]))
        exit(1)

    max_depth = 6.0
    cam = camera.Camera(max_depth = max_depth)
    source = None
    if argv[1] == 'cam':
        cam.connect()
        source = cam
        print('Connected to R200 camera')
    elif argv[1] == 'data':
        print('Using data directory for frames')
        source = './Camera/Sample_Data/random_stuff'
    else:
        print('Usage: python {0} [cam|data]'.format(argv[0]))
        exit(1)

    numFrames = 60
    # height_ratio of 1 keeps all rows of original image
    # default of h_r = 0.5, s_s = 0.3
    height_ratio = 1
    sub_sample = 0.3
    # reduce_to argument can be: 'lower', 'middle_lower', 'middle', 'middle_upper', and 'upper'
    reduce_to = 'middle'
    iters = 2
    perc_samples = 0.01

    print('Program settings:')
    print('\tsource: ' + str(source))
    print('\tmax_depth: ' + str(max_depth))
    print('\tnumFrames: ' + str(numFrames))
    print('\theight_ratio: ' + str(height_ratio))
    print('\tsub_sample: ' + str(sub_sample))
    print('\treduce_to: ' + reduce_to)
    print('\titers: ' + str(iters))

    #######################################################
    # test algorithms and plot
    #######################################################
    # sleep to make sure camera starts up
    time.sleep(2.5)
    d, c = getFramesFromSource(source, numFrames)
    d_small = cam.reduceFrame(d, height_ratio = height_ratio, sub_sample = sub_sample, reduce_to = reduce_to)

    # uncomment to plot original image
    fig0 = plt.figure()
    plt.imshow(c)
    plt.title('Color Image')
    plt.grid()
    fig0.show()

    figs = []
    scaledTitle = 'Scaled (height_ratio = {0}, sub_sample = {1})'.format(height_ratio, sub_sample)

    # regular cropping and resizing
    plot2(figs, d, d_small, 'Original', scaledTitle)

    # initial discretization
    t1 = time.time()
    recon = disc.depthCompletion(d_small, iters)
    t2 = time.time()

    print('Time to do disc: ' + str(t2 - t1))
    print('')
    plot2(figs, d_small, recon, scaledTitle, 'Discretization')

    # use when rbf fails
    # raw_input('Press <Enter> to close all plots and exit')
    # return
    
    # radial basis function
    t1 = time.time()
    samples, measured_vector = cs.createSamples(d_small, perc_samples)
    try:
        rbf = rbfi.interpolate(d_small.shape, samples, measured_vector)
    except:
        rbf = d_small
    t2 = time.time()
    rbf_disc = disc.depthCompletion(rbf, iters)
    t3 = time.time()

    print('Time to do RBF: ' + str(t2 - t1))
    plot2(figs, d_small, rbf, scaledTitle, 'RBF')

    print('Time to do RBF and disc: ' + str(t3 - t1))
    print('')
    plot2(figs, d_small, rbf_disc, scaledTitle, 'RBF and disc')

    # Voronoi interpolation
    t1 = time.time()
    samples, measured_vector = cs.createSamples(d_small, perc_samples)
    try:
        v = voro.getVoronoi(d_small.shape, samples, measured_vector)
    except:
        v = d_small
    t2 = time.time()
    voro_disc = disc.depthCompletion(v, iters)
    t3 = time.time()

    print('Time to do Voronoi: ' + str(t2 - t1))
    plot2(figs, d_small, v, scaledTitle, 'Voronoi')

    print('Time to do Voronoi and disc: ' + str(t3 - t1))
    print('')
    plot2(figs, d_small, voro_disc, scaledTitle, 'Voronoi and disc')

    # block plots until button is pressed
    raw_input('Press <Enter> to close all plots and exit')