diff --git a/SuperBuild/cmake/External-ExifTool.cmake b/SuperBuild/cmake/External-ExifTool.cmake index 50291203e..ac59bd3d3 100644 --- a/SuperBuild/cmake/External-ExifTool.cmake +++ b/SuperBuild/cmake/External-ExifTool.cmake @@ -28,7 +28,7 @@ externalproject_add(${_proj_name} SOURCE_DIR ${SB_SOURCE_DIR}/${_proj_name} #--Download step-------------- DOWNLOAD_DIR ${SB_DOWNLOAD_DIR} - URL https://github.com/exiftool/exiftool/archive/refs/tags/12.62.zip + URL https://github.com/exiftool/exiftool/archive/refs/tags/12.70.zip UPDATE_COMMAND "" CONFIGURE_COMMAND "" BUILD_IN_SOURCE 1 diff --git a/opendm/exiftool.py b/opendm/exiftool.py index 7dfe087ae..a538aa6da 100644 --- a/opendm/exiftool.py +++ b/opendm/exiftool.py @@ -2,6 +2,7 @@ import os import tempfile import base64 +import numpy as np from rasterio.io import MemoryFile from opendm.system import run from opendm import log @@ -36,7 +37,43 @@ def extract_raw_thermal_image_data(image_path): img = img[0][:,:,None] del j["RawThermalImage"] - + elif "ThermalData" in j: + thermal_data = base64.b64decode(j["ThermalData"][len("base64:"):]) + thermal_data_buf = np.frombuffer(thermal_data, dtype=np.int16) + + thermal_calibration = base64.b64decode(j["ThermalCalibration"][len("base64:"):]) + thermal_calibration_buf = np.frombuffer(thermal_calibration, dtype=np.int16) + + # TODO: how to interpret these? + # https://exiftool.org/forum/index.php?topic=11401.45 + print(thermal_data_buf.shape) + print(thermal_calibration_buf.shape) + print(" ".join("%02x" % b for b in thermal_data_buf[0:10])) + print(thermal_data_buf[0:10]) + print(thermal_calibration_buf[0:10]) + + # temperatures = np.right_shift(thermal_data_buf, 2).astype(np.float32) + # temperatures *= 0.0625 + # temperatures -= 273.15 + img = thermal_data_buf.reshape((512, 640)) # notice row, column format + + + # from PIL import Image + # img = Image.fromarray(im) + + # temperatures = np.right_shift(thermal_data_buf, 2).astype(np.float32) + # temperatures *= 0.0625 + # temperatures -= 273.15 + + # rows = 512 + # cols = 640 + # im = temperatures.reshape((rows, cols)) # notice row, column format + + # dest_path = '/datasets/dji_thermal/out.tiff' + # img_thermal = Image.fromarray(im) + # img_thermal.save(dest_path) + + return extract_temperature_params_from(j), img else: raise Exception("Invalid JSON (not a list)") @@ -68,6 +105,7 @@ def _convert(v): def extract_temperature_params_from(tags): # Defaults + meta = { "Emissivity": float, "ObjectDistance": unit("m"), @@ -83,12 +121,25 @@ def extract_temperature_params_from(tags): "PlanckR2": float, } + aliases = { + "AtmosphericTemperature": ["AmbientTemperature"], + "ReflectedApparentTemperature": ["ReflectedTemperature"], +# "IRWindowTemperature": ["ReflectedApparentTemperature"], #fallback + } + params = {} for m in meta: - if m not in tags: - # All or nothing + keys = [m] + keys += aliases.get(m, []) + val = None + for k in keys: + if k in tags: + val = (meta[m])(tags[k]) + break + if val is None: raise Exception("Cannot find %s in tags" % m) - params[m] = (meta[m])(tags[m]) + + params[m] = val return params \ No newline at end of file diff --git a/opendm/photo.py b/opendm/photo.py index 0baaf2595..4bc187f54 100644 --- a/opendm/photo.py +++ b/opendm/photo.py @@ -482,6 +482,12 @@ def parse_exif_values(self, _path_file): self.capture_uuid = matches.group(1) self.band_name = band_aliases.get(matches.group(2), matches.group(2)) + # Some DJI models do not have a band name but have an image source field + if self.camera_make.lower() == 'dji': + image_source = self.get_xmp_tag(xtags, '@drone-dji:ImageSource') + if self.band_name == 'RGB' and isinstance(image_source, str) and image_source.lower() == "infraredcamera": + self.band_name = 'LWIR' + # Sanitize band name since we use it in folder paths self.band_name = re.sub('[^A-Za-z0-9]+', '', self.band_name)