[68d617]: contrib / brl / bseg / bvxm / pyscripts / bvxm_volm_adaptor.py Maximize Restore History

Download this file

bvxm_volm_adaptor.py    209 lines (191 with data), 9.1 kB

  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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
from bvxm_register import bvxm_batch, dbvalue;
import math;
def map_sdet_to_volm_ids(sdet_color_class_img):
bvxm_batch.init_process("volmGenerateClassMapProcess");
bvxm_batch.set_input_from_db(0,sdet_color_class_img);
bvxm_batch.run_process();
(id, type) = bvxm_batch.commit_output(0);
out_img = dbvalue(id, type);
return out_img
def volm_id_color_img(id_img, id_to_color_txt=""):
bvxm_batch.init_process("volmGenerateColorClassMapProcess")
bvxm_batch.set_input_from_db(0,id_img);
bvxm_batch.set_input_string(1,id_to_color_txt)
bvxm_batch.run_process();
(id, type) = bvxm_batch.commit_output(0);
out_img = dbvalue(id, type);
return out_img;
def update_class_map(class_img, source_img):
bvxm_batch.init_process("volmUpdateClassMapProcess");
bvxm_batch.set_input_from_db(0, class_img);
bvxm_batch.set_input_from_db(1, source_img);
status = bvxm_batch.run_process()
return status;
def load_sat_resources(res_file_name):
bvxm_batch.init_process("volmLoadSatResourcesProcess");
bvxm_batch.set_input_string(0,res_file_name);
bvxm_batch.run_process();
(res2_id, res2_type) = bvxm_batch.commit_output(0);
res2 = dbvalue(res2_id, res2_type);
return res2
def find_resource_pair(res, name):
bvxm_batch.init_process("volmFindResourcePairProcess");
bvxm_batch.set_input_from_db(0,res);
bvxm_batch.set_input_string(1,name);
statuscode=bvxm_batch.run_process();
(f_id, f_type) = bvxm_batch.commit_output(0);
full_path = bvxm_batch.get_output_string(f_id);
bvxm_batch.remove_data(f_id);
(n_id, n_type) = bvxm_batch.commit_output(1);
pair_name = bvxm_batch.get_output_string(n_id);
bvxm_batch.remove_data(n_id);
(p_id, p_type) = bvxm_batch.commit_output(2);
full_path_pair_name = bvxm_batch.get_output_string(p_id);
bvxm_batch.remove_data(p_id);
return statuscode, full_path, pair_name, full_path_pair_name
def get_full_path(res, name):
bvxm_batch.init_process("volmGetFullPathProcess");
bvxm_batch.set_input_from_db(0,res);
bvxm_batch.set_input_string(1,name);
statuscode=bvxm_batch.run_process();
(f_id, f_type) = bvxm_batch.commit_output(0);
full_path = bvxm_batch.get_output_string(f_id);
bvxm_batch.remove_data(f_id);
return full_path
## band_name is PAN or MULTI
def pick_nadir_resource(res, lower_left_lon, lower_left_lat, upper_right_lon, upper_right_lat, satellite_name, band_name="PAN", non_cloud_folder=""):
bvxm_batch.init_process("volmPickNadirResProcess");
bvxm_batch.set_input_from_db(0,res);
bvxm_batch.set_input_double(1, lower_left_lon);
bvxm_batch.set_input_double(2, lower_left_lat);
bvxm_batch.set_input_double(3, upper_right_lon);
bvxm_batch.set_input_double(4, upper_right_lat);
bvxm_batch.set_input_string(5, band_name);
bvxm_batch.set_input_string(6, satellite_name);
bvxm_batch.set_input_string(7, non_cloud_folder);
bvxm_batch.run_process();
(id, type) = bvxm_batch.commit_output(0);
sat_path = bvxm_batch.get_output_string(id);
return sat_path;
## find the PAN/MULTI pair for given rectangular region, also output the sorted list of such PAN/MULIT lists
def pick_nadir_resource_pair(res, lower_left_lon, lower_left_lat, upper_right_lon, upper_right_lat, satellite_name, out_folder, band_name="PAN", non_cloud_folder=""):
bvxm_batch.init_process("volmPickNadirResPairProcess");
bvxm_batch.set_input_from_db(0,res);
bvxm_batch.set_input_double(1, lower_left_lon);
bvxm_batch.set_input_double(2, lower_left_lat);
bvxm_batch.set_input_double(3, upper_right_lon);
bvxm_batch.set_input_double(4, upper_right_lat);
bvxm_batch.set_input_string(5, band_name);
bvxm_batch.set_input_string(6, satellite_name);
bvxm_batch.set_input_string(7, non_cloud_folder);
bvxm_batch.set_input_string(8, out_folder)
statuscode = bvxm_batch.run_process();
if statuscode:
(p_id, p_type) = bvxm_batch.commit_output(0);
pan_path = bvxm_batch.get_output_string(p_id);
bvxm_batch.remove_data(p_id);
(m_id, m_type) = bvxm_batch.commit_output(1);
multi_path = bvxm_batch.get_output_string(m_id);
bvxm_batch.remove_data(m_id);
else:
pan_path = "";
multi_path = "";
return statuscode, pan_path, multi_path
## GSD: ground sampling distance, e.g. pass 1 to eliminate all the images which have pixel GSD more than 1 meter; the default is 10 meters, so practically returns all the satellite images
def scene_resources(res, lower_left_lon, lower_left_lat, upper_right_lon, upper_right_lat, scene_res_file, band="PAN",GSD_threshold=10.0, pick_seeds=0, n_seeds=0):
bvxm_batch.init_process("volmQuerySatelliteResourcesProcess");
bvxm_batch.set_input_from_db(0,res);
bvxm_batch.set_input_double(1, lower_left_lon);
bvxm_batch.set_input_double(2, lower_left_lat);
bvxm_batch.set_input_double(3, upper_right_lon);
bvxm_batch.set_input_double(4, upper_right_lat);
bvxm_batch.set_input_string(5, scene_res_file);
bvxm_batch.set_input_string(6, band);
bvxm_batch.set_input_bool(7, pick_seeds); ## of 0, it returns all resources that intersect the box, otherwise, it picks n_seeds among these resources
bvxm_batch.set_input_int(8, n_seeds);
bvxm_batch.set_input_double(9, GSD_threshold);
bvxm_batch.run_process();
(id, type) = bvxm_batch.commit_output(0);
cnt = bvxm_batch.get_output_unsigned(id);
return cnt;
def scene_resources2(res, poly_kml, scene_res_file, band="PAN", GSD_threshold=10.0, pick_seeds=0, n_seeds=0):
bvxm_batch.init_process("volmQuerySatelliteResourceKmlProcess");
bvxm_batch.set_input_from_db(0, res);
bvxm_batch.set_input_string(1, poly_kml);
bvxm_batch.set_input_string(2, scene_res_file);
bvxm_batch.set_input_string(3, band);
bvxm_batch.set_input_bool(4, pick_seeds);
bvxm_batch.set_input_int(5, n_seeds);
bvxm_batch.set_input_double(6, GSD_threshold);
bvxm_batch.run_process();
(id, type) = bvxm_batch.commit_output(0)
cnt = bvxm_batch.get_output_unsigned(id);
return cnt;
def find_stereo_pairs(res, lower_left_lon, lower_left_lat, upper_right_lon, upper_right_lat, scene_res_file, satellite_name):
bvxm_batch.init_process("volmFindSatellitePairsProcess");
bvxm_batch.set_input_from_db(0,res);
bvxm_batch.set_input_double(1, lower_left_lon);
bvxm_batch.set_input_double(2, lower_left_lat);
bvxm_batch.set_input_double(3, upper_right_lon);
bvxm_batch.set_input_double(4, upper_right_lat);
bvxm_batch.set_input_string(5, scene_res_file);
bvxm_batch.set_input_string(6, satellite_name);
bvxm_batch.run_process();
(id, type) = bvxm_batch.commit_output(0);
cnt = bvxm_batch.get_output_unsigned(id);
return cnt;
def correct_ransac_process(res, cor_file, output_folder, pixel_radius):
bvxm_batch.init_process("volmCorrectRationalCamerasRANSACProcess");
bvxm_batch.set_input_from_db(0, res);
bvxm_batch.set_input_string(1, cor_file);
bvxm_batch.set_input_string(2, output_folder);
bvxm_batch.set_input_float(3, pixel_radius); ## pixel radius to count for inliers
bvxm_batch.run_process();
## this one checks if the camera is already corrected and exists in the output folder
## weights the cameras accordingly
def correct_ransac_process2(res, cor_file, output_folder, pixel_radius):
bvxm_batch.init_process("volmCorrectRationalCamerasRANSACProcess2");
bvxm_batch.set_input_from_db(0, res);
bvxm_batch.set_input_string(1, cor_file);
bvxm_batch.set_input_string(2, output_folder);
bvxm_batch.set_input_float(3, pixel_radius); ## pixel radius to count for inliers
bvxm_batch.run_process();
## process to transfer geo_index leaf id to leaf string
## the geo index is loaded from tree_txt
def obtain_leaf_string(tree_txt, out_txt):
bvxm_batch.init_process("volmTransferGeoIndexIDToStr")
bvxm_batch.set_input_string(0, tree_txt)
bvxm_batch.set_input_string(1, out_txt)
bvxm_batch.run_process()
## process to transfer geo_index leaf id to leaf string
## the geo index is created from given region and min_size
def obtain_leaf_string2(min_size, in_poly, out_txt):
bvxm_batch.init_process("volmTransferGeoIndexIDToStr")
bvxm_batch.set_input_float(0, min_size)
bvxm_batch.set_input_string(1, in_poly)
bvxm_batch.set_input_string(2, out_txt)
bvxm_batch.run_process()
def generate_height_map_from_ply(ply_folder, ni, nj):
bvxm_batch.init_process("volmGenerateHeightMapFromPlyProcess")
bvxm_batch.set_input_string(0, ply_folder);
bvxm_batch.set_input_unsigned(1, ni);
bvxm_batch.set_input_unsigned(2, nj);
bvxm_batch.run_process()
(id, type) = bvxm_batch.commit_output(0);
out = dbvalue(id, type);
return out
## process to refine the height map obtained from bvxm world
## max_h and min_h are the predominant height for sky and ground mask
def refine_bvxm_height_map(img, max_h, min_h):
bvxm_batch.init_process("volmRefineBvxmHeightMapProcess")
bvxm_batch.set_input_from_db(0, img)
bvxm_batch.set_input_float(1, max_h)
bvxm_batch.set_input_float(2, min_h)
status = bvxm_batch.run_process()
if status:
(id, type) = bvxm_batch.commit_output(0);
out_img = dbvalue(id, type);
return out_img;
else:
out_img = 0;
return out_img;