forked from OpenDroneMap/ODM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ua_postprocessing.py
109 lines (88 loc) · 4.74 KB
/
ua_postprocessing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import os
import json
import numpy as np
import awscli_util
# clean unnecessary heavy files
# this prepares syncing project folder to S3
def clean_project(project_path):
objects_to_clean = [
# project_path + '/odm_orthophoto/odm_orthophoto.tif',
# project_path + '/odm_orthophoto/odm_orthophoto.png',
# project_path + '/odm_orthophoto/odm_orthophoto.original.tif',
project_path + '/odm_texturing_25d/',
project_path + '/opensfm/',
project_path + '/odm_filterpoints/',
project_path + '/mve/'
]
for o in objects_to_clean:
try:
os.remove(o)
except:
print('Failed to delete ' + o)
pass
def upload_results(project_folder, output_s3key):
awscli_util.aws_cli(['s3', 'sync', '--quiet', project_folder, output_s3key])
def resize_textures(project_path):
odm_texturing_folder = project_path + "/odm_texturing/"
inputObjFile = "odm_textured_model_geo.obj"
inputMtlFile = "odm_textured_model_geo.mtl"
resized_2x_folder = "resized_2x"
resized_4x_folder = "resized_4x"
# due to imagemagick bug, its impossible to have colon : in the -path param content, so use 'cd' to get relative path
resize_2x_command = 'cd ' + odm_texturing_folder + ' && mkdir -p ' + resized_2x_folder + ' && mogrify -adaptive-resize 50% -path ' + resized_2x_folder + ' -format png ' + './*.png'
resize_4x_command = 'cd ' + odm_texturing_folder + ' && mkdir -p ' + resized_4x_folder + ' && mogrify -adaptive-resize 25% -path ' + resized_4x_folder + ' -format png ' + './*.png'
os.system(resize_2x_command)
os.system(resize_4x_command)
# create symlinks that are needed to generate glb files
os.system('cp ' + odm_texturing_folder + inputObjFile + ' ' + odm_texturing_folder + resized_2x_folder)
os.system('cp ' + odm_texturing_folder + inputMtlFile + ' ' + odm_texturing_folder + resized_4x_folder)
outputGLTFFile = project_path + "/odm_texturing/odm_textured_model_geo.gltf"
outputBINFile = project_path + "/odm_texturing/odm_textured_model_geo.bin"
os.system('cp ' + outputGLTFFile + ' ' + odm_texturing_folder + resized_2x_folder)
os.system('cp ' + outputGLTFFile + ' ' + odm_texturing_folder + resized_4x_folder)
os.system('cp ' + outputBINFile + ' ' + odm_texturing_folder + resized_2x_folder)
os.system('cp ' + outputBINFile + ' ' + odm_texturing_folder + resized_4x_folder)
def obj2gltf(project_path):
inputFile = project_path + "/odm_texturing/odm_textured_model_geo.obj"
outputGLTFFile = project_path + "/odm_texturing/odm_textured_model_geo.gltf"
os.system('obj2gltf -s --checkTransparency -i ' + inputFile + ' -o ' + outputGLTFFile)
def obj2glb(project_path):
odm_texturing_folder = project_path + "/odm_texturing/"
inputFile = "odm_textured_model_geo.obj"
outputGLBFile = "odm_textured_model_geo.glb"
resized_2x_folder = odm_texturing_folder + "resized_2x/"
resized_4x_folder = odm_texturing_folder + "resized_4x/"
os.system(
'obj2gltf -b --checkTransparency -i ' + resized_2x_folder + inputFile + ' -o ' + resized_2x_folder + outputGLBFile)
os.system(
'obj2gltf -b --checkTransparency -i ' + resized_4x_folder + inputFile + ' -o ' + resized_4x_folder + outputGLBFile)
# after converting obj to glb all the textures are redundant
def cleanTextures(project_path):
odm_texturing_folder = project_path + "/odm_texturing/"
resized_2x_images = "resized_2x/*.png"
resized_4x_images = "resized_4x/*.png"
os.system('rm -rv ' + odm_texturing_folder + resized_2x_images)
os.system('rm -rv ' + odm_texturing_folder + resized_4x_images)
def tif2tiles(project_path):
input_ortho_file = project_path + "/odm_orthophoto/odm_orthophoto.tif"
output_ortho_tiles_folder = project_path + "/odm_orthophoto/tiles/"
# os.system('gdal2tiles_parallel.py -e -p geodetic -n' + input_ortho_file + ' ' + output_ortho_tiles_folder)
os.system('gdal2tiles.py -z 10-22 -n ' + input_ortho_file + ' ' + output_ortho_tiles_folder)
def calculate_mean_recon_error(reconstruction_json):
"""
Computes the average error rate of an OpenSfM reconstruction.
:param reconstruction_json path to OpenSfM's reconstruction.json
:return mean recon error
"""
if not os.path.isfile(reconstruction_json):
raise IOError(reconstruction_json + " does not exist.")
with open(reconstruction_json) as f:
data = json.load(f)
# Calculate median error from sparse reconstruction
reconstruction = data[0]
reprojection_errors = []
for pointId in reconstruction['points']:
point = reconstruction['points'][pointId]
reprojection_errors.append(point['reprojection_error'])
reprojection_error = np.median(reprojection_errors)
return reprojection_error