Ejemplo n.º 1
0
def test_annotations_from_bounding_box_predictions():
    bbox_1 = BoundingBoxPrediction(0, 0, 10, 100, 0.99)
    bbox_2 = BoundingBoxPrediction(500, 500, 100, 10, 0.99)
    annotations = Annotations.from_bounding_boxes_predictions(
        MUSEUM_NUMBER, [bbox_1, bbox_2], 1000, 1000)
    assert annotations.annotations[0].geometry == Geometry(0.0, 0.0, 1.0, 10.0)
    assert annotations.annotations[1].geometry == Geometry(
        50.0, 50.0, 10.0, 1.0)
    def generate_annotations(self,
                             number: MuseumNumber,
                             fragment_image: File,
                             threshold: float = 0.3) -> Annotations:
        image_bytes = fragment_image.read()
        buf = BytesIO(image_bytes)
        width, height = Image.open(buf).size
        bounding_boxes_predictions = self._request_generate_annotations(
            buf.getvalue())

        bounding_boxes_predictions = list(
            filter(lambda bbox: bbox.probability >= threshold,
                   bounding_boxes_predictions))
        return Annotations.from_bounding_boxes_predictions(
            number, bounding_boxes_predictions, height, width)