diff options
author | aktersnurra <gustaf.rydholm@gmail.com> | 2020-12-07 22:54:04 +0100 |
---|---|---|
committer | aktersnurra <gustaf.rydholm@gmail.com> | 2020-12-07 22:54:04 +0100 |
commit | 25b5d6983d51e0e791b96a76beb7e49f392cd9a8 (patch) | |
tree | 526ba739714b3d040f7810c1a6be3ff0ba37fdb1 /src/text_recognizer/util.py | |
parent | 5529e0fc9ca39e81fe0f08a54f257d32f0afe120 (diff) |
Segmentation working!
Diffstat (limited to 'src/text_recognizer/util.py')
-rw-r--r-- | src/text_recognizer/util.py | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/text_recognizer/util.py b/src/text_recognizer/util.py index 6c07c60..b431e22 100644 --- a/src/text_recognizer/util.py +++ b/src/text_recognizer/util.py @@ -21,20 +21,21 @@ def read_image(image_uri: Union[Path, str], grayscale: bool = False) -> np.ndarr return cv2.imdecode(image_array, imread_flag) else: raise ValueError( - "Url does not start with http, therfore not safe to open..." + "Url does not start with http, therefore not safe to open..." ) from None imread_flag = cv2.IMREAD_GRAYSCALE if grayscale else cv2.IMREAD_COLOR local_file = os.path.exists(image_uri) - try: - image = None - if local_file: - image = read_image_from_filename(image_uri, imread_flag) - else: - image = read_image_from_url(image_uri, imread_flag) - assert image is not None - except Exception as e: - raise ValueError(f"Could not load image at {image_uri}: {e}") + image = None + + if local_file: + image = read_image_from_filename(image_uri, imread_flag) + else: + image = read_image_from_url(image_uri, imread_flag) + + if image is None: + raise ValueError(f"Could not load image at {image_uri}") + return image |