Commit 0a4fdfe3 authored by Andrey Filippov's avatar Andrey Filippov

Copied affine export from lwir16 branch

parent f7200d40
......@@ -174,30 +174,34 @@ public class ComboMatch {
boolean display_pairs = false;
boolean create_map = false;
boolean create_equalize = false;
boolean use_saved_collection = false; // true; // false;
boolean save_collection = false; // true;
boolean process_correlation = true; // use false to save new version of data
int num_tries_fit = 10;
boolean update_match = true; // use false to save new version of data
boolean use_saved_collection = false; // true; // false;
boolean save_collection = false; // true;
boolean process_correlation = true; // use false to save new version of data
int num_tries_fit = 10;
boolean update_match = true; // use false to save new version of data
boolean render_match = false; // true;
boolean test_multi_lma = false;
boolean pattern_match = !dflt_options; //true; // false;
boolean bounds_to_indices = true;
int temp_mode = 0;
boolean restore_temp = true;
double frac_remove = clt_parameters.imp.pmtch_frac_remove; // 0.15;
double metric_error = clt_parameters.imp.pmtch_metric_err; // 0.05; // 0.02;// 2 cm
boolean update_files = false;
boolean update_lla = false; // re-read file metadata
boolean update_kernel_patterns = false;
boolean update_bl_bc = false;
boolean fix_duplicates = false;
String [] suffixes_bl_bc= {"","-BL","-BC"};
boolean log_append = clt_parameters.imp.pwise_log_append;
boolean restore_temp = true;
double frac_remove = clt_parameters.imp.pmtch_frac_remove; // 0.15;
double metric_error = clt_parameters.imp.pmtch_metric_err; // 0.05; // 0.02;// 2 cm
boolean update_files = false;
boolean update_lla = false; // re-read file metadata
boolean update_kernel_patterns = false;
boolean update_bl_bc = false;
boolean export_affine = false; // export per-scene affines
boolean export_affine2 = false; // export per-pair affines
boolean fix_duplicates = false;
String [] suffixes_bl_bc= {"","-BL","-BC"};
boolean log_append = clt_parameters.imp.pwise_log_append;
String log_path = clt_parameters.imp.pwise_log_path;
String omtch_img_set = clt_parameters.imp.omtch_img_set;
......@@ -247,23 +251,27 @@ public class ComboMatch {
gd.addCheckbox ("Equalize intensities", create_equalize, "Create map intensities equalization from pairwise matches.");
gd.addNumericField("Remove fraction of worst matches", frac_remove, 3,7,"", "When fitting scenes remove this fraction of worst match.");
gd.addNumericField("Maximal metric error", metric_error, 3,7,"m", "Maximal tolerable fitting error caused by elevation variations.");
if (use_marked_image ) {
gd.addCheckbox ("Use marked image data", true, "Use markes from the selected image");
}
gd.addCheckbox ("Update scene files", update_files, "Re-read files as specified in .list file, possibly changing versions");
gd.addCheckbox ("Update files metadata", update_lla, "Re-read files metadata (if it was modified)");
gd.addCheckbox ("Update kernels/patterns", update_kernel_patterns, "Re-read kernels and patterns from *.list file");
gd.addCheckbox ("Remove duplicate scenes", fix_duplicates, "Remove scenes with the same timestamp");
if (use_marked_image ) {
gd.addCheckbox ("Use marked image data", true, "Use markes from the selected image");
}
gd.addCheckbox ("Update scene files", update_files, "Re-read files as specified in .list file, possibly changing versions");
gd.addCheckbox ("Update files metadata", update_lla, "Re-read files metadata (if it was modified)");
gd.addCheckbox ("Update kernels/patterns", update_kernel_patterns, "Re-read kernels and patterns from *.list file");
gd.addCheckbox ("Remove duplicate scenes", fix_duplicates, "Remove scenes with the same timestamp");
gd.addCheckbox ("Update BC/BL suffix", update_bl_bc,
"Change source filenames to use -BC for bicubic, -BL - for bilinear, or empty - for old bilinear files");
gd.addChoice("BL/BC suffix:",
suffixes_bl_bc,
suffixes_bl_bc[suffix_bc_bl_indx],
"Select interpolation mode of the source files: old bilinear (empty), bilinear (-BL), or bicubic (-BC)", 0);
gd.addCheckbox ("Write log file", log_append, "Enable writing log file with matching results.");
gd.addStringField ("Log file full path", log_path, 150, "Path of the log file to be appended.");
// gd.addCheckbox ("Read no-alt data (old)", READ_NO_ALT, "Read older format data file where pairs do not have alt_data[].");
suffixes_bl_bc,
suffixes_bl_bc[suffix_bc_bl_indx],
"Select interpolation mode of the source files: old bilinear (empty), bilinear (-BL), or bicubic (-BC)", 0);
gd.addCheckbox ("Export scene affines", export_affine, "Export per-scene affines in text format for migration.");
gd.addCheckbox ("Export pairs affines", export_affine2, "Export per-pair affines in text format for migration.");
gd.addCheckbox ("Write log file", log_append, "Enable writing log file with matching results.");
gd.addStringField ("Log file full path", log_path, 150, "Path of the log file to be appended.");
// gd.addCheckbox ("Read no-alt data (old)", READ_NO_ALT, "Read older format data file where pairs do not have alt_data[].");
......@@ -272,12 +280,14 @@ public class ComboMatch {
if (gd.wasCanceled()) return false;
omtch_img_set = ComboMatch.FILES_LISTS_PATHS[gd.getNextChoiceIndex()];
String files_list_path = omtch_img_set+".list";
String orthoMapsCollection_path =omtch_img_set+".data";
use_saved_collection = gd.getNextBoolean();
save_collection = gd.getNextBoolean();
String orthoMapsCollection_savepath = save_collection?orthoMapsCollection_path:null;
omtch_img_set = ComboMatch.FILES_LISTS_PATHS[gd.getNextChoiceIndex()];
String files_list_path = omtch_img_set+".list";
String orthoMapsCollection_path =omtch_img_set+".data";
String affines_path = omtch_img_set+".affines"; // for export per-scene affines
String affines2_path = omtch_img_set+".affines2"; // for export per-pair affines
use_saved_collection = gd.getNextBoolean();
save_collection = gd.getNextBoolean();
String orthoMapsCollection_savepath = save_collection?orthoMapsCollection_path:null;
process_correlation= gd.getNextBoolean();
num_tries_fit = (int) gd.getNextNumber();
update_match= gd.getNextBoolean();
......@@ -304,49 +314,112 @@ public class ComboMatch {
create_equalize = gd.getNextBoolean();
frac_remove = gd.getNextNumber();
metric_error= gd.getNextNumber();
if (use_marked_image ) { // will only be used if found and asked
use_marked_image= gd.getNextBoolean();
}
update_files= gd.getNextBoolean();
update_lla= gd.getNextBoolean();
update_kernel_patterns= gd.getNextBoolean();
fix_duplicates= gd.getNextBoolean();
update_bl_bc= gd.getNextBoolean();
suffix_bc_bl_indx = gd.getNextChoiceIndex();
log_append = gd.getNextBoolean();
log_path = gd.getNextString();
// READ_NO_ALT = gd.getNextBoolean();
if (use_marked_image ) { // will only be used if found and asked
use_marked_image= gd.getNextBoolean();
}
update_files= gd.getNextBoolean();
update_lla= gd.getNextBoolean();
update_kernel_patterns= gd.getNextBoolean();
fix_duplicates= gd.getNextBoolean();
update_bl_bc= gd.getNextBoolean();
suffix_bc_bl_indx = gd.getNextChoiceIndex();
export_affine = gd.getNextBoolean();
export_affine2 = gd.getNextBoolean();
log_append = gd.getNextBoolean();
log_path = gd.getNextString();
// READ_NO_ALT = gd.getNextBoolean();
// PairwiseOrthoMatch.READ_NO_ALT = READ_NO_ALT; // modifies PairwiseOrthoMatch.readObject() behavior
OrthoMapsCollection maps_collection=null;
boolean use_files_list = false;
if (use_saved_collection) {
try {
maps_collection = OrthoMapsCollection.readOrthoMapsCollection (orthoMapsCollection_path);
} catch (ClassNotFoundException | IOException e) {
use_files_list = true;
System.out.println("Saved data not found: "+orthoMapsCollection_path+", building from a list "+files_list_path);
}
//files_list_path
if (!use_files_list) {
} catch (ClassNotFoundException | IOException e) {
use_files_list = true;
System.out.println("Saved data not found: "+orthoMapsCollection_path+", building from a list "+files_list_path);
}
//files_list_path
if (!use_files_list) {
if (update_kernel_patterns) {
maps_collection.updateKernels(files_list_path);
maps_collection.updatePatterns(files_list_path);
}
if (update_files) {
maps_collection.updateFiles(files_list_path);
}
}
} else {
use_files_list = true;
}
if (use_files_list) { // using files list
maps_collection = new OrthoMapsCollection(files_list_path, null); // should have ".list" extension
maps_collection.updateNumberScenes();
maps_collection.updateSfmGain();
}
if (fix_duplicates) {
removeDuplicateScenes (maps_collection);
}
maps_collection.updateKernels(files_list_path);
maps_collection.updatePatterns(files_list_path);
}
if (update_files) {
maps_collection.updateFiles(files_list_path);
}
}
} else {
use_files_list = true;
}
if (use_files_list) { // using files list
maps_collection = new OrthoMapsCollection(files_list_path, null); // should have ".list" extension
maps_collection.updateNumberScenes();
maps_collection.updateSfmGain();
}
if (export_affine) {
StringBuffer sb = new StringBuffer();
for (OrthoMap omap : maps_collection.ortho_maps) {
String name = omap.getName();
double [][] affine = omap.getAffine();
if (affine != null) {
sb.append(String.format("AFFINE %s %11.8f %11.8f %11.8f %11.8f %11.8f %11.8f\n",
name, affine[0][0], affine[0][1], affine[0][2], affine[1][0], affine[1][1], affine[1][2]));
}
}
CalibrationFileManagement.saveStringToFile (
affines_path, //String path,
sb.toString(), // data,
false); // boolean append)
}
if (export_affine2) {
StringBuffer sb = new StringBuffer();
ArrayList<Point> pairs_list = new ArrayList<Point>();
for (OrthoMap map : maps_collection.ortho_maps) {
for (String other_name: map.pairwise_matches.keySet()) {
pairs_list.add(new Point(
maps_collection.getIndex(map.getName()),
maps_collection.getIndex(other_name)));
}
}
Collections.sort(pairs_list, new Comparator<Point>() {
@Override
public int compare(Point lhs, Point rhs) {
return (rhs.x > lhs.x) ? -1 : (rhs.x < lhs.x) ? 1 :
((rhs.y > lhs.y) ? -1 : (rhs.y < lhs.y) ? 1 : 0); // increasing
}
});
for (Point pair: pairs_list) {
PairwiseOrthoMatch pom = maps_collection.ortho_maps[pair.x].getMatch(
maps_collection.ortho_maps[pair.y].getName(), false); // undef_only || nan_rms);
if ((pom !=null) && pom.isDefined()) {
double overlap = pom.overlap;
double [][] affine = pom.getAffine();
sb.append(String.format("AFFINE2 %s %s %11.8f %11.8f %11.8f %11.8f %11.8f %11.8f %11.8f\n",
maps_collection.ortho_maps[pair.x].getName(),
maps_collection.ortho_maps[pair.y].getName(),
overlap,
affine[0][0], affine[0][1], affine[0][2], affine[1][0], affine[1][1], affine[1][2]));
}
}
CalibrationFileManagement.saveStringToFile (
affines2_path, //String path,
sb.toString(), // data,
false); // boolean append)
}
if (export_affine || export_affine2) {
return true; // do not save
}
if (fix_duplicates) {
removeDuplicateScenes (maps_collection);
}
if (update_bl_bc) {
boolean OK = updateBlBcFileNames(
......@@ -358,6 +431,8 @@ public class ComboMatch {
}
}
String [] names = maps_collection.getNames(); // null
if (object_list != null) {
int corr_size = 128;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment