コード例 #1
0
def get_homography_info_config_file(robot_name):
    strict = False
    roots = [
        os.path.join(dtu.get_duckiefleet_root(), 'calibrations'),
        os.path.join(dtu.get_ros_package_path('duckietown'), 'config',
                     'baseline', 'calibration')
    ]

    found = []
    for df in roots:
        # Load camera information
        fn = os.path.join(df, 'camera_extrinsic', robot_name + '.yaml')
        fn_default = os.path.join(df, 'camera_extrinsic', 'default.yaml')
        if os.path.exists(fn):
            found.append(fn)
            dtu.logger.info("Using filename %s" % fn)
        elif os.path.exists(fn_default):
            found.append(fn_default)
            dtu.logger.info("Using filename %s" % fn_default)

    if len(found) == 0:
        msg = 'Cannot find homography file for robot %r;\n%s' % (robot_name,
                                                                 roots)
        raise NoHomographyInfoAvailable(msg)
    elif len(found) == 1:
        return found[0]
    else:
        msg = 'Found more than one configuration file: \n%s' % "\n".join(found)
        msg += "\n Please delete one of those."
        if strict:
            raise Exception(msg)
        else:
            dtu.logger.error(msg)
            return found[0]
コード例 #2
0
ファイル: io.py プロジェクト: bdura/merganser
def get_homography_info_config_file(robot_name, strict=False):
    roots = [
        os.path.join(dtu.get_duckiefleet_root(), 'calibrations'),
        os.path.join(dtu.get_ros_package_path('duckietown'),
                     'config', 'baseline', 'calibration')
    ]
    found = []

    for root in roots:
        fn = os.path.join(root, 'camera_extrinsic', '{0}.yaml')
        for name in [robot_name, 'default']:
            filename = fn.format(name)
            if os.path.exists(filename):
                found.append(filename)
                dtu.logger.info('Using filename {0}'.format(filename))

    if not found:
        raise NoHomographyInfoAvailable('Cannot find homography file for robot '
                                        '`{0}` in folders\n{1}'.format(
                                        robot_name, '\n'.join(roots)))
    else:
        if len(found) > 1:
            error_message = ('Found more than one configuration file:\n{0}\n'
                             'Please delete one of those'.format('\n'.join(found)))
            if strict:
                raise Exception(error_message)
            else:
                dtu.logger.error(error_message)
        return found[0]
コード例 #3
0
ファイル: db_yaml.py プロジェクト: yuanjun5681/Software
def get_unique_filename(rt_name, rdbe):
    commit = rdbe.commit[-8:]
    d = rdbe.date.replace('-', '')
    basename = rt_name + '_%s_%s_%s.rdbe.yaml' % (d, rdbe.branch, commit)

    dr = dtu.get_ros_package_path('easy_regression')
    filename = os.path.join(dr, 'db', rt_name, basename)
    return filename
コード例 #4
0
ファイル: configuration.py プロジェクト: frank-qcd-qk/dt-core
def load_configuration_for_nodes_in_package(package_name):
    """
        returns dict node_name -> config
    """
    suffix = '.easy_node.yaml'
    package_dir = dtu.get_ros_package_path(package_name)
    configs = dtu.locate_files(package_dir, '*' + suffix)
    res = {}
    for c in configs:
        node_name = os.path.basename(c).replace(suffix, '')
        res[node_name] = load_configuration_package_node(
            package_name, node_name)
    return res
コード例 #5
0
ファイル: camera_info.py プロジェクト: yuanjun5681/Software
def get_camera_info_config_file(robot_name):
    roots = [os.path.join(dtu.get_duckiefleet_root(), 'calibrations'),
             os.path.join(dtu.get_ros_package_path('duckietown'), 'config', 'baseline', 'calibration')]

    for df in roots:
    # Load camera information
        fn = os.path.join(df, 'camera_intrinsic', robot_name + '.yaml')
        if os.path.exists(fn):
            return fn
        else:
            print('%s does not exist' % fn)

    msg = 'Cannot find intrinsic file for robot %r;\n%s' % (robot_name, roots)
    raise NoCameraInfoAvailable(msg)
コード例 #6
0
ファイル: configuration.py プロジェクト: frank-qcd-qk/dt-core
def load_configuration_package_node(package_name, node_type_name):
    path = dtu.get_ros_package_path(package_name)
    look_for = '%s.easy_node.yaml' % node_type_name
    found = dtu.locate_files(path, look_for)
    if not found:
        msg = 'Could not find EasyNode configuration %r.' % look_for
        raise dtu.DTConfigException(msg)  # XXX

    fn = found[0]
    contents = open(fn).read()
    c = load_configuration(fn, contents)
    c = c._replace(package_name=package_name)
    c = c._replace(node_type_name=node_type_name)

    # Add the common parameters
    if node_type_name != 'easy_node':
        c0 = load_configuration_baseline()
        c = merge_configuration(c0, c)

    return c
コード例 #7
0
def find_cmds_to_shortcut():
    package2dir = dtu.get_list_of_packages_in_catkin_ws()
    for package, src in package2dir.items():

        src = dtu.get_ros_package_path(package)

        cmd = ['find', src, '-type', 'f', '-executable']

        res = dtu.system_cmd_result(cwd='.', cmd=cmd, display_stdout=False, display_stderr=False,
                                    raise_on_error=True)

        filenames = [x for x in res.stdout.strip().split('\n') if x]

        for fn in filenames:
            data = open(fn).read()
            if tag in data:
                b = os.path.basename(fn)
                desc = None
                yield Script(package=package, script=b, desc=desc, filename=fn)
            else:
                pass
                dtu.logger.debug('ignoring %s' % fn)
コード例 #8
0
def load_board_info(filename=None):
    '''Load calibration checkerboard info'''
    if filename is None:
        root = dtu.get_ros_package_path('duckietown')
        filename = root + '/config/baseline/ground_projection/ground_projection/default.yaml'

    if not os.path.isfile(filename):
        msg = 'No such file: %s' % filename
        raise dtu.DTException(msg)

    target_data = dtu.yaml_load_file(filename)
    target_info = {
        'width': target_data['board_w'],
        'height': target_data['board_h'],
        'square_size': target_data['square_size'],
        'x_offset': target_data['x_offset'],
        'y_offset': target_data['y_offset'],
        'offset': np.array([target_data['x_offset'],
                            -target_data['y_offset']]),
        'size': (target_data['board_w'], target_data['board_h']),
    }
    dtu.logger.info("Loaded checkerboard parameters")
    return target_info
コード例 #9
0
def examine_dataset(dirname, out):
    logger.info(dirname)
    dirname = dtu.expand_all(dirname)

    jpgs = dtu.locate_files(dirname, '*.jpg')
    mats = dtu.locate_files(dirname, '*.mat')

    logger.debug('I found %d JPGs and %d .mat.' % (len(jpgs), len(mats)))

    if len(jpgs) == 0:
        msg = 'Not JPGs found in %r.' % dirname
        raise ValueError(msg)


#     if len(mats) == 0:
#         msg = 'Not enough mats.'
#         raise ValueError(msg)

    first_jpg = sorted(jpgs)[0]
    logger.debug('Using jpg %r to learn transformation.' % first_jpg)

    first_jpg_image = dtu.image_cv_from_jpg_fn(first_jpg)

    success, health, parameters = calculate_transform(first_jpg_image)

    s = ""
    s += 'success: %s\n' % str(success)
    s += 'health: %s\n' % str(health)
    s += 'parameters: %s\n' % str(parameters)
    w = os.path.join(out, 'learned_transform.txt')
    with open(w, 'w') as f:
        f.write(s)
    logger.info(s)

    transform = ScaleAndShift(**parameters)

    duckietown_package_dir = dtu.get_ros_package_path('duckietown')
    config_dir = os.path.join(
        duckietown_package_dir,
        'config/baseline/line_detector/line_detector_node')

    if not os.path.exists(config_dir):
        msg = 'Could not find configuration dir %s' % config_dir
        raise Exception(msg)

    config_dir = dtu.expand_all(config_dir)
    configurations = dtu.locate_files(config_dir, '*.yaml')

    if not configurations:
        msg = 'Could not find any configuration file in %s.' % config_dir
        raise Exception(msg)
    #logger.info('configurations: %r' % configurations)

    for j in jpgs:
        summaries = []

        shape = (200, 160)
        interpolation = cv2.INTER_NEAREST

        bn = os.path.splitext(os.path.basename(j))[0]
        fn = os.path.join(out, '%s.all.png' % (bn))

        if os.path.exists(fn):
            logger.debug('Skipping because file exists: %r' % fn)
        else:
            for c in configurations:
                logger.info('Trying %r' % c)
                name = os.path.splitext(os.path.basename(c))[0]
                if name in ['oreo', 'myrtle', 'bad_lighting', '226-night']:
                    continue
                with open(c) as f:
                    stuff = yaml.load(f)

                if not 'detector' in stuff:
                    msg = 'Cannot find "detector" section in %r' % c
                    raise ValueError(msg)

                detector = stuff['detector']
                logger.info(detector)
                if not isinstance(detector, list) and len(detector) == 2:
                    raise ValueError(detector)

                def LineDetectorClass():
                    return dtu.instantiate(detector[0], detector[1])

                s = run_detection(transform,
                                  j,
                                  out,
                                  shape=shape,
                                  interpolation=interpolation,
                                  name=name,
                                  LineDetectorClass=LineDetectorClass)
                summaries.append(s)

            together = dtu.make_images_grid(summaries, cols=1, pad=10)
            cv2.imwrite(fn, dtu.zoom_image(together, 4))

    overall_results = []
    comparison_results = {}
    for m in mats:
        logger.debug(m)
        jpg = os.path.splitext(m)[0] + '.jpg'
        if not os.path.exists(jpg):
            msg = 'JPG %r for mat %r does not exist' % (jpg, m)
            logger.error(msg)
        else:
            frame_results = test_pair(transform, jpg, m, out)
            comparison_results[m] = frame_results
            overall_results = merge_comparison_results(comparison_results[m],
                                                       overall_results)
            print "comparison_results[m]=frame_results"

    print "finished mats: " + dirname
    return overall_results