コード例 #1
0
    def test_filter_files_for_reindexing__single_group_for_reindexing__correct(
            self):
        test_group = {
            123: [FileModel("front_123.png"),
                  FileModel("rear_123.png")]
        }
        reindex, remove = FileReindexer.filter_files_for_reindexing(
            test_group, self.TEST_KEYS)

        self.assertEqual(test_group[123], reindex[0])
        self.assertFalse(remove)
コード例 #2
0
    def test_filter_files_for_reindexing__two_groups_for_removing__correct(
            self):
        test_group = {
            123: [FileModel("front_123.png")],
            124: [FileModel("rear_124.png")],
        }
        reindex, remove = FileReindexer.filter_files_for_reindexing(
            test_group, self.TEST_KEYS)

        self.assertFalse(reindex)
        self.assertEqual(test_group[123], remove[0])
        self.assertEqual(test_group[124], remove[1])
コード例 #3
0
    def test_get_path_pair_gazemap_groups__single_group_one_file__correct_path_pair(
        self, ):
        result = get_path_pair_gazemap_groups(
            {"10": [FileModel("10_00000.jpg")]}, self.TEST_NAMING, "")

        self.assertEqual(1, len(result))
        self.assertEqual(1, len(result["10"]))
        path_pair = result["10"][0]
        self.assertEqual(Path("10_00000.jpg"), path_pair.source)
        self.assertEqual(Path("test/front_left_000000.jpg"), path_pair.target)
コード例 #4
0
ファイル: split.py プロジェクト: hofbi/mv-roi
def split_images(images_files, layout, output_dir):
    """
    Split images into individuals according to the provided layout
    :param images_files:
    :param layout:
    :param output_dir:
    :return:
    """
    for image_file in tqdm(images_files, desc="Splitting images..."):
        image_file_model = FileModel(image_file)
        image = PIL.Image.open(image_file)
        for image_segment in layout["layout"]:
            layout_model = ImageLayoutModel(image_segment)
            segment = image.crop(layout_model.box)
            segment.save(
                Path(output_dir).joinpath(
                    image_file_model.get_file_name_with_view_key(layout_model.key)
                )
            )
コード例 #5
0
ファイル: split.py プロジェクト: hofbi/mv-roi
def split_json_data(json_files, layout, image_suffix):
    """
    Split json data into individuals according to the provided layout
    :param json_files:
    :param layout:
    :param image_suffix:
    :return:
    """
    files_to_save = []
    for json_file in tqdm(json_files, desc="Splitting json..."):
        json_file_model = FileModel(json_file)
        json_data = read_json(json_file)
        for image_segment in layout["layout"]:
            layout_model = ImageLayoutModel(image_segment)
            segment_data = crop_from_json(json_data, layout_model)
            file_name = json_file_model.get_file_name_with_view_key(layout_model.key)
            segment_data["imagePath"] = Path(file_name).stem + image_suffix
            files_to_save.append((file_name, segment_data))

    return files_to_save
コード例 #6
0
 def test_get_file_by_key__existing_key__correct_file_path(self):
     files_dict = {"front": FileModel("front_00.png")}
     unit = MergeGroup(TEST_LAYOUT_SINGLE, files_dict)
     self.assertEqual("front_00.png",
                      unit.get_file_path_by_key("front").name)
コード例 #7
0
 def test_lt__two_file_models__one_less_than_two(self):
     one = FileModel("a_000.png")
     two = FileModel("a_001.png")
     self.assertLess(one, two)
コード例 #8
0
 def test_get_file_name_with_view_key__different_view_key__key_changed(
         self):
     unit = FileModel("/test/rear_123.json")
     self.assertEqual("front_000123.json",
                      unit.get_file_name_with_view_key("front"))
コード例 #9
0
 def test_get_file_name_with_view_key__own_view_key__correct_index(self):
     unit = FileModel("/test/rear_123.json")
     self.assertEqual("rear_000123.json",
                      unit.get_file_name_with_view_key())
コード例 #10
0
 def test_get_file_name_with_sequence_index__target_suffix_different__suffix_changed(
     self, ):
     unit = FileModel("/test/rear_123.json")
     self.assertEqual("11_00123.png",
                      unit.get_file_name_with_sequence_index("11", ".png"))
コード例 #11
0
 def test_get_file_name_with_sequence_index__index_11__correct_name(self):
     unit = FileModel("/test/rear_123.json")
     self.assertEqual("11_00123.json",
                      unit.get_file_name_with_sequence_index("11"))
コード例 #12
0
 def test_file_model__invalid_name_pattern__exception_raised(self):
     with self.assertRaises(ValueError):
         FileModel("test.json")
コード例 #13
0
 def test_file_model__different_separator__correct_name(self):
     unit = FileModel("/test/rear_left-123.json")
     self.assertEqual("rear_left", unit.topic_name)
     self.assertEqual(123, unit.file_index)
     self.assertEqual(Path("/test/rear_left-123.json"), unit.file_path)
コード例 #14
0
 def test_file_model__valid_file_path__correct_name(self):
     unit = FileModel("/test/rear_123.json")
     self.assertEqual("rear", unit.topic_name)
     self.assertEqual(123, unit.file_index)
     self.assertEqual(Path("/test/rear_123.json"), unit.file_path)
コード例 #15
0
class MergeImagesTest(unittest.TestCase):
    """Merge frames test"""

    TEST_SUFFIX = ".png"
    TEST_KEYS = [
        "front_left",
        "front",
        "front_right",
        "rear_left",
        "rear",
        "rear_right",
    ]
    TEST_LAYOUT_SINGLE = json.loads(
        """{"width": 10, "height": 5, "layout": [{"camera": "front", "location": {"y": 0, "x": 0}}]}"""
    )
    TEST_LAYOUT = json.loads(
        """{"width": 10, "height": 5, "layout": [{"camera": "front_left", "location": {"y": 0, "x": 0}},
        {"camera": "front", "location": {"y": 0, "x": 640}}, {"camera": "front_right", "location": {"y": 0, "x": 1280}},
        {"camera": "rear_left", "location": {"y": 480, "x": 0}}, {"camera": "rear", "location": {"y": 480, "x": 640}},
        {"camera": "rear_right", "location": {"y": 480, "x": 1280}}]}""")
    TEST_MERGE_GROUP = MergeGroup(
        TEST_LAYOUT, {topic: FileModel("key_000.json")
                      for topic in TEST_KEYS})
    TEST_SHAPES = {
        "shapes": [{
            "label": "veh_r",
            "shape_type": "circle",
            "points": [[20, 30], [30, 45.67]],
        }]
    }

    def test_create_layout_data__six_images_two_rows__correct_dimensions(self):
        result = merge.create_layout_data(self.TEST_KEYS, 3, 640, 480)
        self.assertEqual(3 * 640, result["width"])
        self.assertEqual(2 * 480, result["height"])
        self.assertEqual(6, len(result["layout"]))

    def test_create_layout_data__single_image__correct_dimensions(self):
        result = merge.create_layout_data(["front"], 1, 640, 480)
        self.assertEqual(640, result["width"])
        self.assertEqual(480, result["height"])
        self.assertEqual(1, len(result["layout"]))

    def test_create_layout_data__six_images_two_rows__correct_layout(self):
        result = merge.create_layout_data(self.TEST_KEYS, 3, 640, 480)
        for idx, key in enumerate(self.TEST_KEYS):
            self.assertEqual(key, result["layout"][idx]["camera"])

    def test_merge_json__empty_list__empty(self):
        result = merge.merge_json_data([], self.TEST_SUFFIX)
        self.assertFalse(result)

    @patch("builtins.open", new_callable=mock_open, read_data="data")
    @patch("json.loads", MagicMock())
    def test_merge_json__two_elements__size_2(self, _):
        result = merge.merge_json_data(
            [self.TEST_MERGE_GROUP, self.TEST_MERGE_GROUP], self.TEST_SUFFIX)
        self.assertEqual(2, len(result))

    @patch("builtins.open", new_callable=mock_open, read_data="data")
    @patch("json.loads", MagicMock())
    def test_merge_json__one_element__correct_header(self, _):
        result = merge.merge_json_data([self.TEST_MERGE_GROUP],
                                       self.TEST_SUFFIX)[0]

        self.assertEqual(10, int(result["imageWidth"]))
        self.assertEqual(5, int(result["imageHeight"]))
        self.assertEqual("merged_000000.png", result["imagePath"])

    @patch("builtins.open", new_callable=mock_open, read_data="data")
    @patch("json.loads", MagicMock(return_value=copy.deepcopy(TEST_SHAPES)))
    def test_merge_json__one_element__correct_shape_num(self, _):
        result = merge.merge_json_data([self.TEST_MERGE_GROUP],
                                       self.TEST_SUFFIX)[0]
        self.assertEqual(6, len(result["shapes"]))