Skip to content

Commit 1ac8805

Browse files
committed
dev(images): harden the load primitives, must specify a format now
1 parent c4b7baa commit 1ac8805

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/ZooProcess_lib/img_tools.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,15 @@ def loadimage(
242242
return image
243243

244244

245-
def load_image(file_path: Path, img_type=cv2.COLOR_BGR2GRAY) -> np.ndarray:
245+
def load_image(file_path: Path, imread_mode: int) -> np.ndarray:
246+
assert imread_mode in (cv2.IMREAD_COLOR_RGB, cv2.IMREAD_COLOR_BGR)
246247
if file_path.name.endswith(".gif"):
247248
# patent issue? opencv cannot read GIF
248-
# TODO: Not consistent, img_type unused here
249+
# TODO: Not consistent, imread_mode unused here
249250
pil_image = Image.open(file_path)
250251
image = np.array(pil_image)
251252
else:
252-
image = cv2.imread(file_path.as_posix(), img_type)
253+
image = cv2.imread(file_path.as_posix(), imread_mode)
253254
if image is None: # TODO: wrong diag if format issue or any
254255
raise Exception(f"Could not load: {file_path}")
255256
return image

0 commit comments

Comments
 (0)