Commit 2d5052a0 authored by Andrey Filippov's avatar Andrey Filippov

Before isolating image dimensions and zoom from map instance

parent af6220a8
......@@ -326,7 +326,23 @@ public class IntersceneMatchParameters {
public double ct_min = 3.7; //
public double ct_max = 4.5; //
public double ct_step = 0.02; // pix
public int ct_expand = 2; // pix // expand section area by 1 pixel in 8 directions
public int ct_expand = -4; // pix // expand section area by 1 pixel in 8 directions
// Generate terrain surface (cut trees)
// flat surface extraction
// public boolean terr_enable = true;
public double terr_rmse_above = 1.0; // from average
public double terr_rmse_below = 1.0; // from average, // positive value
public int terr_num_refine = 5;
public double terr_frac_above = 0.4;
public double terr_frac_below = 0.3;
public double terr_rthrsh_abv = 0.01; // 08; // later may be relative to SfM ?
public boolean terr_flat_brd = true; // when filling NaN, replace NaN border tiles with flat ground
public int terr_expand = 4; // 2;
public boolean terr_save = true; // save debug data in model directory
// Debug and visualization
public boolean scene_is_ref_test= false; // correlate ref-2-ref for testing
......@@ -1164,6 +1180,19 @@ min_str_neib_fpn 0.35
gd.addNumericField("CT scan step", this.ct_step, 5,7,"pix","Scan step.");
gd.addNumericField("CT scan expand section", this.ct_expand, 0,3,"tiles","expand section area, 2 - a tile in 8 directions.");
gd.addMessage ("Terrain generation (w/o vegetation)");
// gd.addCheckbox ("Generate terrain", this.terr_enable, "Generate \"CT scan\" of the vegetation.");
gd.addNumericField("Plain fit, limit above", this.terr_rmse_above,5,7,"std","Discard higher disparity, relative to stadard deviation.");
gd.addNumericField("Plain fit, limit below", this.terr_rmse_below,5,7,"std","Discard lower disparity, relative to stadard deviation.");
gd.addNumericField("Plain fitting passes", this.terr_num_refine, 0,3,"","Number of passes to refine ground plane fitting.");
gd.addNumericField("Plain fit, outliers above", this.terr_frac_above*100,5,7,"%","Discard this fraction of outliers above plane.");
gd.addNumericField("Plain fit, outliers below", this.terr_frac_below*100,5,7,"%","Discard this fraction of outliers above plane.");
gd.addNumericField("Relative vegetation disparity", this.terr_rthrsh_abv,5,7,"x","Relative to disparity threshold of vegetation height.");
gd.addCheckbox ("Assign border to fitted plane", this.terr_flat_brd,"Assign NaN border tiles to fitted plane disparity.");
gd.addNumericField("Expand detected vegetation area", this.terr_expand, 0,3,"tiles","Expand section area, 2 - a tile in 8 directions.");
gd.addCheckbox ("Save debug terrain images", this.terr_save, "Save terrain-related debug image in the model directory.");
gd.addMessage ("Debug and visialization parameters");
gd.addCheckbox ("Replace scene with reference scene", this.scene_is_ref_test,
"Correlate reference scene with itself for testing (may want to manually change scene_atr and scene_xyz in debug mode)");
......@@ -2097,6 +2126,17 @@ min_str_neib_fpn 0.35
this.ct_step = gd.getNextNumber();
this.ct_expand = (int) gd.getNextNumber();
// this.terr_enable= gd.getNextBoolean();
this.terr_rmse_above= gd.getNextNumber();
this.terr_rmse_below= gd.getNextNumber();
this.terr_num_refine= (int) gd.getNextNumber();
this.terr_frac_above= 0.01*gd.getNextNumber();
this.terr_frac_below= 0.01*gd.getNextNumber();
this.terr_rthrsh_abv= gd.getNextNumber();
this.terr_flat_brd= gd.getNextBoolean();
this.terr_expand= (int) gd.getNextNumber();
this.terr_save= gd.getNextBoolean();
this.scene_is_ref_test = gd.getNextBoolean();
this.render_ref = gd.getNextBoolean();
this.render_scene = gd.getNextBoolean();
......@@ -2713,6 +2753,17 @@ min_str_neib_fpn 0.35
properties.setProperty(prefix+"ct_step", this.ct_step+""); // double
properties.setProperty(prefix+"ct_expand", this.ct_expand+""); // int
// properties.setProperty(prefix+"terr_enable", this.terr_enable+""); // boolean
properties.setProperty(prefix+"terr_rmse_above", this.terr_rmse_above+""); // double
properties.setProperty(prefix+"terr_rmse_below", this.terr_rmse_below+""); // double
properties.setProperty(prefix+"terr_num_refine", this.terr_num_refine+""); // int
properties.setProperty(prefix+"terr_frac_above", this.terr_frac_above+""); // double
properties.setProperty(prefix+"terr_frac_below", this.terr_frac_below+""); // double
properties.setProperty(prefix+"terr_rthrsh_abv", this.terr_rthrsh_abv+""); // double
properties.setProperty(prefix+"terr_flat_brd", this.terr_flat_brd+""); // boolean
properties.setProperty(prefix+"terr_expand", this.terr_expand+""); // int
properties.setProperty(prefix+"terr_save", this.terr_save+""); // boolean
properties.setProperty(prefix+"scene_is_ref_test", this.scene_is_ref_test+""); // boolean
properties.setProperty(prefix+"render_ref", this.render_ref+""); // boolean
properties.setProperty(prefix+"render_scene", this.render_scene+""); // boolean
......@@ -3292,6 +3343,17 @@ min_str_neib_fpn 0.35
if (properties.getProperty(prefix+"ct_step")!=null) this.ct_step=Double.parseDouble(properties.getProperty(prefix+"ct_step"));
if (properties.getProperty(prefix+"ct_expand")!=null) this.ct_expand=Integer.parseInt(properties.getProperty(prefix+"ct_expand"));
// if (properties.getProperty(prefix+"terr_enable")!=null) this.terr_enable=Boolean.parseBoolean(properties.getProperty(prefix+"terr_enable"));
if (properties.getProperty(prefix+"terr_rmse_above")!=null) this.terr_rmse_above=Double.parseDouble(properties.getProperty(prefix+"terr_rmse_above"));
if (properties.getProperty(prefix+"terr_rmse_below")!=null) this.terr_rmse_below=Double.parseDouble(properties.getProperty(prefix+"terr_rmse_below"));
if (properties.getProperty(prefix+"terr_num_refine")!=null) this.terr_num_refine=Integer.parseInt(properties.getProperty(prefix+"terr_num_refine"));
if (properties.getProperty(prefix+"terr_frac_above")!=null) this.terr_frac_above=Double.parseDouble(properties.getProperty(prefix+"terr_frac_above"));
if (properties.getProperty(prefix+"terr_frac_below")!=null) this.terr_frac_below=Double.parseDouble(properties.getProperty(prefix+"terr_frac_below"));
if (properties.getProperty(prefix+"terr_rthrsh_abv")!=null) this.terr_rthrsh_abv=Double.parseDouble(properties.getProperty(prefix+"terr_rthrsh_abv"));
if (properties.getProperty(prefix+"terr_flat_brd")!=null) this.terr_flat_brd=Boolean.parseBoolean(properties.getProperty(prefix+"terr_flat_brd"));
if (properties.getProperty(prefix+"terr_expand")!=null) this.terr_expand=Integer.parseInt(properties.getProperty(prefix+"terr_expand"));
if (properties.getProperty(prefix+"terr_save")!=null) this.terr_save=Boolean.parseBoolean(properties.getProperty(prefix+"terr_save"));
if (properties.getProperty(prefix+"scene_is_ref_test")!=null) this.scene_is_ref_test=Boolean.parseBoolean(properties.getProperty(prefix+"scene_is_ref_test"));
if (properties.getProperty(prefix+"render_ref")!=null) this.render_ref=Boolean.parseBoolean(properties.getProperty(prefix+"render_ref"));
if (properties.getProperty(prefix+"render_scene")!=null) this.render_scene=Boolean.parseBoolean(properties.getProperty(prefix+"render_scene"));
......@@ -3876,6 +3938,17 @@ min_str_neib_fpn 0.35
imp.ct_step = this.ct_step;
imp.ct_expand = this.ct_expand;
// imp.terr_enable = this.terr_enable;
imp.terr_rmse_above = this.terr_rmse_above;
imp.terr_rmse_below = this.terr_rmse_below;
imp.terr_num_refine = this.terr_num_refine;
imp.terr_frac_above = this.terr_frac_above;
imp.terr_frac_below = this.terr_frac_below;
imp.terr_rthrsh_abv = this.terr_rthrsh_abv;
imp.terr_flat_brd = this.terr_flat_brd;
imp.terr_expand = this.terr_expand;
imp.terr_save = this.terr_save;
imp.scene_is_ref_test = this.scene_is_ref_test;
imp.render_ref = this.render_ref;
imp.render_scene = this.render_scene;
......
......@@ -6182,6 +6182,7 @@ public class OpticalFlow {
}
}
double terr_rthrsh_abv = clt_parameters.imp.terr_rthrsh_abv;
if (export_CT) {
double [][][] ct_scans = new double [(int) Math.ceil((ct_max-ct_min)/ct_step) + 1][][];
......@@ -6199,6 +6200,7 @@ public class OpticalFlow {
ct_step, // final double ct_step,
ct_expand, // final int ct_expand,
false, // final boolean terrain_mode,
terr_rthrsh_abv, // final double terrain_threshold, // in disparity so may depend on average, sfm, etc.
null, // final double [][] hdr_render_size, // { hdr_whs[3],hdr_x0y0[2]}; save/use rendering parameters
false, // final boolean hdr_render_slave,// use rendering parameters (to match other mode)
updateStatus, // final boolean updateStatus,
......@@ -6233,7 +6235,7 @@ public class OpticalFlow {
}
}
// debugging 3D model
// 3D model
int [] whs = new int[3];
double [] x0y0 = new double[2];
double [][] hdr_render_size = new double[2][];
......@@ -6252,6 +6254,7 @@ public class OpticalFlow {
0, // final double ct_step,
0, // final int ct_expand,
false, // final boolean terrain_mode,
terr_rthrsh_abv, // final double terrain_threshold, // in disparity so may depend on average, sfm, etc.
hdr_render_size, // final double [][] hdr_render_size, // { hdr_whs[3],hdr_x0y0[2]}; save/use rendering parameters
false, // final boolean hdr_render_slave,// use rendering parameters (to match other mode)
updateStatus, // final boolean updateStatus,
......@@ -6274,6 +6277,7 @@ public class OpticalFlow {
0, // final double ct_step,
0, // final int ct_expand,
true, // final boolean terrain_mode,
terr_rthrsh_abv, // final double terrain_threshold, // in disparity so may depend on average, sfm, etc.
hdr_render_size, // final double [][] hdr_render_size, // { hdr_whs[3],hdr_x0y0[2]}; save/use rendering parameters
hdr_render_slave, // final boolean hdr_render_slave,// use rendering parameters (to match other mode)
updateStatus, // final boolean updateStatus,
......
......@@ -1714,6 +1714,7 @@ public class QuadCLTCPU {
int num_refine,
double frac_above,
double frac_below,
double [] plane, // null or double [3] - will return {tiltX,tiltY,average}
String debug_title) {
final double [] plane_disparity = new double [disparity.length];
final int num_bins = 1024;
......@@ -1757,6 +1758,11 @@ public class QuadCLTCPU {
tilesX, // final int width,
center_xy); // final double [] xy0)
}
if (plane != null) {
plane[0] = plane_tiles[0];
plane[1] = plane_tiles[1];
plane[2] = plane_tiles[2];
}
for (int nTile = 0; nTile < disparity.length; nTile++) {
int tileX = nTile % tilesX;
......
......@@ -2436,7 +2436,9 @@ public class TexturedModel {
final double [] flat,
final double threshold_above,
final int expand,
final int width){
final boolean flat_border,
final int width,
boolean [] dbg_mask){
final int height = disparity.length/width;
double [] terrain_disparity = disparity.clone();
boolean [] above_terrain = new boolean [disparity.length];
......@@ -2452,10 +2454,31 @@ public class TexturedModel {
for (int i = 0; i <above_terrain.length; i++) if (above_terrain[i]){
terrain_disparity[i] = Double.NaN;
}
if (flat_border) {
for (int h = 0; h < height; h+=height-1) {
for (int w = 0; w < width; w++) {
int indx = h*width+w;
if (Double.isNaN(terrain_disparity[indx])) {
terrain_disparity[indx] = flat[indx];
}
}
}
for (int w = 0; w < width; w+= width-1) {
for (int h = 0; h < height; h++) {
int indx = h*width+w;
if (Double.isNaN(terrain_disparity[indx])) {
terrain_disparity[indx] = flat[indx];
}
}
}
}
OrthoMap.fillNaNs(
terrain_disparity, // double [] data,
tn, // TileNeibs tn,
3); // int min_neibs)
if (dbg_mask != null) {
System.arraycopy(above_terrain, 0, dbg_mask, 0, dbg_mask.length);
}
return terrain_disparity;
}
......@@ -2569,6 +2592,7 @@ public class TexturedModel {
final double ct_step,
final int ct_expand_in,
final boolean terrain_mode,
final double terr_rthrsh_abv, // relative to average disparity so may depend sfm, etc.
final double [][] hdr_render_size, // { hdr_whs[3],hdr_x0y0[2]}; save/use rendering parameters
final boolean hdr_render_slave,// use rendering parameters (to match other mode)
final boolean updateStatus,
......@@ -2662,6 +2686,17 @@ public class TexturedModel {
final double gsmth_str_bump = clt_parameters.gsmth_str_bump ; // 0.5; // enable bumps above level stronger than this
final double gsmth_str_dip = clt_parameters.gsmth_str_dip ; // 0.55; // enable dips below level stronger than this
final double rmse_above = clt_parameters.imp.terr_rmse_above; //1.0; // from average
final double rmse_below = clt_parameters.imp.terr_rmse_below; //1.0; // from average, // positive value
final int num_refine = clt_parameters.imp.terr_num_refine; //5;
final double frac_above = clt_parameters.imp.terr_frac_above; //0.4;
final double frac_below = clt_parameters.imp.terr_frac_below; // 0.3;
final boolean flat_border = clt_parameters.imp.terr_flat_brd; // when filling NaN, replace NaN border tiles with flat ground
final int expand_above = clt_parameters.imp.terr_expand; // 4; // 2;
final boolean save_terrain = clt_parameters.imp.terr_save & terrain_mode; // save debug data in model directory
// final int ref_index = scenes.length - 1;
final QuadCLT ref_scene = scenes[ref_index];
final TileProcessor tp = ref_scene.getTileProcessor();
......@@ -2832,15 +2867,9 @@ public class TexturedModel {
}
}
double [] smooth_ground = null;
double rmse_above = 1.0; // from average
double rmse_below = 1.0; // from average, // positive value
int num_refine = 5;
double frac_above = 0.4;
double frac_below = 0.3;
double [] flat_ground = null;
final double threshold_above = 0.05;
final int expand_above = 4; // 2;
// final double threshold_above = 0.03;
if (gsmth_enable && (!has_sfm || gsmth_sfm_gnd)) {
smooth_ground = scenes[ref_index].getSmoothGround(
......@@ -2848,6 +2877,7 @@ public class TexturedModel {
has_sfm, // boolean sfm_mode,
debugLevel);
String title_flat = (show_bs_debug)? (ref_scene.getImageName()+"-dbg_flat"):null ;
double [] plane = new double[3];
flat_ground = scenes[ref_index].getFlatGround(
smooth_ground, // double [] disparity,
rmse_above, //double rmse_above, // from average
......@@ -2855,8 +2885,9 @@ public class TexturedModel {
num_refine, // int num_refine,
frac_above, // double frac_above,
frac_below, // double frac_below,
plane, // double [] plane, // null or double [3] - will return {tiltX,tiltY,average}
title_flat); // String debug_title)
double threshold_above = plane[2] * terr_rthrsh_abv;
if (smooth_ground != null) {
if (has_sfm && gsmth_sfm_deviate) {
mixed_flat = true;
......@@ -2888,27 +2919,46 @@ public class TexturedModel {
for (int i = 0; i < single_disparity.length; i++) if (ss_fg_bg_common[1][i] > ss_fg_bg_common[0][i]) {
single_disparity[i] = ds_fg_bg_common[1][i];
}
boolean [] terr_mask = (save_terrain || show_bs_debug) ? (new boolean [ single_disparity.length]):null;
double [] terrain_disparity = getTerrainDisparity(
single_disparity, // final double [] disparity, // maybe already filtered from smooth (combined, allow strong deviations)
flat_ground, // final double [] flat,
threshold_above, // final double threshold_above,
expand_above, // final int expand,
tilesX); // final int width) ;
flat_border, // final boolean flat_border,
tilesX, // final int width) ;
terr_mask); // boolean [] dbg_mask);
if (show_bs_debug) {
String [] dbg_titles = {"FG","BG","FG_LMA", "BG_LMA", "GND", "FLAT", "SINGLE", "TERRAIN", "FS", "BS"};
if (save_terrain || show_bs_debug) {
String [] dbg_titles = {"FG","BG","FG_LMA", "BG_LMA", "GND", "FLAT", "SINGLE", "TERRAIN", "TERR-MASK", "FS", "BS"};
double [] terr_dbg = new double [terr_mask.length];
for (int i = 0; i < terr_dbg.length; i++) {
terr_dbg[i] = terr_mask[i]? 10: Double.NaN;
}
double [][] dbg_img = {
ds_fg_bg_common[0], ds_fg_bg_common[1], dls_fg[1], dls_bg[1],
smooth_ground, flat_ground, single_disparity, terrain_disparity,
smooth_ground, flat_ground, single_disparity, terrain_disparity,terr_dbg,
ss_fg_bg_common[0], ss_fg_bg_common[1]}; // here BG==FG
String dbg_suffix = String.format("-fg-bg-disparity_strength-LMA-GND-FLAT_th%.4f",threshold_above);
if (show_bs_debug) {
ShowDoubleFloatArrays.showArrays(
dbg_img,
tilesX,
dbg_img[0].length/tilesX,
true,
ref_scene.getImageName()+"-fg-bg-disparity_strength-LMA-GND-FLAT",
ref_scene.getImageName()+dbg_suffix,
dbg_titles);
}
if (save_terrain) {
scenes[ref_index].saveDoubleArrayInModelDirectory(
dbg_suffix, // String suffix,
dbg_titles, // String [] labels, // or null
dbg_img, // double [][] data,
tilesX, // int width, // int tilesX,
tilesY); // int height, // int tilesY,
}
}
scenes[ref_index].setSmoothGround( // was in the end
clt_parameters, // CLTParameters clt_parameters,
smooth_ground, // double [] smooth_ground,
......
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