def parse_pyexiv2_values(self, _path_file, _force_focal, _force_ccd): # read image metadata metadata = pyexiv2.ImageMetadata(_path_file) metadata.read() # loop over image tags for key in metadata: # try/catch tag value due to weird bug in pyexiv2 # ValueError: invalid literal for int() with base 10: '' GPS = 'Exif.GPSInfo.GPS' try: # parse tag names if key == 'Exif.Image.Make': self.camera_make = metadata[key].value elif key == 'Exif.Image.Model': self.camera_model = metadata[key].value elif key == 'Exif.Photo.FocalLength': self.focal_length = float(metadata[key].value) elif key == GPS + 'Latitude': self.latitude = self.dms_to_decimal(*metadata[key].value + [metadata[GPS + 'LatitudeRef'].value]) elif key == GPS + 'Longitude': self.longitude = self.dms_to_decimal(*metadata[key].value + [metadata[GPS + 'LongitudeRef'].value]) elif key == GPS + 'Altitude': self.altitude = float(metadata[key].value) if metadata[GPS + 'AltitudeRef'] and int(metadata[GPS + 'AltitudeRef'].value) > 0: self.altitude *= -1. except (pyexiv2.ExifValueError, ValueError) as e: pass except KeyError as e: log.ODM_DEBUG('Tag not set') except NotImplementedError as e: pass if self.camera_make and self.camera_model: self.make_model = sensor_string(self.camera_make, self.camera_model) # needed to do that since sometimes metadata contains wrong data img = cv2.imread(_path_file) self.width = img.shape[1] self.height = img.shape[0] # force focal and ccd_width with user parameter if _force_focal: self.focal_length = _force_focal if _force_ccd: self.ccd_width = _force_ccd # find ccd_width from file if needed if self.ccd_width is None and self.camera_model is not None: # load ccd_widths from file ccd_widths = system.get_ccd_widths() # search ccd by camera model key = [x for x in ccd_widths.keys() if self.make_model in x] # convert to float if found if key: self.ccd_width = float(ccd_widths[key[0]]) else: log.ODM_WARNING('Could not find ccd_width in file. Use --force-ccd or edit the sensor_data.json ' 'file to manually input ccd width')
def parse_exif_values(self, _path_file, _force_focal, _force_ccd): # Disable exifread log logging.getLogger('exifread').setLevel(logging.CRITICAL) with open(_path_file, 'rb') as f: tags = exifread.process_file(f, details=False) try: if 'Image Make' in tags: self.camera_make = tags['Image Make'].values.encode('utf8') if 'Image Model' in tags: self.camera_model = tags['Image Model'].values.encode( 'utf8') if 'EXIF FocalLength' in tags: self.focal_length = self.float_values( tags['EXIF FocalLength'])[0] if 'GPS GPSAltitude' in tags: self.altitude = self.float_values( tags['GPS GPSAltitude'])[0] if 'GPS GPSAltitudeRef' in tags and self.int_values( tags['GPS GPSAltitudeRef'])[0] > 0: self.altitude *= -1 if 'GPS GPSLatitude' in tags and 'GPS GPSLatitudeRef' in tags: self.latitude = self.dms_to_decimal( tags['GPS GPSLatitude'], tags['GPS GPSLatitudeRef']) if 'GPS GPSLongitude' in tags and 'GPS GPSLongitudeRef' in tags: self.longitude = self.dms_to_decimal( tags['GPS GPSLongitude'], tags['GPS GPSLongitudeRef']) except IndexError as e: log.ODM_WARNING("Cannot read EXIF tags for %s: %s" % (_path_file, e.message)) if self.camera_make and self.camera_model: self.make_model = sensor_string(self.camera_make, self.camera_model) # needed to do that since sometimes metadata contains wrong data img = cv2.imread(_path_file) self.width = img.shape[1] self.height = img.shape[0] # force focal and ccd_width with user parameter if _force_focal: self.focal_length = _force_focal if _force_ccd: self.ccd_width = _force_ccd # find ccd_width from file if needed if self.ccd_width is None and self.camera_model is not None: # load ccd_widths from file ccd_widths = system.get_ccd_widths() # search ccd by camera model key = [x for x in ccd_widths.keys() if self.make_model in x] # convert to float if found if key: self.ccd_width = float(ccd_widths[key[0]]) else: log.ODM_WARNING( 'Could not find ccd_width in file. Use --force-ccd or edit the sensor_data.json ' 'file to manually input ccd width')
def parse_pyexiv2_values(self, _path_file, _force_focal, _force_ccd): # read image metadata metadata = pyexiv2.ImageMetadata(_path_file) metadata.read() # loop over image tags for key in metadata: # try/catch tag value due to weird bug in pyexiv2 # ValueError: invalid literal for int() with base 10: '' try: val = metadata[key].value # parse tag names if key == 'Exif.Image.Make': self.camera_make = val elif key == 'Exif.Image.Model': self.camera_model = val elif key == 'Exif.Photo.FocalLength': self.focal_length = float(val) except (pyexiv2.ExifValueError, ValueError) as e: pass except NotImplementedError as e: pass if self.camera_make and self.camera_model: self.make_model = sensor_string(self.camera_make, self.camera_model) # needed to do that since sometimes metadata contains wrong data img = cv2.imread(_path_file) self.width = img.shape[1] self.height = img.shape[0] # force focal and ccd_width with user parameter if _force_focal: self.focal_length = _force_focal if _force_ccd: self.ccd_width = _force_ccd # find ccd_width from file if needed if self.ccd_width is None and self.camera_model is not None: # load ccd_widths from file ccd_widths = system.get_ccd_widths() # search ccd by camera model key = [x for x in ccd_widths.keys() if self.make_model in x] # convert to float if found if key: self.ccd_width = float(ccd_widths[key[0]]) else: log.ODM_WARNING('Could not find ccd_width in file. Use --force-ccd or edit the sensor_data.json ' 'file to manually input ccd width')