Merge in RR/cv-analysis from remove_pil to master
Squashed commit of the following:
commit 83c8d88f3d48404251470176c70979ee75ae068b
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Thu Jul 21 10:51:51 2022 +0200
remove deprecated server tests
commit cebc03b5399ac257a74036b41997201f882f5b74
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Thu Jul 21 10:51:08 2022 +0200
remove deprecated server tests
commit ce2845b0c51f001b7b5b8b195d6bf7e034ec4e39
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Wed Jul 20 17:05:00 2022 +0200
repair tests to work without pillow WIP
commit 023fdab8322f28359a24c63e32635a3d0deccbe4
Author: Isaac Riley <Isaac.Riley@iqser.com>
Date: Wed Jul 20 16:40:36 2022 +0200
fixed typo
commit 33850ca83a175f74789ae6b9bebd057ed84b7fb3
Author: Isaac Riley <Isaac.Riley@iqser.com>
Date: Wed Jul 20 16:38:37 2022 +0200
fixed import from refactored open_img.py
commit dbc6d345f074e538948e2c4f94ebed8a5ef520bc
Author: Isaac Riley <Isaac.Riley@iqser.com>
Date: Wed Jul 20 16:32:42 2022 +0200
removed PIL from production code, now inly in scripts
60 lines
1.8 KiB
Python
60 lines
1.8 KiB
Python
import gzip
|
|
import io
|
|
|
|
import numpy as np
|
|
import cv2
|
|
import pytest
|
|
from funcy import first
|
|
|
|
from cv_analysis.utils.structures import Rectangle
|
|
from incl.pyinfra.pyinfra.server.packing import bytes_to_string
|
|
|
|
|
|
@pytest.fixture
|
|
def random_image_as_bytes_and_compressed(random_image):
|
|
image = cv2.cvtColor(random_image.astype("uint8"), cv2.COLOR_RGB2RGBA)
|
|
img_byte_arr = io.BytesIO()
|
|
image.save(img_byte_arr, format="PNG")
|
|
return gzip.compress(img_byte_arr.getvalue())
|
|
|
|
|
|
@pytest.fixture
|
|
def random_image_metadata_package(random_image_as_bytes_and_compressed):
|
|
data = bytes_to_string(random_image_as_bytes_and_compressed)
|
|
return [
|
|
{
|
|
"data": data,
|
|
"metadata": {
|
|
"page_info": {"width": 1000, "height": 2000, "rotation": 90},
|
|
"image_info": {"dpi": 200},
|
|
},
|
|
}
|
|
]
|
|
|
|
|
|
@pytest.fixture
|
|
def expected_analyse_metadata(operation, random_image_metadata_package, image_size):
|
|
metadata = first(random_image_metadata_package)
|
|
metadata = metadata["metadata"]
|
|
|
|
if image_size == (200, 200):
|
|
result_metadata = {"cells": [{"height": 72.0, "width": 71.99999999999999, "x": 0.0, "y": 1928.0}]}
|
|
elif image_size == (500, 500):
|
|
result_metadata = {"cells": [{"height": 180.0, "width": 179.99999999999997, "x": 0.0, "y": 1820.0}]}
|
|
elif image_size == (800, 800):
|
|
result_metadata = {"cells": [{"height": 288.0, "width": 287.99999999999994, "x": 0.0, "y": 1712.0}]}
|
|
else:
|
|
result_metadata = {}
|
|
|
|
if operation == "mock":
|
|
|
|
return {**metadata, **result_metadata}
|
|
|
|
|
|
@pytest.fixture
|
|
def analysis_fn_mock(operation):
|
|
def analyse_mock(image: np.ndarray):
|
|
return [Rectangle.from_xywh((0, 0, image.shape[1], image.shape[0]))]
|
|
|
|
return analyse_mock
|