Ejemplo n.º 1
0
def ObjectDb(db_params):
    """
    Returns the ObjectDb for the given db_params given as a dictionary
    It crawls the object_recognition_core module or any other module
    in order to find the ObjectDb you are looking for

    :param db_params: ObjectDbParameters defining a DB, or json string or dict
    """

    if (isinstance(db_params, ObjectDbParameters)):
        db_params_raw = db_params.raw
        object_db_params = db_params
    elif (isinstance(db_params, str)):
        db_params_raw = json.loads(db_params)
        object_db_params = ObjectDbParameters(db_params)
    else:
        db_params_raw = db_params
        object_db_params = ObjectDbParameters(db_params)

    # check if it is a conventional DB from object_recognition_core
    db_type = db_params_raw.get('type', None)
    if db_type.lower() in core_db_types():
        from object_recognition_core.boost.interface import ObjectDb as ObjectDbCpp
        return ObjectDbCpp(object_db_params)

    # otherwise, look for the possible modules for that DB type
    module = db_params_raw.get('module', None)
    if not module:
        raise RuntimeError(
            "The 'module' property is not set. It is required to find the DB object"
        )
    for db_factory in find_classes([module], [ObjectDbFactory]):
        if db_factory.__name__ == db_type:
            return db_factory.object_db(db_params_raw)
Ejemplo n.º 2
0
 def declare_direct_params(p):
     p.declare('markers_topic',
               'The ROS topic to use for the marker array.', 'markers')
     p.declare('pose_topic', 'The ROS topic to use for the pose array.',
               'poses')
     p.declare('object_ids_topic',
               'The ROS topic to use for the object meta info string',
               'object_ids')
     p.declare('recognized_object_array_topic',
               'The ROS topic to use for the recognized object',
               'recognized_object_array')
     p.declare('latched', 'Determines if the topics will be latched.', True)
     p.declare('db_params', 'The DB parameters', ObjectDbParameters({}))
Ejemplo n.º 3
0
 def declare_direct_params(p):
     p.declare(
         'do_visualize',
         'If True some markers are displayed for visualization. '
         'For RSO Groovy and above, use the RViz plugin instead.', False)
     p.declare('markers_topic',
               'The ROS topic to use for the marker array.', 'markers')
     p.declare('pose_topic', 'The ROS topic to use for the pose array.',
               'poses')
     p.declare('object_ids_topic',
               'The ROS topic to use for the object meta info string',
               'object_ids')
     p.declare('recognized_object_array_topic',
               'The ROS topic to use for the recognized object',
               'recognized_object_array')
     p.declare('latched', 'Determines if the topics will be latched.', True)
     p.declare('db_params', 'The DB parameters', ObjectDbParameters({}))
def args_to_db_params(args, secondary_parameters={}):
    """
    Given command line parsed args, create an ObjectDbParameters object. The keys in args have to be:
    'db_type', 'db_root', 'db_collection'
    Any parameter that is not in the args will be taken from the dictionary secondary_parameters, where the keys are:
    'type', 'url', 'collection'
    """
    dic = {}
    remap_dic = {
        'db_type': 'type',
        'db_root': 'root',
        'db_collection': 'collection'
    }
    for args_key, secondary_key in remap_dic.iteritems():
        if hasattr(args, args_key):
            dic[secondary_key] = getattr(args, args_key)
        if secondary_parameters.has_key(secondary_key):
            dic[secondary_key] = secondary_parameters[secondary_key]
    return ObjectDbParameters(dic)
def interpret_object_ids(db_params, ids=[], names=[]):
    """
    Given db parameters, clean the 'object_ids' field to be a list of object ids
    (as it could be the string 'all')
    """
    db_type = eval(db_params).get('type', '')
    if db_type.lower() not in core_db_types():
        return []

    # initialize the DB
    if isinstance(ids, str) and ids != 'all' and ids != 'missing':
        ids = eval(ids)
    if isinstance(names, str) and names != 'all' and names != 'missing':
        names = eval(names)

    if not ids and not names:
        return []

    object_ids = set()

    db = dbtools.db_params_to_db(ObjectDbParameters(db_params))
    import models
    if 'all' in (ids, names):
        return set([str(x.id) for x in models.Object.all(db)
                    ])  # unicode without the str()
    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)
    if names and names != 'missing':
        for object_name in names:
            object_ids.update(
                [str(x.id) for x in models.objects_by_name(db, object_name)])

    if isinstance(object_ids, set):
        return list(object_ids)
    else:
        return []