Пример #1
0
def record(filename=None):
    opennpy.align_depth_to_rgb()
    if filename is None:
        filename = str(np.random.rand())

    foldername = 'data/sets/%s/' % filename
    dataset.folder = foldername

    os.mkdir(foldername)
    shutil.copytree('data/newest_calibration/config', '%s/config' % foldername)
    print "Created new dataset: %s" % foldername

    frame = 0
    try:
        while 1:
            opennpy.sync_update()
            (depth, _) = opennpy.sync_get_depth()
            (rgb, _) = opennpy.sync_get_video()

            np.save('%s/depth_%05d.npy' % (foldername, frame), depth)

            cv.CvtColor(rgb, rgb, cv.CV_RGB2BGR)
            cv.SaveImage('%s/rgb_%05d.png' % (foldername, frame), rgb)

            if frame % 30 == 0:
                print 'frame: %d' % frame
            frame = frame + 1
    except KeyboardInterrupt:
        print "Captured %d frames" % frame
        compress()
Пример #2
0
def start(dset=None, frame_num=0):
    main.initialize()

    if not FOR_REAL:
        if dset is None:
            dataset.load_random_dataset()
        else:
            dataset.load_dataset(dset)
        while dataset.frame_num < frame_num:
            dataset.advance()

        name = dset
        name = os.path.split(name)[1]
        custom = os.path.join('data/sets/', name, 'gt.txt')
        if os.path.exists(custom):
            # Try dataset directory first
            fname = custom
        else:
            import re
            # Fall back on generic ground truth file
            match = re.match('.*_z(\d)m_(.*)', name)
            number = int(match.groups()[0])
            fname = 'data/experiments/gt/gt%d.txt' % number

        with open(fname) as f:
            GT = grid.gt2grid(f.read())
        grid.initialize_with_groundtruth(GT)

    else:
        config.load('data/newest_calibration')
        opennpy.align_depth_to_rgb()
        dataset.setup_opencl()
Пример #3
0
def run_calib():
    close('all')
    """Run the table plane calibration
    """
    global points, depth
    print("Getting an image from the camera")
    opennpy.align_depth_to_rgb()
    for i in range(10):
        opennpy.sync_update()
        depth, _ = opennpy.sync_get_depth()

    fig = figure(1)
    clf()
    points = []

    def pick(event):
        global points
        points.append((event.xdata, event.ydata))
        print('Picked point %d of 4' % (len(points)))

    #imshow(depth)
    imshow(1. / depth)
    draw()
    fig.canvas.mpl_disconnect('button_press_event')
    fig.canvas.mpl_connect('button_press_event', pick)

    print("Click four points")
    while len(points) < 4:
        waitforbuttonpress(0.001)

    print 'OK'
    np.save('%s/config/boundpts' % (newest_folder), points)
    np.save('%s/config/depth' % (newest_folder), depth)

    finish_table_calib()
Пример #4
0
def record(filename=None):
    opennpy.align_depth_to_rgb()
    if filename is None:
        filename = str(np.random.rand())

    foldername = 'data/sets/%s/' % filename
    dataset.folder = foldername

    os.mkdir(foldername)
    shutil.copytree('data/newest_calibration/config', '%s/config' % foldername)
    print "Created new dataset: %s" % foldername

    frame = 0
    try:
        while 1:
            opennpy.sync_update()
            (depth,_) = opennpy.sync_get_depth()
            (rgb,_) = opennpy.sync_get_video()

            np.save('%s/depth_%05d.npy' % (foldername,frame), depth)

            cv.CvtColor(rgb, rgb, cv.CV_RGB2BGR)
            cv.SaveImage('%s/rgb_%05d.png' % (foldername,frame), rgb)

            if frame % 30 == 0:
                print 'frame: %d' % frame
            frame = frame + 1
    except KeyboardInterrupt:
        print "Captured %d frames" % frame
        compress()
Пример #5
0
def run_calib():
    close('all')
    """Run the table plane calibration
    """
    global points, depth
    print("Getting an image from the camera")
    opennpy.align_depth_to_rgb()
    for i in range(10):
        opennpy.sync_update()
        depth, _ = opennpy.sync_get_depth()

    fig = figure(1)
    clf()
    points = []

    def pick(event):
        global points
        points.append((event.xdata, event.ydata))
        print('Picked point %d of 4' % (len(points)))

    #imshow(depth)
    imshow(1./depth)
    draw()
    fig.canvas.mpl_disconnect('button_press_event')
    fig.canvas.mpl_connect('button_press_event', pick)

    print("Click four points")
    while len(points) < 4:
        waitforbuttonpress(0.001)

    print 'OK'
    np.save('%s/config/boundpts' % (newest_folder), points)
    np.save('%s/config/depth' % (newest_folder), depth)

    finish_table_calib()
Пример #6
0
def start(dset=None, frame_num=0):
    main.initialize()

    if not FOR_REAL:
        if dset is None:
            dataset.load_random_dataset()
        else:
            dataset.load_dataset(dset)
        while dataset.frame_num < frame_num:
            dataset.advance()

        name = dset
        name = os.path.split(name)[1]
        custom = os.path.join('data/sets/', name, 'gt.txt')
        if os.path.exists(custom):
            # Try dataset directory first
            fname = custom
        else:
            import re
            # Fall back on generic ground truth file
            match = re.match('.*_z(\d)m_(.*)', name)            
            number = int(match.groups()[0])
            fname = 'data/experiments/gt/gt%d.txt' % number

        with open(fname) as f:
            GT = grid.gt2grid(f.read())
        grid.initialize_with_groundtruth(GT)

    else:
        config.load('data/newest_calibration')
        opennpy.align_depth_to_rgb()
        dataset.setup_opencl()
Пример #7
0
def preview(cams):
    opennpy.align_depth_to_rgb()
    opennpy.sync_update()
    global depth_cache
    for cam in cams:
        (depth,_) = opennpy.sync_get_depth(cam)
        print(depth.shape)
        print "Depth aligned:", is_aligned(depth)
        depth_cache.append(np.array(depth))
        depth_cache = depth_cache[-6:]
        show_depth('depth_%d'%cam, depth)
Пример #8
0
def start(dset=None, frame_num=0):
    main.initialize()
    if not FOR_REAL:
        if dset is None:
            dataset.load_random_dataset()
        else:
            dataset.load_dataset(dset)
        while dataset.frame_num < frame_num:
            dataset.advance()
    else:
        config.load('data/newest_calibration')
        opennpy.align_depth_to_rgb()
        dataset.setup_opencl()
Пример #9
0
 def block_setup(self):
     """Initialize blockplayer stuff"""
     glxcontext.makecurrent()
     main.initialize()
     
     config.load('data/newest_calibration')
     opennpy.align_depth_to_rgb()
     dataset.setup_opencl()
     
     self.blocks = None
     self.block_loop_quit = False
     self.block_initialized = True
     self.block_loop()
Пример #10
0
def start(dset=None, frame_num=0):
    main.initialize()
    if not FOR_REAL:
        if dset is None:
            dataset.load_random_dataset()
        else:
            dataset.load_dataset(dset)
        while dataset.frame_num < frame_num:
            dataset.advance()
    else:
        config.load('data/newest_calibration')
        opennpy.align_depth_to_rgb()
        dataset.setup_opencl()
def run_calib():
    config.load('data/newest_calibration')
    opennpy.align_depth_to_rgb()

    samples = []

    for i in arange(0,2*np.pi,np.pi/8): 
        line = line_through_point(center, i)
        draw_line_XZ(line)
        pylab.waitforbuttonpress(0.1)
        for _ in range(60):
            opennpy.sync_update()
            rgb, _ = opennpy.sync_get_video()
            depth, _ = opennpy.sync_get_depth()
        samples.append((line, rgb, depth))

    return samples
Пример #12
0
def start(dset=None, frame_num=0):
    main.initialize()

    #with open('data/experiments/collab/2011.txt') as f:
    global target_model
    with open('data/experiments/collab/block.txt') as f:
        target_model = grid.gt2grid(f.read())
    #grid.initialize_with_groundtruth(GT)

    if not FOR_REAL:
        if dset is None:
            dataset.load_random_dataset()
        else:
            dataset.load_dataset(dset)
        while dataset.frame_num < frame_num:
            dataset.advance()
    else:
        config.load('data/newest_calibration')
        opennpy.align_depth_to_rgb()
        dataset.setup_opencl()
def start():
    main.initialize()
    config.load('data/newest_calibration')
    opennpy.align_depth_to_rgb()
    dataset.setup_opencl()
Пример #14
0
def record(filename=None, cams=(0,), do_rgb=False):
    if len(cams) > 1 and do_rgb:
        print """You're trying to record from 2+ kinects with RGB and depth.
        This probably will not work out for you, but it depends on if you have
        enough USB bandwidth to support all four streams. Call record with 
        do_rgb=False to turn off rgb."""
    q = multiprocessing.Queue(10000)
    p = multiprocessing.Process(target=worker, args=(q,))
    p.start()
        
    opennpy.align_depth_to_rgb()
    if filename is None:
        filename = str(time.time())

    foldername = KINECT_PATH + '%s' % filename
    dataset.folder = foldername
    try:
        os.makedirs(foldername)
    except OSError:
        pass
    #shutil.copytree('data/newest_calibration/config', '%s/config' % foldername)
    print "Created new dataset: %s" % foldername
    min_delay = 1
    frame = 0
    frame_md5s = {}
    frame_last_update = {}
    def check_frame(name, cam, frame_data):
        frame_md5 = hashlib.md5(frame_data).digest()
        key = '%s:%d' % (name, cam)
        if frame_md5s.get(key) == frame_md5:
            #print('Kinect [%s] is repeating data, likely crashed...' % key)
            last_update = frame_last_update.get(key)
            if last_update is None or (time.time() - last_update) > 10.:
                return 'die'
        else:
            frame_last_update[key] = time.time()
            frame_md5s[key] = frame_md5
            return 'new'

    def die():
        q.put(None)

    while 1:
        print('')
        st = time.time()
        opennpy.sync_update()
        for cam in cams:
            (depth,_) = opennpy.sync_get_depth(cam)
            ret = check_frame('depth', cam, depth.tostring())
            if ret == 'die':
                return die()
            elif ret == 'new':
                q.put(('%s/depth_%f_%05d_%d.snappy' % (foldername,st,frame,cam), depth.tostring()))
            if do_rgb:
                (rgb,_) = opennpy.sync_get_video(cam)
                ret = check_frame('rgb', cam, rgb.tostring())
                if ret == 'die':
                    return die()
                elif ret == 'new':
                    rgb = cv2.cvtColor(rgb, cv.CV_RGB2BGR)
                    q.put(('%s/rgb_%f_%05d_%d.ppm' % (foldername,st,frame,cam), rgb))

        if frame % 30 == 0:
            print 'frame: %d' % frame
        cur_time = time.time()
        print({k: cur_time - v for k, v in frame_last_update.items()})
        frame = frame + 1
        sleep_time = max(0, min_delay - (time.time() - st))
        #time.sleep(sleep_time)
        print('Time: %f' % (time.time() - st,))
Пример #15
0
import numpy as np
import pylab
import opennpy


from blockplayer import calibkinect
from blockplayer import config
from blockplayer import preprocess

if config.ALIGNED:
    opennpy.align_depth_to_rgb()

from blockplayer.visuals.pointwindow import PointWindow
global window
if not 'window' in globals():
    window = PointWindow(title='demo_calib', size=(640,480))

mat = np.linalg.inv(calibkinect.aligned_projection())
mat = np.ascontiguousarray(mat)

PREPROCESS = True


def once():
    global depth
    global rgb
    opennpy.sync_update()
    depth,_ = opennpy.sync_get_depth()
    rgb,_ = opennpy.sync_get_video()

    global x,y,z,xyz
Пример #16
0
def go(cams=(0,)):
    opennpy.align_depth_to_rgb()
    while 1:
        preview(cams)
        pylab.waitforbuttonpress(0.005)
from OpenGL.GL import *
from OpenGL.GLUT import *
import numpy as np
from rtmodel import mesh
from rtmodel import camera
from wxpy3d import Window
from wxpy3d.opengl_state import opengl_state
import opennpy
import calibkinect
import cv
import scipy.ndimage
import os
import cPickle as pickle

opennpy.align_depth_to_rgb(); opennpy.sync_update()
np.set_printoptions(2)


"""
My best guess for the intrinsic calibration values for the dell projector are:
KK = [[2460, 0, 1152/2],
      [0, 2460, 863],
      [0, 0, 1]]

This is based on measuring the focal length with a tape measure, averaging
between my measurements for X and Y. Assume the principal point is at the bottom
and pixels are square.
      
"""

if not 'window' in globals():
Пример #18
0
def go():
    opennpy.align_depth_to_rgb()
    while 1:
        preview()
        pylab.waitforbuttonpress(0.005)
Пример #19
0
import opennpy

a = opennpy.sync_get_depth()
b = opennpy.sync_get_video()
opennpy.align_depth_to_rgb()
a = opennpy.sync_get_depth()
b = opennpy.sync_get_video()