示例#1
0
    def test_scale__crash_geometry_must_be_a_point_or_line_string__correct(
            self):
        unit = Circle((2, 3), (2, 3))
        unit.scale(2, 2)

        self.assertEqual(4, unit.centroid.x)
        self.assertEqual(6, unit.centroid.y)
class GeneratePseudoLabelTest(unittest.TestCase):
    """Generate Pseudo Label Test"""
    def test_create_pseudo_labels__no_files__empty(self):
        result = generate_pseudo_label.create_pseudo_labels([], 0, 0, 0, 0,
                                                            ".png")
        self.assertFalse(result)

    @patch("PIL.Image.open", MagicMock())
    @patch("annotation.generate_pseudo_label.binarize_image")
    @patch("annotation.generate_pseudo_label.get_roi_circles_from_bin_image")
    @patch("annotation.generate_pseudo_label.get_shapes_from_roi_circles")
    def test_create_pseudo_labels__one_file__correct_image_dimensions_and_label_path(
            self, mock_bin, mock_roi, mock_shapes):
        result = generate_pseudo_label.create_pseudo_labels([Path("test.png")],
                                                            640, 480, 96, 0.05,
                                                            ".png")
        path, data = result[0]

        self.assertEqual(1, len(result))
        self.assertEqual(640, data["imageWidth"])
        self.assertEqual(480, data["imageHeight"])
        self.assertEqual("test.json", path)

        mock_bin.assert_called_once()
        mock_roi.assert_called_once()
        mock_shapes.assert_called_once()

    @patch("PIL.Image.open", MagicMock())
    @patch(
        "annotation.generate_pseudo_label.get_roi_circles_from_bin_image",
        MagicMock(return_value=[
            Circle([10.10, 20], [30, 40]),
            Circle([50, 60], [70, 88.88])
        ]),
    )
    def test_create_pseudo_labels__one_file_with_two_shapes__correct_shapes(
            self):
        result = generate_pseudo_label.create_pseudo_labels([Path("test.png")],
                                                            640, 480, 96, 0.05,
                                                            ".png")[0][1]

        self.assertEqual(2, len(result["shapes"]))
示例#3
0
def create_gazemap_from_shapes(shapes, image_size):
    """
    Create gazemap from ROI shapes
    :param shapes:
    :param image_size:
    :return:
    """
    image = PIL.Image.new(config.GAZEMAP_FORMAT, image_size)
    draw = PIL.ImageDraw.Draw(image)
    for shape in shapes:
        roi = Circle.from_json(shape["points"])
        draw.ellipse(roi.bounding_box, fill=255, outline=255)
    return image
示例#4
0
    def test_scale__downscale__correct(self):
        unit = Circle((2, 3), (3, 3))
        unit.scale(0.5, 0.25)

        self.assertEqual(1, unit.centroid.x)
        self.assertEqual(0.75, unit.centroid.y)
示例#5
0
    def test_scale__upscale__correct(self):
        unit = Circle((2, 3), (3, 3))
        unit.scale(2, 2)

        self.assertEqual(4, unit.centroid.x)
        self.assertEqual(6, unit.centroid.y)
示例#6
0
    def test_translate__positive_translation__correct(self):
        unit = Circle((0, 0), (0, 1))
        unit.translate(2, 3)

        self.assertEqual(2, unit.centroid.x)
        self.assertEqual(3, unit.centroid.y)
示例#7
0
    def test_to_json__test_points_coordinates__equal_to_test_points(self):
        unit = Circle((20, 30), (30, 45.67))

        self.assertEqual(self.TEST_POINTS, unit.to_json())
示例#8
0
    def test_from_json__test_points__correct(self):
        unit = Circle.from_json(self.TEST_POINTS)

        self.assertEqual(20, unit.centroid.x)
        self.assertEqual(30, unit.centroid.y)
示例#9
0
    def test_bounding_box__not_origin_with_radius_one__correct(self):
        unit = Circle((1, 1), (2, 1))

        self.assertEqual([0, 0, 2, 2], unit.bounding_box)
示例#10
0
    def test_bounding_box__origin_with_radius_one__correct(self):
        unit = Circle((0, 0), (1, 0))

        self.assertEqual([-1, -1, 1, 1], unit.bounding_box)