Esempio n. 1
0
def test_single_image_upload_bytesio(tmpdir):
    tmpdir = Path(tmpdir)

    projects_found = sa.search_projects(PROJECT_NAME_BYTES,
                                        return_metadata=True)
    for pr in projects_found:
        sa.delete_project(pr)

    project = sa.create_project(PROJECT_NAME_BYTES, "test", "Vector")

    with open("./tests/sample_project_vector/example_image_1.jpg", "rb") as f:
        img = io.BytesIO(f.read())
    try:
        sa.upload_image_to_project(project,
                                   img,
                                   annotation_status="InProgress")
    except sa.SABaseException as e:
        assert e.message == "Image name img_name should be set if img is not Pathlike"
    else:
        assert False

    sa.upload_image_to_project(project,
                               img,
                               image_name="rr.jpg",
                               annotation_status="InProgress")
    images = sa.search_images(project)
    assert len(images) == 1
    image = images[0]
    assert sa.annotation_status_int_to_str(
        sa.get_image_metadata(project,
                              image)["annotation_status"]) == "InProgress"
    assert image == "rr.jpg"
def test_fuse_image_create_pixel(tmpdir):
    tmpdir = Path(tmpdir)

    projects = sa.search_projects(PROJECT_NAME_PIXEL, return_metadata=True)
    for project in projects:
        sa.delete_project(project)

    project = sa.create_project(PROJECT_NAME_PIXEL, "test", "Pixel")

    sa.upload_image_to_project(
        project,
        "./tests/sample_project_pixel/example_image_1.jpg",
        annotation_status="QualityCheck"
    )

    sa.create_annotation_classes_from_classes_json(
        project, "./tests/sample_project_pixel/classes/classes.json"
    )
    sa.upload_image_annotations(
        PROJECT_NAME_PIXEL, "example_image_1.jpg",
        "./tests/sample_project_pixel/example_image_1.jpg___pixel.json",
        "./tests/sample_project_pixel/example_image_1.jpg___save.png"
    )

    export = sa.prepare_export(project, include_fuse=True)
    (tmpdir / "export").mkdir()
    sa.download_export(project, export, (tmpdir / "export"))

    # sa.create_fuse_image(
    #     "./tests/sample_project_vector/example_image_1.jpg",
    #     "./tests/sample_project_vector/classes/classes.json", "Vector"
    # )

    paths = sa.download_image(
        project,
        "example_image_1.jpg",
        tmpdir,
        include_annotations=True,
        include_fuse=True
    )
    print(paths, paths[2])
    im1 = Image.open(tmpdir / "export" / "example_image_1.jpg___fuse.png")
    im1_array = np.array(im1)

    im2 = Image.open(paths[2][0])
    im2_array = np.array(im2)

    assert im1_array.shape == im2_array.shape
    assert im1_array.dtype == im2_array.dtype
    assert np.array_equal(im1_array, im2_array)
Esempio n. 3
0
def test_image_move(tmpdir):
    tmpdir = Path(tmpdir)

    projects_found = sa.search_projects(PROJECT_NAME_MOVE,
                                        return_metadata=True)
    for pr in projects_found:
        sa.delete_project(pr)

    project = sa.create_project(PROJECT_NAME_MOVE, "test", "Vector")

    sa.upload_image_to_project(
        project,
        "./tests/sample_project_vector/example_image_1.jpg",
        annotation_status="InProgress")
    sa.upload_image_to_project(
        project,
        "./tests/sample_project_vector/example_image_2.jpg",
        annotation_status="InProgress")

    images = sa.search_images(project)
    assert len(images) == 2
    image = images[0]
    try:
        sa.move_image(project, image, project)
    except sa.SABaseException as e:
        assert e.message == "Cannot move image if source_project == destination_project."
    else:
        assert False

    projects_found = sa.search_projects(PROJECT_NAME_MOVE + "dif",
                                        return_metadata=True)
    for pr in projects_found:
        sa.delete_project(pr)

    dest_project = sa.create_project(PROJECT_NAME_MOVE + "dif", "test",
                                     "Vector")
    sa.move_image(project, image, dest_project)
    di = sa.search_images(dest_project, image)
    assert len(di) == 1
    assert di[0] == image

    si = sa.search_images(project, image)
    assert len(si) == 0

    si = sa.search_images(project)
    assert len(si) == 1
Esempio n. 4
0
def test_image_copy_mult(tmpdir):
    tmpdir = Path(tmpdir)

    projects_found = sa.search_projects(PROJECT_NAME_CPY_MULT,
                                        return_metadata=True)
    for pr in projects_found:
        sa.delete_project(pr)

    project = sa.create_project(PROJECT_NAME_CPY_MULT, "test", "Vector")

    sa.upload_image_to_project(
        project,
        "./tests/sample_project_vector/example_image_1.jpg",
        annotation_status="InProgress")
    sa.create_annotation_classes_from_classes_json(
        project, "./tests/sample_project_vector/classes/classes.json")
    sa.upload_image_annotations(
        project, "example_image_1.jpg",
        "./tests/sample_project_vector/example_image_1.jpg___objects.json")
    sa.upload_image_to_project(
        project,
        "./tests/sample_project_vector/example_image_2.jpg",
        annotation_status="InProgress")
    sa.pin_image(project, "example_image_1.jpg")

    images = sa.search_images(project)
    assert len(images) == 2
    image = images[0]

    for _ in range(3):
        sa.copy_image(project,
                      image,
                      project,
                      include_annotations=True,
                      copy_annotation_status=True,
                      copy_pin=True)
    assert len(sa.search_images(project)) == 5
    images = sa.search_images(project)
    for i in range(3):
        assert f"example_image_1_({i+1}).jpg" in images
    anns = sa.get_image_annotations(project, f"example_image_1_({i+1}).jpg")
    assert anns["annotation_json"] is not None

    metadata = sa.get_image_metadata(project, f"example_image_1_({i+1}).jpg")
    assert metadata["is_pinned"] == 1
Esempio n. 5
0
def test_image_copy(tmpdir):
    tmpdir = Path(tmpdir)

    projects_found = sa.search_projects(PROJECT_NAME_CPY, return_metadata=True)
    for pr in projects_found:
        sa.delete_project(pr)

    project = sa.create_project(PROJECT_NAME_CPY, "test", "Vector")

    sa.upload_image_to_project(
        project,
        "./tests/sample_project_vector/example_image_1.jpg",
        annotation_status="InProgress")
    sa.upload_image_to_project(
        project,
        "./tests/sample_project_vector/example_image_2.jpg",
        annotation_status="InProgress")

    images = sa.search_images(project)
    assert len(images) == 2
    image = images[0]

    sa.copy_image(project, image, project)
    images = sa.search_images(project)
    assert len(images) == 3

    image = "example_image_1_(1).jpg"
    assert len(sa.search_images(project, image)) == 1
    sa.copy_image(project, image, project)

    image = "example_image_1_(2).jpg"
    assert len(sa.search_images(project, image)) == 1

    projects_found = sa.search_projects(PROJECT_NAME_CPY + "dif",
                                        return_metadata=True)
    for pr in projects_found:
        sa.delete_project(pr)

    dest_project = sa.create_project(PROJECT_NAME_CPY + "dif", "test",
                                     "Vector")
    sa.copy_image(project, image, dest_project)
    di = sa.search_images(dest_project, image)
    assert len(di) == 1
    assert di[0] == image
Esempio n. 6
0
def test_single_image_upload_s3(tmpdir):
    tmpdir = Path(tmpdir)

    projects_found = sa.search_projects(PROJECT_NAME_S3, return_metadata=True)
    for pr in projects_found:
        sa.delete_project(pr)

    project = sa.create_project(PROJECT_NAME_S3, "test", "Vector")

    sa.upload_image_to_project(project,
                               "sample_project_vector/example_image_1.jpg",
                               annotation_status="InProgress",
                               from_s3_bucket="superannotate-python-sdk-test")

    images = sa.search_images(project)
    assert len(images) == 1
    image = images[0]
    assert sa.get_image_metadata(project,
                                 image)["annotation_status"] == "InProgress"
Esempio n. 7
0
def test_single_image_upload(tmpdir):
    tmpdir = Path(tmpdir)

    projects_found = sa.search_projects(PROJECT_NAME, return_metadata=True)
    print(projects_found)
    for pr in projects_found:
        sa.delete_project(pr)

    project = sa.create_project(PROJECT_NAME, "test", "Vector")

    sa.upload_image_to_project(
        project,
        "./tests/sample_project_vector/example_image_1.jpg",
        annotation_status="InProgress")

    images = sa.search_images(project)
    assert len(images) == 1
    image = images[0]
    assert sa.get_image_metadata(project,
                                 image)["annotation_status"] == "InProgress"
    assert image == "example_image_1.jpg"
Esempio n. 8
0
def test_fuse_image_create_vector(tmpdir):
    tmpdir = Path(tmpdir)

    projects = sa.search_projects(PROJECT_NAME_VECTOR, return_metadata=True)
    for project in projects:
        sa.delete_project(project)

    project = sa.create_project(PROJECT_NAME_VECTOR, "test", "Vector")

    sa.upload_image_to_project(
        project,
        "./tests/sample_project_vector/example_image_1.jpg",
        annotation_status="QualityCheck")

    sa.create_annotation_classes_from_classes_json(
        project, "./tests/sample_project_vector/classes/classes.json")

    sa.add_annotation_bbox_to_image(project, "example_image_1.jpg",
                                    [20, 20, 40, 40], "Human")
    sa.add_annotation_polygon_to_image(project, "example_image_1.jpg",
                                       [60, 60, 100, 100, 80, 100],
                                       "Personal vehicle")
    sa.add_annotation_polyline_to_image(project, "example_image_1.jpg",
                                        [200, 200, 300, 200, 350, 300],
                                        "Personal vehicle")
    sa.add_annotation_point_to_image(project, "example_image_1.jpg",
                                     [400, 400], "Personal vehicle")
    sa.add_annotation_ellipse_to_image(project, "example_image_1.jpg",
                                       [600, 600, 50, 100, 20],
                                       "Personal vehicle")
    sa.add_annotation_template_to_image(
        project, "example_image_1.jpg",
        [600, 300, 600, 350, 550, 250, 650, 250, 550, 400, 650, 400],
        [1, 2, 3, 1, 4, 1, 5, 2, 6, 2], "Human")
    sa.add_annotation_cuboid_to_image(project, "example_image_1.jpg",
                                      [60, 300, 200, 350, 120, 325, 250, 500],
                                      "Human")

    export = sa.prepare_export(project, include_fuse=True)
    (tmpdir / "export").mkdir()
    sa.download_export(project, export, (tmpdir / "export"))

    # sa.create_fuse_image(
    #     "./tests/sample_project_vector/example_image_1.jpg",
    #     "./tests/sample_project_vector/classes/classes.json", "Vector"
    # )

    paths = sa.download_image(project,
                              "example_image_1.jpg",
                              tmpdir,
                              include_annotations=True,
                              include_fuse=True,
                              include_overlay=True)
    im1 = Image.open(tmpdir / "export" / "example_image_1.jpg___fuse.png")
    im1_array = np.array(im1)

    im2 = Image.open(paths[2][0])
    im2_array = np.array(im2)

    assert im1_array.shape == im2_array.shape
    assert im1_array.dtype == im2_array.dtype