示例#1
0
def create_layout_data(image_topics, images_per_row, width, height):
    """
    Create layout data to calculate ROI position for individual frames
    :param image_topics:
    :param images_per_row:
    :param width:
    :param height:
    :return:
    """
    data = {"layout": []}
    x_count = 0
    y_count = 0
    for topic in image_topics:
        if x_count == images_per_row:
            y_count += 1
            x_count = 0

        data["layout"].append(
            ImageLayoutModel.create(topic,
                                    x=x_count * width,
                                    y=y_count * height,
                                    width=width,
                                    height=height).image_layout)
        x_count += 1

    data["width"] = images_per_row * width
    data["height"] = height + height * y_count

    return data
示例#2
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)
                )
            )
示例#3
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
示例#4
0
    def test_is_inside__not_inside__false(self):
        unit = ImageLayoutModel(TEST_LAYOUT_SINGLE["layout"][0])

        self.assertFalse(unit.is_inside(15, 5))  # y outside
        self.assertFalse(unit.is_inside(5, 25))  # x outside
        self.assertFalse(unit.is_inside(15, 25))  # both outside
示例#5
0
 def test_is_inside__inside__true(self):
     unit = ImageLayoutModel(TEST_LAYOUT_SINGLE["layout"][0])
     self.assertTrue(unit.is_inside(5, 5))
示例#6
0
    def test_create__equal_to_test_layout(self):
        expected = TEST_LAYOUT_SINGLE["layout"][0]
        unit = ImageLayoutModel.create("front", 0, 0, 10, 15)

        self.assertEqual(expected, unit.image_layout)
示例#7
0
    def test_properties__test_layout__correct_coordinates(self):
        unit = ImageLayoutModel(TEST_LAYOUT_SINGLE["layout"][0])

        self.assertEqual((0, 0, 10, 15), unit.box)
        self.assertEqual("front", unit.key)
        self.assertEqual((0, 0), unit.top_left)
示例#8
0
 def test_is_shape_inside__nothing_inside__false(self):
     result = geometry.is_shape_inside(
         self.TEST_SHAPES["shapes"][0],
         ImageLayoutModel.create("", 0, 0, 5, 5))
     self.assertFalse(result)
示例#9
0
 def test_is_shape_inside__circle_point_inside__false(self):
     result = geometry.is_shape_inside(
         self.TEST_SHAPES["shapes"][0],
         ImageLayoutModel.create("", 25, 35, 100, 100))
     self.assertFalse(result)
示例#10
0
 def test_is_shape_inside__center_inside__true(self):
     result = geometry.is_shape_inside(
         self.TEST_SHAPES["shapes"][0],
         ImageLayoutModel.create("", 0, 0, 25, 35))
     self.assertTrue(result)