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())
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())
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']))
return args 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()