def connect_db_inserter(self):
        self.couch = couchdb.Server(self.options.db_root)

        self.db = dbtools.init_object_databases(self.couch)
        sessions = self.db

        session = models.Session()
        session.object_id = "various"
        session.bag_id = "none"
        session.store(self.db)

        session_id = session.id
        print("Session id: " + session_id)
        object_id = "test_object_id"
        db_params = args_to_db_params(self.options)

        db_inserter = ObservationInserter(
            "db_inserter", object_id=object_id,
            session_id=session_id, db_params=db_params)

        self.graph += [
            self.observation_renderer['depth'] >> db_inserter['depth'],
            self.observation_renderer['R', 'T'] >> db_inserter['R', 'T'],
            self.observation_renderer['mask'] >> db_inserter['mask'],
            self.observation_renderer['image'] >> db_inserter['image'],
            self.id_dispatcher['object_id'] >> db_inserter['object_id'],
            self.image_ci['K'] >> db_inserter['K'],
        ]
def handles_object_add(req):
    print "Object Name:", req.name
    obj = models.Object(object_name=req.name, description=req.description)
    couch = couchdb.Server(DEFAULT_DB_ROOT)
    db = dbtools.init_object_databases(couch)
    objects = db
    existing = models.Object.by_object_name(objects, key=obj.object_name)
    store_new = True
    print('*****************test****************************.')
    if len(existing) > 0:
        print('It appears that there are %d object(s) with the same name.' %
              len(existing))
        for x in existing:
            print(x)
            print('Use the object id above? [y,n]')
            use_it = raw_input('')
            if 'y' in use_it.lower():
                store_new = False
                obj = x
                break
    else:
        store_new = True
    if store_new:
        obj.store(objects)
        print('Stored new object with id:', obj.id)
        print('Use the --commit option to commit the proposed change.')
    newObj_ID = obj.id
    return objAddResponse(newObj_ID)
Exemple #3
0
def handles_object_delete(req):
    couch = couchdb.Server(DEFAULT_DB_ROOT)
    db = dbtools.init_object_databases(couch)
    deletion_view(db)
    #delete_object(db, req.id, req.commit)
    del db[req.id]
    print('just kidding. --commit to actually do it.')
    return objDeleteResponse()
Exemple #4
0
def handles_mesh_add(req):
    #args = parse_args()

    couch = couchdb.Server(DEFAULT_DB_ROOT)
    db = dbtools.init_object_databases(couch)
    # dbtools.upload_mesh(db, args.object_id, args.mesh_original, cloud_path=None, mesh_path=None)
    # dbtools.upload_mesh(db, req.id, req.path, cloud_path=None, mesh_path=None)
    dbtools.upload_mesh(db, req.id, req.path, cloud_path=None, mesh_path=None)
    print('Stored mesh for object id :', req.id)
    print('Use the --commit option to commit the proposed change.')
    return meshAddResponse()
def handles_training(req):
    parser = create_parser(do_training=True)

    #args = parser.parse_args()
    args = parser.parse_args(['-c', req.cmd])
    args = parser.parse_args(['--config_file', req.path])
    ork_params, _args = read_arguments(args)

    for _pipeline_id, pipeline_param in ork_params.iteritems():
        pipeline_class = find_class([ pipeline_param['module'] ], pipeline_param['type'] )
        if not pipeline_class:
            raise RuntimeError('Invalid pipeline name: %s\nMake sure that the pipeline type is defined by a '
                               'TrainingPipeline class, in the name class function.' % pipeline_param['type'])

        db_params_raw = pipeline_param['parameters'].get('json_db', {})
        db_params = db_params_raw
        object_ids = interpret_object_ids(db_params, pipeline_param.get('parameters', {}).get('json_object_ids', []))
        print('Training %d objects.' % len(object_ids))
        for object_id in object_ids:
            print('computing object_id: %s' % object_id)
            object_id = object_id.encode('ascii')

            ork_params_sub = {}
            ork_params_sub[_pipeline_id] = pipeline_param
            ork_params_sub[_pipeline_id]['parameters']['object_id'] = object_id
            plasm = create_plasm(ork_params_sub)
            plasm.execute()

        # Make sure the views exist
        object_db = ObjectDb(db_params)
        db_params = ObjectDbParameters(db_params)
        if db_params.type == ObjectDbTypes.COUCHDB:
            import couchdb
            import json
            dic = json.loads(db_params_raw)
            couch = couchdb.Server(dic['root'])
            init_object_databases(couch)
	
    return training_srvResponse()
Exemple #6
0
def handles_object_search(req):
    couch = couchdb.Server(DEFAULT_DB_ROOT)
    db = dbtools.init_object_databases(couch)
    results = models.Object.by_object_name(db)
    name_list = []
    id_list = []
    description_list = []
    num = len(results)
    for obj in results:
        print "******************************"
        print "Object Name:", obj.object_name
        print "Object ID:", obj.id
        name_list.append(obj.object_name)
        id_list.append(obj.id)
        description_list.append(obj.description)
    return objSearchResponse(name_list, id_list, description_list, num)
Exemple #7
0
    parser.add_argument('-t',
                        '--tag',
                        metavar='TAG',
                        dest='tag',
                        type=str,
                        default='',
                        help='Tag to search for.')
    dbtools.add_db_arguments(parser)
    args = parser.parse_args()
    return args


if __name__ == "__main__":
    args = parse_args()
    couch = couchdb.Server(args.db_root)
    db = dbtools.init_object_databases(couch)
    if len(args.tag) > 0:
        results = models.Object.by_tag(db, key=args.tag)
    else:
        results = models.Object.by_object_name(db)
    rospack = rospkg.RosPack()
    fname = rospack.get_path(
        'apc_object_detection') + '/config/object_ids.yaml'
    target = open(fname, 'w')
    target.truncate()
    target.write("apc:\n  objects:\n")

    for obj in results:
        print "******************************"
        print "Object Name:", obj.object_name
        #print "Description:", obj.description
import object_recognition_core
from object_recognition_core.db import tools as dbtools, models
import couchdb
import argparse

def parse_args():
    parser = argparse.ArgumentParser(description='Search for an objects in the DB based on tags..')
    parser.add_argument('-t', '--tag', metavar='TAG', dest='tag', type=str, default='',
                       help='Tag to search for.')
    dbtools.add_db_arguments(parser)
    args = parser.parse_args()
    return args

if __name__ == "__main__":
    args = parse_args()
    couch = couchdb.Server(args.db_root)
    db = dbtools.init_object_databases(couch)
    if len(args.tag) > 0:
        results = models.Object.by_tag(db, key=args.tag)
    else:
        results = models.Object.by_object_name(db)
    for obj in results:
        print "******************************"
        print "Object Name:", obj.object_name
        print "Description:", obj.description
        print "Tags:", ','.join(obj.tags)
        print "Author:", obj.author_name
        print "email:", obj.author_email
        print "db id:", obj.id
        print "session ids:", [session.id for session in models.Session.by_object_id(db, key=obj.id)]
    #create a list of tuples, so that they can be sorted by frame number
    obs_tuples = [ (obs.frame_number, obs.id) for obs in results]
    # sort by frame_number, helps preserve chronological order
    obs_ids = zip(*sorted(obs_tuples, key=lambda obs: obs[0]))[1]
    return obs_ids

def find_model_for_object(models_collection, object_id, model_type='all'):
    ''' Finds all of the models associated with the given object_id
    The type of the model can be specified through model_type
    '''
    #run the view, keyed on the object id.
    if not Model.by_object_id_and.has_key(model_type):
        return []
    r = Model.by_object_id_and[model_type](models_collection, key=object_id)

    if len(r) == 0 : return []
    return [ m.id for m in r ]

def objects_by_name(objects_collection, object_name):
    r = Object.by_object_name(objects_collection, key=object_name)
    if len(r) == 0 : return []
    return r

if __name__ == "__main__":
    couch = couchdb.Server(DEFAULT_DB_ROOT)
    dbs = init_object_databases(couch)
    obj = Object(object_id="TestObject", object_name="A test object.", description="test objects are fun.", tags=['test', 'object', 'tod'])
    obj.store(dbs['objects'])
    print obj
    print dbs
Exemple #10
0
def find_model_for_object(models_collection, object_id, model_type='all'):
    ''' Finds all of the models associated with the given object_id
    The type of the model can be specified through model_type
    '''
    #run the view, keyed on the object id.
    if not Model.by_object_id_and.has_key(model_type):
        return []
    r = Model.by_object_id_and[model_type](models_collection, key=object_id)

    if len(r) == 0: return []
    return [m.id for m in r]


def objects_by_name(objects_collection, object_name):
    r = Object.by_object_name(objects_collection, key=object_name)
    if len(r) == 0: return []
    return r


if __name__ == "__main__":
    couch = couchdb.Server(DEFAULT_DB_ROOT)
    dbs = init_object_databases(couch)
    obj = Object(object_id="TestObject",
                 object_name="A test object.",
                 description="test objects are fun.",
                 tags=['test', 'object', 'tod'])
    obj.store(dbs['objects'])
    print obj
    print dbs