Skip to content

Commit

Permalink
Added exception for photo load error
Browse files Browse the repository at this point in the history
  • Loading branch information
ppizarror committed Feb 27, 2024
1 parent fb63a3f commit f5c0861
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions MLStructFP/db/image/_rect_photo.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ def _parse_image(self, ip: str, mutator_scale_x: float = 1, mutator_scale_y: flo
pixels: 'np.ndarray'
if self._empty_color >= 0:
image: 'np.ndarray' = cv2.imread(ip, cv2.IMREAD_UNCHANGED)
if image is None:
raise RectFloorPhotoFileLoadException(ip)
if len(image.shape) == 3 and image.shape[2] == 4:
# Make mask of where the transparent bits are
trans_mask = image[:, :, 3] == 0
Expand All @@ -281,6 +283,8 @@ def _parse_image(self, ip: str, mutator_scale_x: float = 1, mutator_scale_y: flo
pixels = image
else:
pixels = cv2.imread(ip)
if pixels is None:
raise RectFloorPhotoFileLoadException(ip)
# Turn all black lines to white
if len(pixels.shape) == 3 and np.max(pixels) == 0:
image = cv2.imread(ip, cv2.IMREAD_UNCHANGED)
Expand Down Expand Up @@ -538,7 +542,7 @@ def _get_crop_image(
except ValueError as e:
if rect is not None:
print(f'Shape inconsistency at rect ID <{rect.id}>, Floor ID {rect.floor.id}')
raise RectFloorShapeException(str(e))
raise RectFloorPhotoShapeException(str(e))

"""
Good: INTER_AREA
Expand Down Expand Up @@ -579,7 +583,13 @@ def close(self) -> None:
gc.collect()


class RectFloorShapeException(Exception):
class RectFloorPhotoShapeException(Exception):
"""
Custom exception from rect floor generation image.
"""


class RectFloorPhotoFileLoadException(Exception):
"""
Exception thrown if the image could not be loaded.
"""

0 comments on commit f5c0861

Please sign in to comment.