コード例 #1
0
ファイル: demo_lattice.py プロジェクト: amiller/blockplayer
def once():
    if not FOR_REAL:
        dataset.advance()
        global depth
        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

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

    # Compute the surface normals
    normals.normals_opencl(depth, mask, rect)

    # Find the lattice orientation and then translation
    global R_oriented, R_aligned, R_correct
    R_oriented = lattice.orientation_opencl()
    R_aligned = lattice.translation_opencl(R_oriented)

    global modelmat
    if modelmat is None:
        modelmat = R_aligned.copy()
    else:
        modelmat,_ = grid.nearest(modelmat, R_aligned)

    global face, Xo, Yo, Zo
    _,_,_,face = np.rollaxis(opencl.get_modelxyz(),1)
    Xo,Yo,Zo,_ = np.rollaxis(opencl.get_xyz(),1)

    global cx,cy,cz
    cx,cy,cz,_ = np.rollaxis(np.frombuffer(np.array(face).data,
                                           dtype='i1').reshape(-1,4),1)
    R,G,B = [np.abs(_).astype('f') for _ in cx,cy,cz]

    window.update_xyz(Xo,Yo,Zo,COLOR=(R,G,B,R*0+1))

    window.clearcolor = [1,1,1,0]
    window.Refresh()
    pylab.waitforbuttonpress(0.005)
コード例 #2
0
def once():
    if not FOR_REAL:
        dataset.advance()
        global depth
        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

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

    # Compute the surface normals
    normals.normals_opencl(depth, mask, rect)

    # Find the lattice orientation and then translation
    global R_oriented, R_aligned, R_correct
    R_oriented = lattice.orientation_opencl()
    R_aligned = lattice.translation_opencl(R_oriented)

    global modelmat
    if modelmat is None:
        modelmat = R_aligned.copy()
    else:
        modelmat, _ = grid.nearest(modelmat, R_aligned)

    global face, Xo, Yo, Zo
    _, _, _, face = np.rollaxis(opencl.get_modelxyz(), 1)
    Xo, Yo, Zo, _ = np.rollaxis(opencl.get_xyz(), 1)

    global cx, cy, cz
    cx, cy, cz, _ = np.rollaxis(
        np.frombuffer(np.array(face).data, dtype='i1').reshape(-1, 4), 1)
    R, G, B = [np.abs(_).astype('f') for _ in cx, cy, cz]

    window.update_xyz(Xo, Yo, Zo, COLOR=(R, G, B, R * 0 + 1))

    window.clearcolor = [1, 1, 1, 0]
    window.Refresh()
    pylab.waitforbuttonpress(0.005)
コード例 #3
0
ファイル: demo_flatrot.py プロジェクト: amiller/blockplayer
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
    try:
        (mask, rect) = preprocess.threshold_and_mask(depth, config.bg)
    except IndexError:
        return

    normals.opencl.set_rect(rect)
    normals.normals_opencl(depth, mask, rect).wait()

    # Find the lattice orientation and then translation
    global R_oriented, R_aligned, R_correct
    R_oriented = lattice.orientation_opencl()

    if "R_correct" in globals():
        # Correct the lattice ambiguity for 90 degree rotations just by
        # using the previous estimate. This is good enough for illustrations
        # but global alignment is preferred (see hashalign)
        R_oriented, _ = grid.nearest(R_correct, R_oriented)

    R_aligned = lattice.translation_opencl(R_oriented)
    R_correct = R_aligned

    # Find the color based on the labeling from lattice
    global face, Xo, Yo, Zo
    _, _, _, face = np.rollaxis(opencl.get_modelxyz(), 1)

    global cx, cy, cz
    cx, cy, cz, _ = np.rollaxis(np.frombuffer(np.array(face).data, dtype="i1").reshape(-1, 4), 1) - 1
    global R, G, B
    R, G, B = [np.abs(_).astype("f") for _ in cx, cy, cz]
    if 0:
        G *= 0
        R *= 0
        B *= 0
    else:
        pass

    # Draw the points collected on a sphere
    nw = normals.opencl.get_normals()
    global n, w
    n, w = nw[:, :, :3], nw[:, :, 3]

    if 1:  # Point cloud position mode
        X, Y, Z, _ = np.rollaxis(opencl.get_xyz(), 1)
    else:
        X, Y, Z = n[:, :, 0], n[:, :, 1], n[:, :, 2]
        X, Y, Z = map(lambda _: _.copy(), (X, Y, Z))

    # Render the points in 'table space' but colored with the axes from flatrot
    window.update_xyz(X, Y, Z, COLOR=(R, G * 0, B, R * 0 + w.flatten()))
    window.clearcolor = [1, 1, 1, 0]
    window.Refresh()
    # pylab.imshow(1./depth)
    pylab.waitforbuttonpress(0.01)
コード例 #4
0
ファイル: demo_flatrot.py プロジェクト: theY4Kman/blockplayer
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
    try:
        (mask, rect) = preprocess.threshold_and_mask(depth, config.bg)
    except IndexError:
        return

    normals.opencl.set_rect(rect)
    normals.normals_opencl(depth, mask, rect).wait()

    # Find the lattice orientation and then translation
    global R_oriented, R_aligned, R_correct
    R_oriented = lattice.orientation_opencl()

    if 'R_correct' in globals():
        # Correct the lattice ambiguity for 90 degree rotations just by
        # using the previous estimate. This is good enough for illustrations
        # but global alignment is preferred (see hashalign)
        R_oriented, _ = grid.nearest(R_correct, R_oriented)

    R_aligned = lattice.translation_opencl(R_oriented)
    R_correct = R_aligned

    # Find the color based on the labeling from lattice
    global face, Xo, Yo, Zo
    _, _, _, face = np.rollaxis(opencl.get_modelxyz(), 1)

    global cx, cy, cz
    cx, cy, cz, _ = np.rollaxis(
        np.frombuffer(np.array(face).data, dtype='i1').reshape(-1, 4), 1) - 1
    global R, G, B
    R, G, B = [np.abs(_).astype('f') for _ in cx, cy, cz]
    if 0:
        G *= 0
        R *= 0
        B *= 0
    else:
        pass

    # Draw the points collected on a sphere
    nw = normals.opencl.get_normals()
    global n, w
    n, w = nw[:, :, :3], nw[:, :, 3]

    if 1:  # Point cloud position mode
        X, Y, Z, _ = np.rollaxis(opencl.get_xyz(), 1)
    else:
        X, Y, Z = n[:, :, 0], n[:, :, 1], n[:, :, 2]
        X, Y, Z = map(lambda _: _.copy(), (X, Y, Z))

    # Render the points in 'table space' but colored with the axes from flatrot
    window.update_xyz(X, Y, Z, COLOR=(R, G * 0, B, R * 0 + w.flatten()))
    window.clearcolor = [1, 1, 1, 0]
    window.Refresh()
    #pylab.imshow(1./depth)
    pylab.waitforbuttonpress(0.01)