Skip to content

Commit c4cf3b0

Browse files
committed
fix mypy
1 parent 15dc626 commit c4cf3b0

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

agentic_doc/utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ def save_groundings_as_images(
8787
save_dir.mkdir(parents=True, exist_ok=True)
8888
if file_type == "image":
8989
img = cv2.imread(str(file_path))
90+
if img is None:
91+
raise ValueError(f"Failed to read image from {file_path}")
9092
return _crop_groundings(img, chunks, save_dir, inplace)
9193

9294
assert file_type == "pdf"
@@ -424,7 +426,10 @@ def _read_img_rgb(img_path: str) -> np.ndarray:
424426
Returns:
425427
img (H, W, 3): a numpy array image in RGB format
426428
"""
427-
img = cv2.cvtColor(cv2.imread(img_path), cv2.COLOR_BGR2RGB)
429+
img_bgr = cv2.imread(img_path)
430+
if img_bgr is None:
431+
raise ValueError(f"Failed to read image from {img_path}")
432+
img = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
428433
if img.shape[-1] == 1:
429434
img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)
430435
elif img.shape[-1] == 4:

0 commit comments

Comments
 (0)