Пример #1
0
    def test_imwrite_bgr(self, get_asset, tmpdir):
        lena_png = get_asset("lena.png")

        image_bgr = imread(lena_png, rgb=False)
        imwrite(Path(tmpdir) / "lena.png", image_bgr, image_bgr=True)
        image_bgr = imread(lena_png, rgb=False)

        image_cv_bgr = cv2.imread(lena_png.as_posix())

        assert np.allclose(image_cv_bgr, image_bgr)
Пример #2
0
    def test_imwrite(self, get_asset, tmpdir):
        lena_png = get_asset("lena.png")

        image_rgb = imread(lena_png)
        imwrite(Path(tmpdir) / "lena.png", image_rgb)
        image_rgb = imread(lena_png)

        image_cv_bgr = cv2.imread(lena_png.as_posix())
        image_cv_rgb = cv2.cvtColor(image_cv_bgr, cv2.COLOR_BGR2RGB)

        assert np.allclose(image_cv_rgb, image_rgb)
Пример #3
0
    def test_correct_color(self, get_asset):
        lena_png = get_asset("lena.png")

        # reads as rgb by default
        image_rgb = imread(lena_png)
        image_bgr = imread(lena_png, rgb=False)

        image_cv_bgr = cv2.imread(lena_png.as_posix())
        image_cv_rgb = cv2.cvtColor(image_cv_bgr, cv2.COLOR_BGR2RGB)

        assert np.allclose(image_cv_rgb, image_rgb)
        assert np.allclose(image_cv_bgr, image_bgr)
Пример #4
0
    def test_correct_pil(self, get_asset):
        lena_png = get_asset("lena.png")

        # reads as rgb by default
        image_rgb = imread(lena_png, pil=True)
        image_bgr = imread(lena_png, rgb=False, pil=True)

        image_cv_bgr = cv2.imread(lena_png.as_posix())
        image_cv_rgb = cv2.cvtColor(image_cv_bgr, cv2.COLOR_BGR2RGB)

        assert isinstance(image_rgb, Image.Image)
        assert isinstance(image_bgr, Image.Image)
        assert np.allclose(image_cv_rgb, np.asarray(image_rgb))
        assert np.allclose(image_cv_bgr, np.asarray(image_bgr))
Пример #5
0
def test_visualize_smoke(lena_rgb, get_asset):
    # draw some primitives

    bbox = (228, 228, 377, 377)
    draw_bbox(lena_rgb, bbox)
    draw_bbox(lena_rgb, (350, 350, 480, 480), color="red", text="bbox text")

    # sample mask
    mask = np.full((512, 512), False)
    mask[130:260, 130:260] = True
    draw_mask(lena_rgb, mask)

    draw_landmarks(lena_rgb, landmarks)

    draw_text(lena_rgb, "Sample text")
    draw_text(lena_rgb, "Shadowed text", shadow=True, position=(0, 55))

    draw_text_multiline(lena_rgb, "line 1\nline 2", position=(415, 25))

    ref_image = imread(get_asset("lena_visualization.png"))
    np.testing.assert_allclose(lena_rgb, ref_image)
Пример #6
0
    def test_imread_jpg(self, get_asset):
        lena_png = get_asset("lena.jpg")

        image = imread(lena_png)

        assert image.shape == (512, 512, 3)
Пример #7
0
def lena_rgb():
    lena_path = TEST_DATA.joinpath("lena.png")
    return imread(lena_path)