Refactoring, use odm_version(), add seconds

pull/1797/head
Piero Toffanin 2024-09-05 14:27:16 -04:00
rodzic 6ecc8274f8
commit f0ddaba12e
3 zmienionych plików z 31 dodań i 53 usunięć

Wyświetl plik

@ -6,6 +6,7 @@ import datetime
import dateutil.parser import dateutil.parser
import shutil import shutil
import multiprocessing import multiprocessing
from repoze.lru import lru_cache
from opendm.arghelpers import double_quote, args_to_dict from opendm.arghelpers import double_quote, args_to_dict
from vmem import virtual_memory from vmem import virtual_memory
@ -30,6 +31,7 @@ else:
lock = threading.Lock() lock = threading.Lock()
@lru_cache(maxsize=None)
def odm_version(): def odm_version():
with open(os.path.join(os.path.dirname(__file__), "..", "VERSION")) as f: with open(os.path.join(os.path.dirname(__file__), "..", "VERSION")) as f:
return f.read().split("\n")[0].strip() return f.read().split("\n")[0].strip()

Wyświetl plik

@ -21,6 +21,17 @@ from opensfm.geo import ecef_from_lla
projections = ['perspective', 'fisheye', 'fisheye_opencv', 'brown', 'dual', 'equirectangular', 'spherical'] 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): def find_largest_photo_dims(photos):
max_mp = 0 max_mp = 0
max_dims = None max_dims = None

Wyświetl plik

@ -8,7 +8,7 @@ from osgeo import gdal
from opendm import io from opendm import io
from opendm import log from opendm import log
from opendm import types from opendm import types
from opendm import context from opendm import photo
from opendm.utils import copy_paths, get_processing_results_paths from opendm.utils import copy_paths, get_processing_results_paths
from opendm.ogctiles import build_3dtiles from opendm.ogctiles import build_3dtiles
@ -19,56 +19,25 @@ class ODMPostProcess(types.ODM_Stage):
log.ODM_INFO("Post Processing") log.ODM_INFO("Post Processing")
# -- TIFFTAG information - add datetime and software version to .tif metadata rasters = [tree.odm_orthophoto_tif,
tree.path("odm_dem", "dsm.tif"),
tree.path("odm_dem", "dtm.tif")]
# Gather information mean_capture_time = photo.find_mean_utc_time(reconstruction.photos)
# ODM version ... mean_capture_dt = None
with open(os.path.join(context.root_path, 'VERSION')) as version_file: if mean_capture_time is not None:
version = version_file.read().strip() mean_capture_dt = datetime.fromtimestamp(mean_capture_time).strftime('%Y:%m:%d %H:%M:%S') + '+00:00'
# Datetimes ...
shots_file = tree.path("odm_report", "shots.geojson")
if not args.skip_report and os.path.isfile(shots_file):
# Open file
with open(shots_file, 'r') as f:
odm_shots = json.loads(f.read())
# Compute mean time
cts = []
for feat in odm_shots["features"]:
ct = feat["properties"]["capture_time"]
cts.append(ct)
mean_dt = datetime.fromtimestamp(np.mean(cts))
# Format it
CAPTURE_DATETIME = mean_dt.strftime('%Y:%m:%d %H:%M') + '+00:00' #UTC
else:
#try instead with images.json file
images_file = tree.path('images.json')
if os.path.isfile(images_file):
# Open file
with open(images_file, 'r') as f:
imgs = json.loads(f.read())
# Compute mean time
cts = []
for img in imgs:
ct = img["utc_time"]/1000. #ms to s
cts.append(ct)
mean_dt = datetime.fromtimestamp(np.mean(cts))
# Format it
CAPTURE_DATETIME = mean_dt.strftime('%Y:%m:%d %H:%M') + '+00:00' #UTC
else:
CAPTURE_DATETIME = None
# Add it # Add TIFF tags
for product in [tree.odm_orthophoto_tif, for product in rasters:
tree.path("odm_dem", "dsm.tif"), if os.path.isfile(product):
tree.path("odm_dem", "dtm.tif")]: log.ODM_INFO("Adding TIFFTAGs to {}".format(product))
for pdt in [product, product.replace('.tif', '.original.tif')]: with rasterio.open(product, 'r+') as rst:
if os.path.isfile(pdt): if mean_capture_dt is not None:
log.ODM_INFO("Adding TIFFTAGs to {} ...".format(pdt)) rst.update_tags(TIFFTAG_DATETIME=mean_capture_dt)
with rasterio.open(pdt, 'r+') as rst: rst.update_tags(TIFFTAG_SOFTWARE='ODM {}'.format(log.odm_version()))
rst.update_tags(TIFFTAG_DATETIME=CAPTURE_DATETIME)
rst.update_tags(TIFFTAG_SOFTWARE='OpenDroneMap {}'.format(version))
# -- GCP info # GCP info
if not outputs['large']: if not outputs['large']:
# TODO: support for split-merge? # TODO: support for split-merge?
@ -83,9 +52,7 @@ class ODMPostProcess(types.ODM_Stage):
with open(gcp_gml_export_file) as f: with open(gcp_gml_export_file) as f:
gcp_xml = f.read() gcp_xml = f.read()
for product in [tree.odm_orthophoto_tif, for product in rasters:
tree.path("odm_dem", "dsm.tif"),
tree.path("odm_dem", "dtm.tif")]:
if os.path.isfile(product): if os.path.isfile(product):
ds = gdal.Open(product) ds = gdal.Open(product)
if ds is not None: if ds is not None:
@ -100,11 +67,9 @@ class ODMPostProcess(types.ODM_Stage):
else: else:
log.ODM_WARNING("Cannot open %s for writing, skipping GCP embedding" % product) log.ODM_WARNING("Cannot open %s for writing, skipping GCP embedding" % product)
# -- 3D tiles
if getattr(args, '3d_tiles'): if getattr(args, '3d_tiles'):
build_3dtiles(args, tree, reconstruction, self.rerun()) build_3dtiles(args, tree, reconstruction, self.rerun())
# -- Copy to
if args.copy_to: if args.copy_to:
try: try:
copy_paths([os.path.join(args.project_path, p) for p in get_processing_results_paths()], args.copy_to, self.rerun()) copy_paths([os.path.join(args.project_path, p) for p in get_processing_results_paths()], args.copy_to, self.rerun())