Exemplo n.º 1
0
def run_normals():
    global ds
    ds = []

    try:
        shutil.rmtree(out_path)
    except:
        pass
    os.mkdir(out_path)

    for i in range(1):
        dataset.load_random_dataset()
        dataset.advance()

        name = 'dataset_%s' % str(i)
        d = dict(name=name)
        folder = os.path.join(out_path, name)
        os.mkdir(folder)

        depthL = dataset.depthL.astype('f')
        pylab.figure(0)
        pylab.clf()
        pylab.imshow(depthL)
        pylab.savefig(os.path.join(folder,'depth.jpg'))

        dt = timeit.timeit(lambda: normals.normals_numpy(depthL),
                           number=1)
        d['numpy'] = dt
        n,w = normals.normals_numpy(depthL)
        pylab.clf()
        show_normals(n, w)
        pylab.savefig(os.path.join(folder,'normals_numpy.jpg'))

        dt = timeit.timeit(lambda: normals.normals_c(depthL),
                           number=1)
        d['c'] = dt
        n,w = normals.normals_c(depthL)
        pylab.clf()
        show_normals(n, w)
        pylab.savefig(os.path.join(folder,'normals_c.jpg'))

        rect = ((0,0),(640,480))
        mask = np.zeros((480,640),'bool')
        mask[1:-1,1:-1] = 1
        normals.opencl.set_rect(rect, ((0,0),(0,0)))
        dt = timeit.timeit(lambda:
                        normals.normals_opencl(depthL, mask, rect).wait(),
                           number=1)
        d['opencl'] = dt
        nw,_ = normals.opencl.get_normals()
        n,w = nw[:,:,:3], nw[:,:,3]
        pylab.clf()
        show_normals(n,w)
        pylab.savefig(os.path.join(folder,'normals_opencl.jpg'))

        ds.append(d)
Exemplo n.º 2
0
def once():
    global depth
    if not FOR_REAL:
        dataset.advance()
        depth = dataset.depth
    else:
        opennpy.sync_update()
        depth,_ = opennpy.sync_get_depth()

    def from_rect(m,rect):
        (l,t),(r,b) = rect
        return m[t:b,l:r]

    global mask, rect, modelmat
    (mask,rect) = preprocess.threshold_and_mask(depth,config.bg)

    global n,w
    if 0:
        n,w = normals.normals_numpy(depth)
        show_normals(n, w, 'normals_numpy')

    if 0:
        n,w = normals.normals_c(depth)
        show_normals(n, w, 'normals_c')

    if 1:
        normals.opencl.set_rect(rect)
        dt = timeit.timeit(lambda:
                           normals.normals_opencl(depth, mask, rect).wait(),
                           number=1)

        #print dt
        nw = normals.opencl.get_normals()
        n,w = nw[:,:,:3], nw[:,:,3]
        #show_normals(n, w, 'normals_opencl')
        show_normals_sphere(n, w)

    pylab.waitforbuttonpress(0.01)
Exemplo n.º 3
0
def once():
    global depth
    if not FOR_REAL:
        dataset.advance()
        depth = dataset.depth
    else:
        opennpy.sync_update()
        depth, _ = opennpy.sync_get_depth()

    def from_rect(m, rect):
        (l, t), (r, b) = rect
        return m[t:b, l:r]

    global mask, rect, modelmat
    (mask, rect) = preprocess.threshold_and_mask(depth, config.bg)

    global n, w
    if 0:
        n, w = normals.normals_numpy(depth)
        show_normals(n, w, 'normals_numpy')

    if 0:
        n, w = normals.normals_c(depth)
        show_normals(n, w, 'normals_c')

    if 1:
        normals.opencl.set_rect(rect)
        dt = timeit.timeit(
            lambda: normals.normals_opencl(depth, mask, rect).wait(), number=1)

        #print dt
        nw = normals.opencl.get_normals()
        n, w = nw[:, :, :3], nw[:, :, 3]
        #show_normals(n, w, 'normals_opencl')
        show_normals_sphere(n, w)

    pylab.waitforbuttonpress(0.01)