Skip to content

Commit

Permalink
updated image.py
Browse files Browse the repository at this point in the history
  • Loading branch information
franioli committed Jun 6, 2024
1 parent 33b56dc commit 172c4b1
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/deep_image_matching/utils/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
import cv2
import exifread
import numpy as np
from PIL import Image as PImage

from exifread.exceptions import ExifNotFound, InvalidExif
from PIL import Image as PImage

from .sensor_width_database import SensorWidthDatabase

Expand Down Expand Up @@ -115,7 +114,8 @@ def __init__(self, path: Union[str, Path], id: int = None) -> None:

try:
self.read_exif()
except InvalidExif as e:
except InvalidExif:
logger.debug(f"No exif data available for image {self.name} (this will probably not affect the matching)")
img = PImage.open(path)
self._width, self._height = img.size

Expand Down Expand Up @@ -257,9 +257,7 @@ def read_exif(self) -> None:
Read image exif with exifread and store them in a dictionary
Raises:
IOError: If there is an error reading the image file.
InvalidExif: If the exif data is invalid.
ExifNotFound: If no exif data is found for the image.
InvalidExif: If the exif data is invalid or not available.
Returns:
None
Expand All @@ -269,12 +267,10 @@ def read_exif(self) -> None:
with open(self._path, "rb") as f:
exif = exifread.process_file(f, details=False, debug=False)
except (IOError, InvalidExif, ExifNotFound) as e:
logger.debug(f"{e}. Unable to read exif data for image {self.name}.")
raise InvalidExif("Exif error")
raise InvalidExif(e)

if len(exif) == 0:
logger.info(f"No exif data available for image {self.name} (this will probably not affect the matching).")
raise ValueError("Exif error")
raise InvalidExif()

# Get image size
if "Image ImageWidth" in exif.keys() and "Image ImageLength" in exif.keys():
Expand Down

0 comments on commit 172c4b1

Please sign in to comment.