Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thermal support for DJI M3T [WIP] #1670

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SuperBuild/cmake/External-ExifTool.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
59 changes: 55 additions & 4 deletions opendm/exiftool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)")
Expand Down Expand Up @@ -68,6 +105,7 @@ def _convert(v):

def extract_temperature_params_from(tags):
# Defaults

meta = {
"Emissivity": float,
"ObjectDistance": unit("m"),
Expand All @@ -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
6 changes: 6 additions & 0 deletions opendm/photo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading