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 read_arguments(parser=None, argv=sys.argv): """ Returns: params, pipeline_params, db_dict, db params: all the pipeline parameters specified in the config file or command line pipeline_params: an array of parameters for each pipeline db_dict: the dictionary of the db parameters db: a db object created from those parameters """ if parser is None: parser = ObjectRecognitionParser() parser.add_argument('-c', '--config_file', help='Config file') parser.add_argument('--object_ids', help='If set, it overrides the list of object_ids in the config file') parser.add_argument('--object_names', help='If set, it overrides the list of object names in the config file') parser.add_argument('--visualize', help='If set, it will display some windows with temporary results', default=False, action='store_true') dbtools.add_db_options(parser) try: import ecto_ros ecto_ros.strip_ros_args(argv) except: pass if '--help' in sys.argv or '-h' in sys.argv: args = parser.parse_args() else: args = parser.parse_args()#args=argv) # define the input if args.config_file is None or not os.path.exists(args.config_file): print >>sys.stderr, "The option file does not exist. --help for usage." sys.exit(-1) params = yaml.load(open(args.config_file)) # read some parameters db_params = args_to_db_params(args, params.get('db', {})) # initialize the DB db = dbtools.db_params_to_db(db_params) # read the object_ids object_ids = set() for obj in (args.__dict__, params): ids = obj.get('object_ids', None) names = obj.get('object_names', None) if 'all' in (ids, names): object_ids = set([ str(x.id) for x in models.Object.all(db) ]) #unicode without the str() break if 'missing' in (ids, names): tmp_object_ids = set([ str(x.id) for x in models.Object.all(db) ]) tmp_object_ids_from_names = set([ str(x.object_id) for x in models.Model.all(db) ]) object_ids.update(tmp_object_ids.difference(tmp_object_ids_from_names)) if ids and ids != 'missing': object_ids.update(ids[1:-1].split(',')) if names and names != 'missing': for object_name in names[1:-1].split(','): object_ids.update([str(x.id) for x in models.objects_by_name(db, object_name)]) # if we got some ids through the command line, just stop here if object_ids: break object_ids = list(object_ids) params['object_ids'] = object_ids pipeline_params = [] for key , value in params.iteritems(): if key.startswith('pipeline'): pipeline_params.append(value) args = vars(args) return params, args, pipeline_params, args['visualize'], db_params
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()
def read_arguments(parser=None, argv=sys.argv): """ Returns: params, pipeline_params, db_dict, db params: all the pipeline parameters specified in the config file or command line pipeline_params: an array of parameters for each pipeline db_dict: the dictionary of the db parameters db: a db object created from those parameters """ if parser is None: parser = ObjectRecognitionParser() parser.add_argument('-c', '--config_file', help='Config file') parser.add_argument( '--object_ids', help='If set, it overrides the list of object_ids in the config file') parser.add_argument( '--object_names', help='If set, it overrides the list of object names in the config file' ) parser.add_argument( '--visualize', help='If set, it will display some windows with temporary results', default=False, action='store_true') dbtools.add_db_options(parser) try: import ecto_ros ecto_ros.strip_ros_args(argv) except: pass if '--help' in sys.argv or '-h' in sys.argv: args = parser.parse_args() else: args = parser.parse_args() #args=argv) # define the input if args.config_file is None or not os.path.exists(args.config_file): print >> sys.stderr, "The option file does not exist. --help for usage." sys.exit(-1) params = yaml.load(open(args.config_file)) # read some parameters db_params = args_to_db_params(args, params.get('db', {})) # initialize the DB db = dbtools.db_params_to_db(db_params) # read the object_ids object_ids = set() for obj in (args.__dict__, params): ids = obj.get('object_ids', None) names = obj.get('object_names', None) if 'all' in (ids, names): object_ids = set([str(x.id) for x in models.Object.all(db) ]) #unicode without the str() break if 'missing' in (ids, names): tmp_object_ids = set([str(x.id) for x in models.Object.all(db)]) tmp_object_ids_from_names = set( [str(x.object_id) for x in models.Model.all(db)]) object_ids.update( tmp_object_ids.difference(tmp_object_ids_from_names)) if ids and ids != 'missing': object_ids.update(ids[1:-1].split(',')) if names and names != 'missing': for object_name in names[1:-1].split(','): object_ids.update([ str(x.id) for x in models.objects_by_name(db, object_name) ]) # if we got some ids through the command line, just stop here if object_ids: break object_ids = list(object_ids) params['object_ids'] = object_ids pipeline_params = [] for key, value in params.iteritems(): if key.startswith('pipeline'): pipeline_params.append(value) args = vars(args) return params, args, pipeline_params, args['visualize'], db_params