def query_by_museum_number(self, number: MuseumNumber) -> Annotations:
        try:
            result = self._collection.find_one({"fragmentNumber": str(number)})

            return AnnotationsSchema().load(result, unknown=EXCLUDE)
        except NotFoundError:
            return Annotations(number)
Esempio n. 2
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)
Esempio n. 3
0
def test_find_annotations(client):
    fragment_number = MuseumNumber("X", "2")
    annotations = Annotations(fragment_number)

    result = client.simulate_get(
        f"/fragments/{fragment_number}/annotations",
        params={"generateAnnotations": False},
    )

    expected_json = AnnotationsSchema().dump(annotations)
    assert result.status == falcon.HTTP_OK
    assert result.json == expected_json
    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)
Esempio n. 5
0
def test_generate_annotations(
    annotations_repository, photo_repository, changelog, when
):
    fragment_number = MuseumNumber.of("X.0")

    image_file = create_test_photo("K.2")

    when(photo_repository).query_by_file_name(f"{fragment_number}.jpg").thenReturn(
        image_file
    )
    ebl_ai_client = EblAiClient("mock-localhost:8001")
    service = AnnotationsService(
        ebl_ai_client, annotations_repository, photo_repository, changelog
    )

    expected = Annotations(fragment_number, tuple())
    when(ebl_ai_client).generate_annotations(fragment_number, image_file, 0).thenReturn(
        expected
    )

    annotations = service.generate_annotations(fragment_number, 0)
    assert isinstance(annotations, Annotations)
    assert annotations == expected
Esempio n. 6
0
WIDTH = 0.32
Y = 35.4
X = 34.2
GEOMETRY = Geometry(X, Y, WIDTH, HEIGHT)

PATH = [2, 3]
VALUE = "kur"
TYPE = AnnotationValueType.HAS_SIGN
ID = "1234"
SIGN_NAME = "KUR"
DATA = AnnotationData(ID, VALUE, TYPE, PATH, SIGN_NAME)

ANNOTATION = Annotation(GEOMETRY, DATA)

MUSEUM_NUMBER = MuseumNumber("K", "1")
ANNOTATIONS = Annotations(MUSEUM_NUMBER, [ANNOTATION])


def test_geometry():
    assert GEOMETRY.x == X
    assert GEOMETRY.y == Y
    assert GEOMETRY.width == WIDTH
    assert GEOMETRY.height == HEIGHT


def test_data():
    assert DATA.id == ID
    assert DATA.value == VALUE
    assert DATA.path == PATH
    assert DATA.sign_name == SIGN_NAME
def test_query_by_museum_number_not_found(database, annotations_repository):
    fragment_number = MuseumNumber("X", "1")

    assert annotations_repository.query_by_museum_number(
        fragment_number
    ) == Annotations(fragment_number)
Esempio n. 8
0
 def make_annotation(self, data, **kwargs):
     data["fragment_number"] = MuseumNumber.of(data["fragment_number"])
     return Annotations(**data)