Skip to content

Commit

Permalink
Merge pull request #1797 from stephenwinn16/master
Browse files Browse the repository at this point in the history
Adding TIFFTAG_* to .tif outputs
  • Loading branch information
pierotofy authored Sep 5, 2024
2 parents e6e4095 + 33e8500 commit 2242d17
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
2 changes: 2 additions & 0 deletions opendm/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import dateutil.parser
import shutil
import multiprocessing
from repoze.lru import lru_cache

from opendm.arghelpers import double_quote, args_to_dict
from vmem import virtual_memory
Expand All @@ -30,6 +31,7 @@

lock = threading.Lock()

@lru_cache(maxsize=None)
def odm_version():
with open(os.path.join(os.path.dirname(__file__), "..", "VERSION")) as f:
return f.read().split("\n")[0].strip()
Expand Down
11 changes: 11 additions & 0 deletions opendm/photo.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@

projections = ['perspective', 'fisheye', 'fisheye_opencv', 'brown', 'dual', 'equirectangular', 'spherical']

def find_mean_utc_time(photos):
utc_times = []
for p in photos:
if p.utc_time is not None:
utc_times.append(p.utc_time / 1000.0)
if len(utc_times) == 0:
return None

return np.mean(utc_times)


def find_largest_photo_dims(photos):
max_mp = 0
max_dims = None
Expand Down
27 changes: 24 additions & 3 deletions stages/odm_postprocess.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import os
import rasterio

from datetime import datetime
from osgeo import gdal
from opendm import io
from opendm import log
from opendm import types
from opendm import photo
from opendm.utils import copy_paths, get_processing_results_paths
from opendm.ogctiles import build_3dtiles

Expand All @@ -14,6 +17,25 @@ def process(self, args, outputs):

log.ODM_INFO("Post Processing")

rasters = [tree.odm_orthophoto_tif,
tree.path("odm_dem", "dsm.tif"),
tree.path("odm_dem", "dtm.tif")]

mean_capture_time = photo.find_mean_utc_time(reconstruction.photos)
mean_capture_dt = None
if mean_capture_time is not None:
mean_capture_dt = datetime.fromtimestamp(mean_capture_time).strftime('%Y:%m:%d %H:%M:%S') + '+00:00'

# Add TIFF tags
for product in rasters:
if os.path.isfile(product):
log.ODM_INFO("Adding TIFFTAGs to {}".format(product))
with rasterio.open(product, 'r+') as rst:
if mean_capture_dt is not None:
rst.update_tags(TIFFTAG_DATETIME=mean_capture_dt)
rst.update_tags(TIFFTAG_SOFTWARE='ODM {}'.format(log.odm_version()))

# GCP info
if not outputs['large']:
# TODO: support for split-merge?

Expand All @@ -28,9 +50,7 @@ def process(self, args, outputs):
with open(gcp_gml_export_file) as f:
gcp_xml = f.read()

for product in [tree.odm_orthophoto_tif,
tree.path("odm_dem", "dsm.tif"),
tree.path("odm_dem", "dtm.tif")]:
for product in rasters:
if os.path.isfile(product):
ds = gdal.Open(product)
if ds is not None:
Expand All @@ -53,3 +73,4 @@ def process(self, args, outputs):
copy_paths([os.path.join(args.project_path, p) for p in get_processing_results_paths()], args.copy_to, self.rerun())
except Exception as e:
log.ODM_WARNING("Cannot copy to %s: %s" % (args.copy_to, str(e)))

0 comments on commit 2242d17

Please sign in to comment.