Exemplo n.º 1
0
def generate_pointclouds_in_object_space(dbs, session, args):
    object_name = dbs[session.object_id]['object_name']
    if not os.path.exists(object_name):
        os.mkdir(object_name)
    obs_ids = models.find_all_observations_for_session(dbs, session.id)
    if len(obs_ids) == 0:
        raise RuntimeError("There are no observations available.")
    db_reader = capture.ObservationReader(
        'Database Source', db_params=dbtools.args_to_db_params(args))

    #observation dealer will deal out each observation id.
    observation_dealer = ecto.Dealer(
        tendril=db_reader.inputs.at('observation'), iterable=obs_ids)
    depthTo3d = calib.DepthTo3d('Depth ~> 3D')
    rescale_depth = capture.RescaledRegisteredDepth(
        'Depth scaling')  #this is for SXGA mode scale handling.
    point_cloud_transform = reconstruction.PointCloudTransform(
        'Object Space Transform', do_transform=False
    )  #keeps the points in camera coordinates, but populates the global sensor position and orientatino.
    point_cloud_converter = conversion.MatToPointCloudXYZRGB('To Point Cloud')
    to_ecto_pcl = ecto_pcl.PointCloudT2PointCloud('converter',
                                                  format=ecto_pcl.XYZRGB)
    plasm = ecto.Plasm()
    plasm.connect(observation_dealer[:] >> db_reader['observation'],
                  db_reader['K'] >> depthTo3d['K'],
                  db_reader['image'] >> rescale_depth['image'],
                  db_reader['depth'] >> rescale_depth['depth'],
                  rescale_depth[:] >> depthTo3d['depth'],
                  depthTo3d['points3d'] >> point_cloud_converter['points'],
                  db_reader['image'] >> point_cloud_converter['image'],
                  db_reader['mask'] >> point_cloud_converter['mask'],
                  db_reader['R', 'T'] >> point_cloud_transform['R', 'T'],
                  point_cloud_converter['point_cloud'] >> to_ecto_pcl[:],
                  to_ecto_pcl[:] >> point_cloud_transform['cloud'])
    ply_writer = ecto_pcl.PLYWriter('PLY Saver',
                                    filename_format='%s/cloud_%%05d.ply' %
                                    (object_name))
    pcd_writer = ecto_pcl.PCDWriter('PCD Saver',
                                    filename_format='%s/cloud_%%05d.pcd' %
                                    (object_name))
    plasm.connect(point_cloud_transform['view'] >> (ply_writer['input'],
                                                    pcd_writer['input']))

    if args.visualize:
        global cloud_view
        plasm.connect(
            point_cloud_transform['view'] >> cloud_view,
            db_reader['image'] >> imshows['image'],
            db_reader['depth'] >> imshows['depth'],
            db_reader['mask'] >> imshows['mask'],
        )

    from ecto.opts import run_plasm
    run_plasm(args, plasm, locals=vars())
Exemplo n.º 2
0
def test_dealer(Scheduler):
    print "*" *80
    print __name__, Scheduler
    plasm = ecto.Plasm()
    printer = ecto_test.Printer()
    cards = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    dealer = ecto.Dealer(tendril=printer.inputs.at('in'), iterable=cards)
    plasm.connect(dealer['out'] >> printer['in'])
    sched = Scheduler(plasm)
    sched.execute()
    assert dealer.outputs.at('out').type_name == 'double'
    assert dealer.outputs.out == 10
Exemplo n.º 3
0
def test_fileO(Scheduler, file_like_object, realfile=False):
    global cards, filetext
    plasm = ecto.Plasm()
    printer = ecto_test.FileO(file=ecto.ostream(file_like_object))
    dealer = ecto.Dealer(tendril=printer.inputs.at('input'), iterable=cards)
    plasm.connect(dealer['out'] >> printer['input'])
    sched = Scheduler(plasm)
    sched.execute()

    if not realfile:
        file_like_object.seek(0)
        result = ''.join([x for x in file_like_object])
        print result
        assert result == filetext
Exemplo n.º 4
0
def test_dealer_heterogenous_type_fail(Scheduler):
    print "*" * 80
    print __name__, 'test_dealer_heterogenous_type_fail', Scheduler
    printer = ecto_test.Printer()
    cards = [1, 2, 3, 4, 5, 'hello', 7, 8, 9, 10]
    dealer = ecto.Dealer(tendril=printer.inputs.at('in'), iterable=cards)
    plasm = ecto.Plasm()
    plasm.connect(dealer['out'] >> printer['in'])
    sched = Scheduler(plasm)
    try:
        sched.execute()
        assert False == " Should have thrown."
    except ecto.FailedFromPythonConversion, e:
        print "Threw as expected:", str(e)
        assert re.findall('cpp_typename.*double', str(e))
Exemplo n.º 5
0
 def configure(self, p, i, o):
     self._dealer = ecto.Dealer(tendril=ecto.Tendril(Document()),
                                iterable=p.db_models)
Exemplo n.º 6
0
#!/usr/bin/env python

import ecto
import ecto_test

plasm = ecto.Plasm()
printer = ecto_test.Printer()
cards = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
dealer = ecto.Dealer(tendril=printer.inputs.at('in'), iterable=cards)
plasm.connect(dealer['out'] >> printer['in'])

if __name__ == '__main__':
    Scheduler = ecto.schedulers.Singlethreaded
    sched = Scheduler(plasm)
    sched.execute()
    assert dealer.outputs.at('out').type_name == 'double'
    assert dealer.outputs.out == 10
Exemplo n.º 7
0
args = parse_args()
db = dbtools.init_object_databases(couchdb.Server(args.db_root))

for object_id in args.objects:
    #get a list of observation ids for a particular object id.
    obs_ids = models.find_all_observations_for_object(db, object_id)

    if not obs_ids:
        print 'No observations found for object %s.' % object_id
        continue

    plasm = ecto.Plasm()
    #the db_reader transforms observation id into a set of image,depth,mask,K,R,T
    db_reader = capture.ObservationReader("db_reader", db_params=dbtools.args_to_db_params(args))
    #this iterates over all of the observation ids.
    observation_dealer = ecto.Dealer(tendril=db_reader.inputs.at('observation'), iterable=obs_ids)

    plasm.connect(observation_dealer[:] >> db_reader['observation'])

    path_names = [ 'image', 'depth', 'mask']
    for path_name in path_names:
        path = os.path.join(object_id, path_name)
        if not os.path.exists(path):
            os.makedirs(path)
        writer_image = ImageSaver(filename_format=os.path.join(path, '%05d.png'))[:]
        plasm.connect(db_reader[path_name] >> (writer_image, imshow(name=path_name)['image']))

    sched = ecto.schedulers.Singlethreaded(plasm)
    sched.execute()

    # write files listing the produced files
Exemplo n.º 8
0
 def declare_io(self, p, i, o):
     self.db_reader = ObservationReader(db_params=p.db_params)
     self.observation_dealer = ecto.Dealer(
         tendril=self.db_reader.inputs.at('observation'),
         iterable=p.observation_ids)
     o.forward_all('db_reader')