예제 #1
0
def main():
    """main"""
    args = parse_arguments()

    output_image_path = Path(args.output_dir).joinpath("camera_images")
    output_gaze_path = Path(args.output_dir).joinpath("gazemap_images")
    output_image_path.mkdir(parents=True, exist_ok=True)
    output_gaze_path.mkdir(parents=True, exist_ok=True)
    input_dirs = [Path(input_dir) for input_dir in args.input_dirs]

    naming_data = init_naming_data(args.naming)

    print("Reading scenarios...")
    scenario_index = get_scenario_start_index(naming_data)
    num_previous_scenarios = scenario_index - 1
    scenario_groups = []
    for input_dir in input_dirs:
        image_files = get_files_with_suffix(input_dir, args.suffix)
        json_files = get_files_with_suffix(input_dir, config.LABELME_SUFFIX)
        scenario_grouper = ScenarioGrouper(
            scenario_index,
            input_dir.name,
            args.image_topics,
            image_files,
            json_files,
        )
        if not image_files:
            print(
                "Could not find any image files in scenario %s with %s extension. "
                "Make sure you set the corrent suffix with --suffix." %
                (scenario_grouper.scenario_name, args.suffix),
                file=sys.stderr,
            )
            sys.exit(1)
        if not scenario_grouper.is_valid:
            print(
                "Images of scenario %s are not aligned or of same length for topics %s.\n"
                "Run merge.py with --reindex to align your files" %
                (scenario_grouper.scenario_name, args.image_topics),
                file=sys.stderr,
            )
            sys.exit(1)
        if FileGrouper.is_empty(scenario_grouper.image_groups):
            print(
                "None of the image files for scenario %s is matching a topic in %s"
                % (scenario_grouper.scenario_name, args.image_topics),
                file=sys.stderr,
            )
            sys.exit(1)
        scenario_groups.append(scenario_grouper)
        scenario_index += 1

    print("Write %s" % config.MVROI_NAMING_FILE)
    naming_data = append_naming_data(scenario_groups, naming_data)
    write_json(
        Path(args.output_dir).joinpath(config.MVROI_NAMING_FILE), naming_data)

    for scenario_group in tqdm(scenario_groups, desc="Preparing scenarios..."):
        size = prepare_scenario_group_images(scenario_group, output_image_path)
        prepare_scenario_group_gazemaps(scenario_group, size, output_gaze_path)
예제 #2
0
 def test_is_empty__all_empty__true(self):
     test_group = FileGrouper.group_files_by_keys([], ["test"])
     self.assertTrue(FileGrouper.is_empty(test_group))