feat(v4): add docker-compose and production-ready application
This commit is contained in:
@@ -18,9 +18,12 @@ def save_image_array(image, prefix="image"):
|
||||
filename = f"sessions/{prefix}-{uuid4().hex}.png"
|
||||
path = Path(settings.MEDIA_ROOT) / filename
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
rgb = ensure_uint8(image)
|
||||
bgr = cv2.cvtColor(rgb, cv2.COLOR_RGB2BGR)
|
||||
ok, encoded = cv2.imencode(".png", bgr)
|
||||
array = ensure_uint8(image)
|
||||
if array.ndim == 2:
|
||||
encoded_source = array
|
||||
else:
|
||||
encoded_source = cv2.cvtColor(array, cv2.COLOR_RGB2BGR)
|
||||
ok, encoded = cv2.imencode(".png", encoded_source)
|
||||
if not ok:
|
||||
raise ProcessingError("Unable to encode image for temporary storage.")
|
||||
path.write_bytes(encoded.tobytes())
|
||||
@@ -32,9 +35,13 @@ def load_image_array(relative_path):
|
||||
if not path.exists():
|
||||
raise ProcessingError("Temporary image file is missing or unreadable.")
|
||||
raw = np.frombuffer(path.read_bytes(), dtype=np.uint8)
|
||||
image = cv2.imdecode(raw, cv2.IMREAD_COLOR)
|
||||
image = cv2.imdecode(raw, cv2.IMREAD_UNCHANGED)
|
||||
if image is None:
|
||||
raise ProcessingError("Temporary image file is missing or unreadable.")
|
||||
if image.ndim == 2:
|
||||
return image.astype(np.uint8)
|
||||
if image.shape[2] == 4:
|
||||
return cv2.cvtColor(image, cv2.COLOR_BGRA2RGB).astype(np.uint8)
|
||||
return cv2.cvtColor(image, cv2.COLOR_BGR2RGB).astype(np.uint8)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user