Commit c5b6a7a7 authored by Andrey Filippov's avatar Andrey Filippov

Prepareing data for rig bundle adjustment

parent dd1befbb
......@@ -38,6 +38,33 @@ public class BiQuadParameters {
public double inf_max_disp_aux = 0.15;
public double inf_max_disp_rig = 0.5; // maybe even higher (2.0) to lock to initially high mismatch
public double first_max_disp_main = 0.5; // before refinement
public double first_max_disp_aux = 0.5;
public double first_max_disp_rig = 4.0; //
public int num_refine_master = 5; // Number of disparity refinement passes
public int num_refine_inter = 2; // Number of disparity refinement passes
public double near_max_disp_main = 0.3; // ater refinement
public double near_max_disp_aux = 0.2;
public double near_max_disp_rig = 0.5; //
public double refine_min_strength = 0.1; //
public double refine_tolerance = 0.03; //
public double rig_disp_range = 10.0; // maximal disparity to try to adjust auxiliary camera pose
public int rig_num_disp_steps = 2; // number of disparity vaues to try - 1 - only infinity, 2 - infinity and near, ...
public int rig_adjust_full_cycles= 1; // number of full rig adjustment steps (with re-creating tiles lists)
public int rig_adjust_short_cycles= 15; // maximal number of full rig adjustment steps (with current tiles lists)
public double rig_adjust_short_threshold= 0.00001;// rms relative improvement to exit short cycle
public boolean rig_adjust_orientation = true; //
public boolean rig_adjust_zoom = true; //
public boolean rig_adjust_angle = true; //
public boolean rig_adjust_distance = false; // distance between camera centers
public boolean rig_adjust_forward = false; // aux camera forward from the principal plane (not implemented)
public double rig_correction_scale= 1.0; // scale calcualated correction
public void dialogQuestions(GenericJTabbedDialog gd) {
gd.addCheckbox ("Debug rig/bi-camera functionality ", this.rig_mode_debug,"Enable debugging of the methods related to dual camera rig");
gd.addCheckbox ("Use poly for main/aux/rig correlations (false - CM)", this.use_poly,"Use LMA/polynomial if correlation is strong enough");
......@@ -59,6 +86,50 @@ public class BiQuadParameters {
"Do not use tile for infinity adjustment if absolute value of the main camera disparity is too high");
gd.addNumericField("Maximal absolute value of inter-camera disparity to use for infinity rig adjustment", this.inf_max_disp_rig, 3,6,"pix",
"Do not use tile for infinity adjustment if absolute value of the inter-camera disparity is too high");
gd.addNumericField("Maximal absolute value of main camera disparity difference near objects, before refinement", this.first_max_disp_main, 3,6,"pix",
"First pass for near objects, before refinement pass");
gd.addNumericField("Maximal absolute value of aux camera disparity difference near objects, before refinement", this.first_max_disp_aux, 3,6,"pix",
"First pass for near objects, before refinement pass");
gd.addNumericField("Maximal absolute value of inter-camera disparity difference near objects, before refinement",this.first_max_disp_rig, 3,6,"pix",
"First pass for near objects, before refinement pass");
gd.addNumericField("Number of disparity refinement passes for the non-infinity measurements, master camera", this.num_refine_master, 0,3,"",
"Remeasure after setting per-tile expected disparity (phase shift before correlation)");
gd.addNumericField("Number of disparity refinement passes for the non-infinity measurements, inter-cameras", this.num_refine_inter, 0,3,"",
"Remeasure after setting per-tile expected disparity (phase shift before correlation)");
gd.addNumericField("Maximal absolute value of main camera disparity difference near objects, after refinement", this.near_max_disp_main, 3,6,"pix",
"After refinement pass (target disparity set to the measured one");
gd.addNumericField("Maximal absolute value of aux camera disparity difference near objects, after refinement", this.near_max_disp_aux, 3,6,"pix",
"After refinement pass (target disparity set to the measured one");
gd.addNumericField("Maximal absolute value of inter-camera disparity difference near objects, after refinement", this.near_max_disp_rig, 3,6,"pix",
"After refinement pass (target disparity set to the measured one");
gd.addNumericField("Minimal correlation strength to try to refine disparity", this.refine_min_strength, 3,6,"",
"Re-scan tile with updated expected disparity if previously measured strength was above this");
gd.addNumericField("Refine tolerance - do not try to refine if residual disparity is lower", this.refine_tolerance, 3,6,"pix",
"Re-scan tile only if residual disparity absolute value is lower that this");
gd.addNumericField("Maximal disparity to try for the rig adjustment", this.rig_disp_range, 3,6,"pix",
"Maximal disparity of the main camera when adjusting auxiliary camera pose");
gd.addNumericField("Number of disparity values to try between zero (infinity) and the maximal one", this.rig_num_disp_steps, 0,3,"",
"1 - only infinity, 2 - infinity and maximal, 3 - infinuty, half-maximal and maximal");
gd.addNumericField("Number of full rig adjustment cycles", this.rig_adjust_full_cycles, 0,3,"",
"Includes full-frame scanning and re-creating the sample tile list");
gd.addNumericField("Number of short rig adjustment cycles", this.rig_adjust_short_cycles, 0,3,"",
"Re-scan only previously selected tiles");
gd.addNumericField("Minimal RMS improvement after short cycle to exit", this.rig_adjust_short_threshold, 3,6,"",
"Short cycle iteration finish after relative RMS improvement is less than this of maximal number of steps is exceeded");
gd.addCheckbox ("Adjust orientation (azimuth, tilt, roll) of the auxiliary camera", this.rig_adjust_orientation,"3 angles, most basic adjustment");
gd.addCheckbox ("Adjust orientation relative zoom of the auxiliary camera", this.rig_adjust_zoom,"Not likely to change, may be frozen");
gd.addCheckbox ("Adjust position of the aux camera in the main camera pricipal plane", this.rig_adjust_angle,"0 - exactly to the right, positive - higher than main");
gd.addCheckbox ("Adjust aux camera distance from the main", this.rig_adjust_distance,"Normally not practical, rely on direct measurement");
gd.addCheckbox ("Adjust aux camera distance from the main principal plane", this.rig_adjust_forward,"Not implemented, assumed zero");
gd.addNumericField("Scale calculated correction before applying", this.rig_correction_scale, 3,6,"",
"Debug feature");
}
public void dialogAnswers(GenericJTabbedDialog gd) {
this.rig_mode_debug= gd.getNextBoolean();
......@@ -72,7 +143,32 @@ public class BiQuadParameters {
this.inf_max_disp_main= gd.getNextNumber();
this.inf_max_disp_aux= gd.getNextNumber();
this.inf_max_disp_rig= gd.getNextNumber();
this.first_max_disp_main= gd.getNextNumber();
this.first_max_disp_aux= gd.getNextNumber();
this.first_max_disp_rig= gd.getNextNumber();
this.num_refine_master= (int) gd.getNextNumber();
this.num_refine_inter= (int) gd.getNextNumber();
this.near_max_disp_main= gd.getNextNumber();
this.near_max_disp_aux= gd.getNextNumber();
this.near_max_disp_rig= gd.getNextNumber();
this.refine_min_strength= gd.getNextNumber();
this.refine_tolerance= gd.getNextNumber();
this.rig_disp_range= gd.getNextNumber();
this.rig_num_disp_steps= (int) gd.getNextNumber();
this.rig_adjust_full_cycles= (int) gd.getNextNumber();
this.rig_adjust_short_cycles= (int) gd.getNextNumber();
this.rig_adjust_short_threshold= gd.getNextNumber();
this.rig_adjust_orientation= gd.getNextBoolean();
this.rig_adjust_zoom= gd.getNextBoolean();
this.rig_adjust_angle= gd.getNextBoolean();
this.rig_adjust_distance= gd.getNextBoolean();
this.rig_adjust_forward= gd.getNextBoolean();
this.rig_correction_scale= gd.getNextNumber();
}
public void setProperties(String prefix,Properties properties){
properties.setProperty(prefix+"rig_mode_debug", this.rig_mode_debug+"");
properties.setProperty(prefix+"use_poly", this.use_poly+"");
......@@ -85,6 +181,31 @@ public class BiQuadParameters {
properties.setProperty(prefix+"inf_max_disp_main", this.inf_max_disp_main+"");
properties.setProperty(prefix+"inf_max_disp_aux", this.inf_max_disp_aux+"");
properties.setProperty(prefix+"inf_max_disp_rig", this.inf_max_disp_rig+"");
properties.setProperty(prefix+"first_max_disp_main", this.first_max_disp_main+"");
properties.setProperty(prefix+"first_max_disp_aux", this.first_max_disp_aux+"");
properties.setProperty(prefix+"first_max_disp_rig", this.first_max_disp_rig+"");
properties.setProperty(prefix+"num_refine_master", this.num_refine_master+"");
properties.setProperty(prefix+"num_refine_inter", this.num_refine_inter+"");
properties.setProperty(prefix+"near_max_disp_main", this.near_max_disp_main+"");
properties.setProperty(prefix+"near_max_disp_aux", this.near_max_disp_aux+"");
properties.setProperty(prefix+"near_max_disp_rig", this.near_max_disp_rig+"");
properties.setProperty(prefix+"refine_min_strength", this.refine_min_strength+"");
properties.setProperty(prefix+"refine_tolerance", this.refine_tolerance+"");
properties.setProperty(prefix+"rig_disp_range", this.rig_disp_range+"");
properties.setProperty(prefix+"rig_num_disp_steps", this.rig_num_disp_steps+"");
properties.setProperty(prefix+"rig_adjust_full_cycles", this.rig_adjust_full_cycles+"");
properties.setProperty(prefix+"rig_adjust_short_cycles", this.rig_adjust_short_cycles+"");
properties.setProperty(prefix+"rig_adjust_short_threshold",this.rig_adjust_short_threshold+"");
properties.setProperty(prefix+"rig_adjust_orientation", this.rig_adjust_orientation+"");
properties.setProperty(prefix+"rig_adjust_zoom", this.rig_adjust_zoom+"");
properties.setProperty(prefix+"rig_adjust_angle", this.rig_adjust_angle+"");
properties.setProperty(prefix+"rig_adjust_distance", this.rig_adjust_distance+"");
properties.setProperty(prefix+"rig_adjust_forward", this.rig_adjust_forward+"");
properties.setProperty(prefix+"rig_correction_scale", this.rig_correction_scale+"");
}
public void getProperties(String prefix,Properties properties){
if (properties.getProperty(prefix+"rig_mode_debug")!=null) this.rig_mode_debug=Boolean.parseBoolean(properties.getProperty(prefix+"rig_mode_debug"));
......@@ -98,6 +219,29 @@ public class BiQuadParameters {
if (properties.getProperty(prefix+"inf_max_disp_main")!=null) this.inf_max_disp_main=Double.parseDouble(properties.getProperty(prefix+"inf_max_disp_main"));
if (properties.getProperty(prefix+"inf_max_disp_aux")!=null) this.inf_max_disp_aux=Double.parseDouble(properties.getProperty(prefix+"inf_max_disp_aux"));
if (properties.getProperty(prefix+"inf_max_disp_rig")!=null) this.inf_max_disp_rig=Double.parseDouble(properties.getProperty(prefix+"inf_max_disp_rig"));
if (properties.getProperty(prefix+"first_max_disp_main")!=null) this.first_max_disp_main=Double.parseDouble(properties.getProperty(prefix+"first_max_disp_main"));
if (properties.getProperty(prefix+"first_max_disp_aux")!=null) this.first_max_disp_aux=Double.parseDouble(properties.getProperty(prefix+"first_max_disp_aux"));
if (properties.getProperty(prefix+"first_max_disp_rig")!=null) this.first_max_disp_rig=Double.parseDouble(properties.getProperty(prefix+"first_max_disp_rig"));
if (properties.getProperty(prefix+"num_refine_master")!=null) this.num_refine_master=Integer.parseInt(properties.getProperty(prefix+"num_refine_master"));
if (properties.getProperty(prefix+"num_refine_inter")!=null) this.num_refine_inter=Integer.parseInt(properties.getProperty(prefix+"num_refine_inter"));
if (properties.getProperty(prefix+"near_max_disp_main")!=null) this.near_max_disp_main=Double.parseDouble(properties.getProperty(prefix+"near_max_disp_main"));
if (properties.getProperty(prefix+"near_max_disp_aux")!=null) this.near_max_disp_aux=Double.parseDouble(properties.getProperty(prefix+"near_max_disp_aux"));
if (properties.getProperty(prefix+"near_max_disp_rig")!=null) this.near_max_disp_rig=Double.parseDouble(properties.getProperty(prefix+"near_max_disp_rig"));
if (properties.getProperty(prefix+"refine_min_strength")!=null) this.refine_min_strength=Double.parseDouble(properties.getProperty(prefix+"refine_min_strength"));
if (properties.getProperty(prefix+"refine_tolerance")!=null) this.refine_tolerance=Double.parseDouble(properties.getProperty(prefix+"refine_tolerance"));
if (properties.getProperty(prefix+"rig_disp_range")!=null) this.rig_disp_range=Double.parseDouble(properties.getProperty(prefix+"rig_disp_range"));
if (properties.getProperty(prefix+"rig_num_disp_steps")!=null) this.rig_num_disp_steps=Integer.parseInt(properties.getProperty(prefix+"rig_num_disp_steps"));
if (properties.getProperty(prefix+"rig_adjust_full_cycles")!=null) this.rig_adjust_full_cycles=Integer.parseInt(properties.getProperty(prefix+"rig_adjust_full_cycles"));
if (properties.getProperty(prefix+"rig_adjust_short_cycles")!=null) this.rig_adjust_short_cycles=Integer.parseInt(properties.getProperty(prefix+"rig_adjust_short_cycles"));
if (properties.getProperty(prefix+"rig_adjust_short_threshold")!=null) this.rig_adjust_short_threshold=Double.parseDouble(properties.getProperty(prefix+"rig_adjust_short_threshold"));
if (properties.getProperty(prefix+"rig_adjust_orientation")!=null) this.rig_adjust_orientation=Boolean.parseBoolean(properties.getProperty(prefix+"rig_adjust_orientation"));
if (properties.getProperty(prefix+"rig_adjust_zoom")!=null) this.rig_adjust_zoom=Boolean.parseBoolean(properties.getProperty(prefix+"rig_adjust_zoom"));
if (properties.getProperty(prefix+"rig_adjust_angle")!=null) this.rig_adjust_angle=Boolean.parseBoolean(properties.getProperty(prefix+"rig_adjust_angle"));
if (properties.getProperty(prefix+"rig_adjust_distance")!=null) this.rig_adjust_distance=Boolean.parseBoolean(properties.getProperty(prefix+"rig_adjust_distance"));
if (properties.getProperty(prefix+"rig_adjust_forward")!=null) this.rig_adjust_forward=Boolean.parseBoolean(properties.getProperty(prefix+"rig_adjust_forward"));
if (properties.getProperty(prefix+"rig_correction_scale")!=null) this.rig_correction_scale=Double.parseDouble(properties.getProperty(prefix+"rig_correction_scale"));
}
@Override
public BiQuadParameters clone() throws CloneNotSupportedException {
......@@ -113,6 +257,29 @@ public class BiQuadParameters {
bqp.inf_max_disp_main = this.inf_max_disp_main;
bqp.inf_max_disp_aux = this.inf_max_disp_aux;
bqp.inf_max_disp_rig = this.inf_max_disp_rig;
bqp.first_max_disp_main= this.first_max_disp_main;
bqp.first_max_disp_aux= this.first_max_disp_aux;
bqp.first_max_disp_rig= this.first_max_disp_rig;
bqp.num_refine_master= this.num_refine_master;
bqp.num_refine_inter= this.num_refine_inter;
bqp.near_max_disp_main= this.near_max_disp_main;
bqp.near_max_disp_aux= this.near_max_disp_aux;
bqp.near_max_disp_rig= this.near_max_disp_rig;
bqp.refine_min_strength= this.refine_min_strength;
bqp.refine_tolerance= this.refine_tolerance;
bqp.rig_disp_range= this.rig_disp_range;
bqp.rig_num_disp_steps= this.rig_num_disp_steps;
bqp.rig_adjust_full_cycles= this.rig_adjust_full_cycles;
bqp.rig_adjust_short_cycles= this.rig_adjust_short_cycles;
bqp.rig_adjust_short_threshold= this.rig_adjust_short_threshold;
bqp.rig_adjust_orientation= this.rig_adjust_orientation;
bqp.rig_adjust_zoom= this.rig_adjust_zoom;
bqp.rig_adjust_angle= this.rig_adjust_angle;
bqp.rig_adjust_distance= this.rig_adjust_distance;
bqp.rig_adjust_forward= this.rig_adjust_forward;
bqp.rig_correction_scale= this.rig_correction_scale;
return bqp;
......
......@@ -100,6 +100,11 @@ public class GeometryCorrection {
public double getDisparityRadius() {
return disparityRadius;
}
public double getBaseline() {
return (rigOffset==null)?Double.NaN:rigOffset.baseline;
}
// correction of cameras mis-alignment
public CorrVector getCorrVector(double [] vector){
return new CorrVector(vector);
......
......@@ -117,6 +117,7 @@ public class ImageDtt {
static int BI_ASTR_DIAGM_INDEX = 21; //21 - strength for main diagonal pair of the aux camera
static int BI_ASTR_DIAGO_INDEX = 22; //22 - strength for main diagonal pair of the aux camera
static int BI_STR_CROSS_INDEX = 23; //23 - strength between the main the aux camera
static int BI_TARGET_INDEX = 24; //24 - target disparity
static String [] BIDISPARITY_TITLES = {
"disparity","disp_hor","disp_vert","disp_diagm","disp_diago",
......@@ -124,7 +125,7 @@ public class ImageDtt {
"bi-disparity","bi-disparity-dx","bi-disparity-dy",
"strength", "str_hor", "str_vert", "str_diagm", "str_diago",
"astrength", "astr_hor", "astr_vert", "astr_diagm", "astr_diago",
"bi-strength"};
"bi-strength", "target"};
static int DISP_FULL_INDEX = 0; // 0 - disparity for all directions of the main camera
static int DISP_HOR_INDEX = 1; // 1 - disparity for 2 horizontal pairs of the main camera
......@@ -7572,8 +7573,9 @@ public class ImageDtt {
public double [][][][][][][] clt_bi_quad(
final EyesisCorrectionParameters.CLTParameters clt_parameters,
final int [][] tile_op_main, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
final int [][] tile_op_aux, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
final int [][] tile_op, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
// final int [][] tile_op_main, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
// final int [][] tile_op_aux, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
final double [][] disparity_array, // [tilesY][tilesX] - individual per-tile expected disparity
final double [][][] image_data_main, // first index - number of image in a quad
final double [][][] image_data_aux, // first index - number of image in a quad
......@@ -7772,21 +7774,21 @@ public class ImageDtt {
tileY = nTile /tilesX;
tileX = nTile % tilesX;
tIndex = tileY * tilesX + tileX;
if ((tile_op_main[tileY][tileX] == 0) && (tile_op_main[tileY][tileX] == 0)) continue; // nothing to do for this tile
int img_mask_main = getImgMask(tile_op_main[tileY][tileX]); // which images to use
int corr_mask_main = getPairMask(tile_op_main[tileY][tileX]); // which pairs to combine in the combo: 1 - top, 2 bottom, 4 - left, 8 - right
int img_mask_aux = getImgMask(tile_op_aux[tileY][tileX]); // which images to use
int corr_mask_aux = getPairMask(tile_op_aux[tileY][tileX]); // which pairs to combine in the combo: 1 - top, 2 bottom, 4 - left, 8 - right
if (tile_op[tileY][tileX] == 0) {
if (disparity_bimap != null){
disparity_bimap[BI_TARGET_INDEX][tIndex] = Double.NaN;
}
continue; // nothing to do for this tile
}
int img_mask = getImgMask(tile_op[tileY][tileX]); // which images to use
int corr_mask = getPairMask(tile_op[tileY][tileX]); // which pairs to combine in the combo: 1 - top, 2 bottom, 4 - left, 8 - right
// mask out pairs that use missing channels
// Is it currently used with diagonals?
// TODO: use masks from tile task
for (int i = 0; i< corr_pairs.length; i++){
if ((((1 << corr_pairs[i][0]) & img_mask_main) == 0) || (((1 << corr_pairs[i][1]) & img_mask_main) == 0)) {
corr_mask_main &= ~ (1 << i);
}
if ((((1 << corr_pairs[i][0]) & img_mask_aux) == 0) || (((1 << corr_pairs[i][1]) & img_mask_aux) == 0)) {
corr_mask_aux &= ~ (1 << i);
if ((((1 << corr_pairs[i][0]) & img_mask) == 0) || (((1 << corr_pairs[i][1]) & img_mask) == 0)) {
corr_mask &= ~ (1 << i);
}
}
// boolean debugTile =(tileX == debug_tileX) && (tileY == debug_tileY);
......@@ -7802,6 +7804,9 @@ public class ImageDtt {
double [][] centersXY_aux;
double disparity_main = disparity_array[tileY][tileX];
double disparity_aux = disparity_main * geometryCorrection_aux.getDisparityRadius()/geometryCorrection_main.getDisparityRadius();
if (disparity_bimap != null){
disparity_bimap[BI_TARGET_INDEX][tIndex] = disparity_main;
}
centersXY_main = geometryCorrection_main.getPortsCoordinatesAndDerivatives(
false, // boolean use_rig_offsets,
corr_rots_main, // Matrix [] rots,
......@@ -8058,8 +8063,8 @@ public class ImageDtt {
extra_disparity_main, // final double extra_disparity,
quad_main, // final int quad, // number of subcameras
numcol, // final int numcol, // number of colors
img_mask_main, // int img_mask,
tile_op_main, // final int [][] tile_op, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
img_mask, // _main, // int img_mask,
tile_op, // _main, // final int [][] tile_op, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
clt_data_main, // final double [][][][] clt_data,
texture_tiles_main, // final double [][][][] texture_tiles, // [tilesY][tilesX]["RGBA".length()][]; null - will skip images combining
filter, // final double [] filter,
......@@ -8077,8 +8082,8 @@ public class ImageDtt {
extra_disparity_aux, // final double extra_disparity,
quad_aux, // final int quad, // number of subcameras
numcol, // final int numcol, // number of colors
img_mask_aux, // int img_mask,
tile_op_aux, // final int [][] tile_op, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
img_mask, // _aux, // int img_mask,
tile_op, // _aux, // final int [][] tile_op, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
clt_data_aux, // final double [][][][] clt_data,
texture_tiles_aux, // final double [][][][] texture_tiles, // [tilesY][tilesX]["RGBA".length()][]; null - will skip images combining
filter, // final double [] filter,
......
......@@ -297,7 +297,7 @@ public class TwoQuadCLT {
// for testing defined for a window, later the tiles to process will be calculated based on previous passes results
int [][] tile_op_main = quadCLT_main.tp.setSameTileOp(clt_parameters, clt_parameters.tile_task_op, debugLevel);
int [][] tile_op_aux = quadCLT_aux.tp.setSameTileOp (clt_parameters, clt_parameters.tile_task_op, debugLevel);
// int [][] tile_op_aux = quadCLT_aux.tp.setSameTileOp (clt_parameters, clt_parameters.tile_task_op, debugLevel);
double [][] disparity_array_main = quadCLT_main.tp.setSameDisparity(clt_parameters.disparity); // [tp.tilesY][tp.tilesX] - individual per-tile expected disparity
......@@ -338,7 +338,7 @@ public class TwoQuadCLT {
image_dtt.clt_bi_quad (
clt_parameters, // final EyesisCorrectionParameters.CLTParameters clt_parameters,
tile_op_main, // final int [][] tile_op_main, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
tile_op_aux, // final int [][] tile_op_aux, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
// tile_op_aux, // final int [][] tile_op_aux, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
disparity_array_main, // final double [][] disparity_array, // [tilesY][tilesX] - individual per-tile expected disparity
double_stacks[0], // final double [][][] image_data_main, // first index - number of image in a quad
double_stacks[1], // final double [][][] image_data_aux, // first index - number of image in a quad
......@@ -820,8 +820,8 @@ public class TwoQuadCLT {
EyesisCorrectionParameters.CLTParameters clt_parameters,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel){
final int debugLevel0){
final int debugLevel = debugLevel0 + (clt_parameters.rig.rig_mode_debug?2:0);
double [][][][] double_stacks = getRigImageStacks(
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
quadCLT_main, // QuadCLT quadCLT_main,
......@@ -833,33 +833,183 @@ public class TwoQuadCLT {
final int tilesX = quadCLT_main.tp.getTilesX();
double [][] disparity_bimap = measureInfinityRig(
quadCLT_main, //QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, //QuadCLT quadCLT_aux,
// perform full re-measure cycles
double [][] disparity_bimap = null;
for (int num_full_cycle = 0; num_full_cycle < clt_parameters.rig.rig_adjust_full_cycles;num_full_cycle++) {
disparity_bimap = null;
ArrayList<Integer> tile_list = new ArrayList<Integer>();
// measuere and refine
for (int disp_step = 0; disp_step < clt_parameters.rig.rig_num_disp_steps; disp_step++) {
double disparity = 0.0;
if (clt_parameters.rig.rig_num_disp_steps > 1) {
disparity = disp_step * clt_parameters.rig.rig_disp_range/(clt_parameters.rig.rig_num_disp_steps -1);
}
disparity_bimap = measureNewRigDisparity(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
double_stacks, // double [][][][] double_stacks,
null, // ArrayList<Integer> tileList, // or null
disparity_bimap, // double [][] src_bimap, // current state of measurements (or null for new measurement)
disparity, // double disparity,
tile_list, // ArrayList<Integer> tile_list, // or null. If non-null - do not remeasure members of teh list
saturation_main, // boolean [][] saturation_main, // (near) saturated pixels or null
saturation_aux, //boolean [][] saturation_aux, // (near) saturated pixels or null
saturation_aux, // boolean [][] saturation_aux, // (near) saturated pixels or null
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
if (disparity_bimap != null) {
ArrayList<Integer> tileList = selectInfinityTiles(
if (disparity_bimap != null){
if (clt_parameters.show_map && (debugLevel > 2) && clt_parameters.rig.rig_mode_debug){
(new showDoubleFloatArrays()).showArrays(
disparity_bimap,
tilesX,
disparity_bimap[0].length/tilesX,
true,
"DISP_MAP-D"+disparity,
ImageDtt.BIDISPARITY_TITLES);
}
}
if (disparity > 0.0) { // refine non-infinity passes
// first - refine once for the main camera
double [][] prev_bimap = null;
for (int nrefine = 0; nrefine < clt_parameters.rig.num_refine_master; nrefine++) {
double [][] disparity_bimap_new = refineRig(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
double_stacks, // double [][][][] double_stacks,
disparity_bimap, // double [][] src_bimap, // current state of measurements (or null for new measurement)
prev_bimap, // double [][] prev_bimap, // previous state of measurements or null
0, // int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
true, // boolean keep_inf, // keep expected disparity 0.0 if it was so
clt_parameters.rig.refine_min_strength , // double refine_min_strength, // do not refine weaker tiles
clt_parameters.rig.refine_tolerance , // double refine_tolerance, // do not refine if absolute disparity below
null, // tile_list, // ArrayList<Integer> tile_list, // or null
saturation_main, // boolean [][] saturation_main, // (near) saturated pixels or null
saturation_aux, // boolean [][] saturation_aux, // (near) saturated pixels or null
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
prev_bimap = disparity_bimap;
disparity_bimap = disparity_bimap_new;
if (disparity_bimap != null){
if (clt_parameters.show_map && (debugLevel > 2) && clt_parameters.rig.rig_mode_debug){
(new showDoubleFloatArrays()).showArrays(
disparity_bimap,
tilesX,
disparity_bimap[0].length/tilesX,
true,
"DISP_MAP-refine_master-"+nrefine,
ImageDtt.BIDISPARITY_TITLES);
}
}
}
// now refine for the inter-camera correlation
prev_bimap = null;
for (int nrefine = 0; nrefine < clt_parameters.rig.num_refine_inter; nrefine++) {
double [][] disparity_bimap_new = refineRig(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
double_stacks, // double [][][][] double_stacks,
disparity_bimap, // double [][] src_bimap, // current state of measurements (or null for new measurement)
prev_bimap, // double [][] prev_bimap, // previous state of measurements or null
2, // int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
true, // boolean keep_inf, // keep expected disparity 0.0 if it was so
clt_parameters.rig.refine_min_strength , // double refine_min_strength, // do not refine weaker tiles
clt_parameters.rig.refine_tolerance , // double refine_tolerance, // do not refine if absolute disparity below
null, // tile_list, // ArrayList<Integer> tile_list, // or null
saturation_main, // boolean [][] saturation_main, // (near) saturated pixels or null
saturation_aux, // boolean [][] saturation_aux, // (near) saturated pixels or null
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
prev_bimap = disparity_bimap;
disparity_bimap = disparity_bimap_new;
if (disparity_bimap != null){
if (clt_parameters.show_map && (debugLevel > 2) && clt_parameters.rig.rig_mode_debug){
(new showDoubleFloatArrays()).showArrays(
disparity_bimap,
tilesX,
disparity_bimap[0].length/tilesX,
true,
"DISP_MAP-refine_inter-"+nrefine,
ImageDtt.BIDISPARITY_TITLES);
}
}
}
} // if (disparity > 0.0) { // refine non-infinity passes
// rebuild tiles list that match requirements, debug-show results
tile_list = selectRigTiles(
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
true, // boolean select_infinity,
true, // boolean select_noninfinity,
disparity_bimap, // double[][] disparity_bimap,
tilesX, // int tilesX,
clt_parameters.rig.rig_mode_debug); // boolean debug
System.out.println("Selected "+tileList.size()+" tiles for infinity correction");
tilesX); // int tilesX,
if (debugLevel > -1) showListedRigTiles(
"rig_tiles_D"+disparity, // title
tile_list, //ArrayList<Integer> tile_list,
disparity_bimap, // double[][] disparity_bimap,
tilesX); // int tilesX
} // for (int disp_step = 0; disp_step < clt_parameters.rig.rig_num_disp_steps; disp_step++)
// short cycle (remeasure only for teh list). May also break from it if RMS is not improving
for (int num_short_cycle = 0; num_short_cycle < clt_parameters.rig.rig_adjust_short_cycles;num_short_cycle++) {
// refine for the existing list - all listed tiles, no thersholds
disparity_bimap = refineRig(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
double_stacks, // double [][][][] double_stacks,
disparity_bimap, // double [][] src_bimap, // current state of measurements (or null for new measurement)
null, // double [][] prev_bimap, // previous state of measurements or null
2, // int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
true, // boolean keep_inf, // keep expected disparity 0.0 if it was so
0.0, // double refine_min_strength, // do not refine weaker tiles
0.0, // double refine_tolerance, // do not refine if absolute disparity below
tile_list, // ArrayList<Integer> tile_list, // or null
saturation_main, // boolean [][] saturation_main, // (near) saturated pixels or null
saturation_aux, // boolean [][] saturation_aux, // (near) saturated pixels or null
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
// show updated results for the list
if (debugLevel > -1) showListedRigTiles(
"selected_rig_tiles", // title
tile_list, //ArrayList<Integer> tile_list,
disparity_bimap, // double[][] disparity_bimap,
tilesX); // int tilesX
// do actual adjustment step, update rig parameters
} // end of for (int num_short_cycle = 0; num_short_cycle < clt_parameters.rig.rig_adjust_short_cycles;num_short_cycle++) {
} // end of for (int num_full_cycle = 0; num_full_cycle < clt_parameters.rig.rig_adjust_full_cycles;num_full_cycle++) {
if (disparity_bimap != null){
if (clt_parameters.show_map && (debugLevel > 0) && clt_parameters.rig.rig_mode_debug){
(new showDoubleFloatArrays()).showArrays(
disparity_bimap,
tilesX,
disparity_bimap[0].length/tilesX,
true,
"DISP_MAP",
ImageDtt.BIDISPARITY_TITLES);
}
}
// loop here with the same tileList
return true;
}
/*
public double [][] measureInfinityRig(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
......@@ -899,11 +1049,316 @@ public class TwoQuadCLT {
debugLevel); // final int debugLevel)
}
*/
/**
* Refine (re-measure with updated expected disparity) tiles. If refine_min_strength and refine_tolerance are both
* set to 0.0, all (or listed) tiles will be re-measured, use camera extrinsics are changed
* @param quadCLT_main main camera QuadCLT instance (should have tp initialized)
* @param quadCLT_aux auxiliary camera QuadCLT instance (should have tp initialized)
* @param double_stacks image data from both cameras converted to double and conditioned
* @param src_bimap results of the older measurements (now includes expected disparity)
* @param prev_bimap results of the even older measurements to interpolate if there was an overshoot
* @param refine_mode reference camera data: 0 - main camera, 1 - aux camera, 2 - cross-camera
* @param keep_inf do not refine expected disparity for infinity
* @param refine_min_strength do not refine weaker tiles
* @param refine_tolerance do not refine if residial disparity (after FD pre-shift by expected disparity) less than this
* @param tile_list list of selected tiles or null. If null - try to refine all tiles, otherwise - only listed tiles
* @param saturation_main saturated pixels bitmaps for the main camera
* @param saturation_aux saturated pixels bitmaps for the auxiliary camera
* @param clt_parameters various configuration parameters
* @param threadsMax maximal number of threads to use
* @param updateStatus update IJ status bar
* @param debugLevel debug level
* @return results of the new measurements combined with the old results
*/
public double [][] refineRig(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
double [][][][] double_stacks,
double [][] src_bimap, // current state of measurements
double [][] prev_bimap, // previous state of measurements or null
int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
boolean keep_inf, // keep expected disparity 0.0 if it was so
double refine_min_strength, // do not refine weaker tiles
double refine_tolerance, // do not refine if absolute disparity below
ArrayList<Integer> tile_list, // or null
// boolean [] unstable,
boolean [][] saturation_main, // (near) saturated pixels or null
boolean [][] saturation_aux, // (near) saturated pixels or null
EyesisCorrectionParameters.CLTParameters clt_parameters,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel){
int tilesX =quadCLT_main.tp.getTilesX();
int tilesY =quadCLT_main.tp.getTilesY();
int [][] tile_op = new int [tilesY][tilesX];
double [][] disparity_array = new double [tilesY][tilesX];
double disp_scale_main = 1.0/clt_parameters.corr_magic_scale; // Is it needed?
double disp_scale_aux = disp_scale_main * quadCLT_main.geometryCorrection.getDisparityRadius()/quadCLT_aux.geometryCorrection.getDisparityRadius();
double disp_scale_inter = disp_scale_main * quadCLT_main.geometryCorrection.getDisparityRadius()/quadCLT_aux.geometryCorrection.getBaseline();
int tile_op_all = clt_parameters.tile_task_op; //FIXME Use some constant?
int numMeas = 0;
if (tile_list == null) { // refine all
for (int tileY = 0; tileY<tilesY;tileY++) {
for (int tileX = 0; tileX<tilesX;tileX++) {
int nTile = tileY * tilesX + tileX;
if (!Double.isNaN(src_bimap[ImageDtt.BI_TARGET_INDEX][nTile])) {
if (prepRefineTile(
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
tile_op_all, // int tile_op_all,
src_bimap, // double [][] src_bimap, // current state of measurements
prev_bimap, // double [][] prev_bimap, // previous state of measurements or null
tile_op, // int [][] tile_op, // common for both amin and aux
disparity_array, // double [][] disparity_array,
refine_mode, // int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
keep_inf, // boolean keep_inf, // keep expected disparity 0.0 if it was so
refine_min_strength, // double refine_min_strength, // do not refine weaker tiles
refine_tolerance, // double refine_tolerance, // do not refine if absolute disparity below
disp_scale_main, // double disp_scale_main, // 1.0
disp_scale_aux, //double disp_scale_aux, // ~0.58
disp_scale_inter, //double disp_scale_inter, // ~4.86
// scale_step, // double scale_step, // scale for "unstable tiles"
tileX, // int tileX,
tileY, // int tileY,
nTile )) numMeas++; //int nTile
}
}
}
} else {
for (int nTile: tile_list) {
int tileY = nTile / tilesX;
int tileX = nTile % tilesX;
if (!(Double.isNaN(src_bimap[ImageDtt.BI_TARGET_INDEX][nTile]))) {
if (prepRefineTile(
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
tile_op_all, // int tile_op_all,
src_bimap, // double [][] src_bimap, // current state of measurements
prev_bimap, // double [][] prev_bimap, // previous state of measurements or null
tile_op, // int [][] tile_op, // common for both amin and aux
disparity_array, // double [][] disparity_array,
refine_mode, // int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
keep_inf, // boolean keep_inf, // keep expected disparity 0.0 if it was so
refine_min_strength, // double refine_min_strength, // do not refine weaker tiles
refine_tolerance, // double refine_tolerance, // do not refine if absolute disparity below
disp_scale_main, // double disp_scale_main, // 1.0
disp_scale_aux, //double disp_scale_aux, // ~0.58
disp_scale_inter, //double disp_scale_inter, // ~4.86
tileX, // int tileX,
tileY, // int tileY,
nTile )) numMeas++; //int nTile
}
}
}
if (debugLevel >0) {
System.out.println("refineRig() mode="+refine_mode+": Prepared "+numMeas+" to measure");
}
double [][] disparity_bimap = measureRig(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
double_stacks, // double [][][][] double_stacks,
tile_op, // int [][] tile_op, // common for both amin and aux
disparity_array, // double [][] disparity_array,
saturation_main, // boolean [][] saturation_main, // (near) saturated pixels or null
saturation_aux, // boolean [][] saturation_aux, // (near) saturated pixels or null
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
threadsMax, //final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel)
// combine with old results for tiles that were not re-measured
if (tile_list == null) { // refine all
for (int tileY = 0; tileY<tilesY;tileY++) {
for (int tileX = 0; tileX<tilesX;tileX++) {
int nTile = tileY * tilesX + tileX;
if (Double.isNaN(disparity_bimap[ImageDtt.BI_TARGET_INDEX][nTile]) && !Double.isNaN(src_bimap[ImageDtt.BI_TARGET_INDEX][nTile])) {
for (int i = 0; i < disparity_bimap.length; i++) {
disparity_bimap[i][nTile] = src_bimap[i][nTile];
}
}
}
}
} else {
for (int nTile: tile_list) {
if (Double.isNaN(disparity_bimap[ImageDtt.BI_TARGET_INDEX][nTile]) && !Double.isNaN(src_bimap[ImageDtt.BI_TARGET_INDEX][nTile])) {
for (int i = 0; i < disparity_bimap.length; i++) {
disparity_bimap[i][nTile] = src_bimap[i][nTile];
}
}
}
}
return disparity_bimap;
}
/**
* Add measurements with new specified disparity of the main camera
* @param quadCLT_main main camera QuadCLT instance (should have tp initialized)
* @param quadCLT_aux auxiliary camera QuadCLT instance (should have tp initialized)
* @param double_stacks image data from both cameras converted to double and conditioned
* @param src_bimap results of the older measurements (now includes expected disparity) or null (no old results available)
* @param disparity new expected disparity value to try
* @param tile_list list of selected tiles or null. If not null, will not re-measure listed tiles
* @param saturation_main saturated pixels bitmaps for the main camera
* @param saturation_aux saturated pixels bitmaps for the auxiliary camera
* @param clt_parameters various configuration parameters
* @param threadsMax maximal number of threads to use
* @param updateStatus update IJ status bar
* @param debugLevel debug level
* @return results of the new measurements combined with the old results (if available)
*/
public double [][] measureNewRigDisparity(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
double [][][][] double_stacks,
double [][] src_bimap, // current state of measurements (or null for new measurement)
double disparity,
ArrayList<Integer> tile_list, // or null. If non-null - do not remeasure members of teh list
boolean [][] saturation_main, // (near) saturated pixels or null
boolean [][] saturation_aux, // (near) saturated pixels or null
EyesisCorrectionParameters.CLTParameters clt_parameters,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel){
if (debugLevel > 0) {
System.out.println("measureNewRigDisparity(), disparity = "+disparity+", tile_list.size()="+tile_list.size());
}
int tile_op_all = clt_parameters.tile_task_op; //FIXME Use some constant?
int tilesX =quadCLT_main.tp.getTilesX();
int tilesY =quadCLT_main.tp.getTilesY();
int [][] tile_op = new int [tilesY][tilesX];
double [][] disparity_array = new double [tilesY][tilesX];
boolean [] selected = new boolean [tilesX * tilesY];
if (tile_list != null) {
for (int nTile:tile_list) {
selected[nTile] = true;
}
}
for (int tileY = 0; tileY<tilesY;tileY++) {
for (int tileX = 0; tileX<tilesX;tileX++) {
int nTile = tileY * tilesX + tileX;
if ((src_bimap == null) || Double.isNaN(src_bimap[ImageDtt.BI_TARGET_INDEX][nTile]) || !selected[nTile]) {
tile_op[tileY][tileX] = tile_op_all;
disparity_array[tileY][tileX] = disparity;
}
}
}
double [][] disparity_bimap = measureRig(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
double_stacks, // double [][][][] double_stacks,
tile_op, // int [][] tile_op, // common for both amin and aux
disparity_array, // double [][] disparity_array,
saturation_main, // boolean [][] saturation_main, // (near) saturated pixels or null
saturation_aux, // boolean [][] saturation_aux, // (near) saturated pixels or null
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
threadsMax, //final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel)
// combine with old results (if available) for the tiles that were not re-measured
if (src_bimap != null) {
for (int tileY = 0; tileY<tilesY;tileY++) {
for (int tileX = 0; tileX<tilesX;tileX++) {
int nTile = tileY * tilesX + tileX;
boolean use_old = false;
// if (Double.isNaN(disparity_bimap[ImageDtt.BI_TARGET_INDEX][nTile]) && !Double.isNaN(src_bimap[ImageDtt.BI_TARGET_INDEX][nTile])) {
if (Double.isNaN(disparity_bimap[ImageDtt.BI_TARGET_INDEX][nTile])) {
use_old = true;
} else if (!Double.isNaN(src_bimap[ImageDtt.BI_TARGET_INDEX][nTile])) {
double comp_strength_old = src_bimap[ImageDtt.BI_STR_FULL_INDEX][nTile] * src_bimap[ImageDtt.BI_ASTR_FULL_INDEX][nTile];
double comp_strength_new = disparity_bimap[ImageDtt.BI_STR_FULL_INDEX][nTile]* disparity_bimap[ImageDtt.BI_ASTR_FULL_INDEX][nTile];
if (comp_strength_old > comp_strength_new) {
use_old = true;
} else if (!(comp_strength_old < comp_strength_new)) { //one or both are NaN
// for now - enough,
if (Double.isNaN (comp_strength_new)) {
use_old = true;
}
}
}
if (use_old) {
for (int i = 0; i < disparity_bimap.length; i++) {
disparity_bimap[i][nTile] = src_bimap[i][nTile];
}
}
}
}
}
return disparity_bimap;
}
private boolean prepRefineTile(
EyesisCorrectionParameters.CLTParameters clt_parameters,
int tile_op_all,
double [][] src_bimap, // current state of measurements
double [][] prev_bimap, // previous state of measurements or null
int [][] tile_op, // common for both amin and aux
double [][] disparity_array,
int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
boolean keep_inf, // keep expected disparity 0.0 if it was so
double refine_min_strength, // do not refine weaker tiles
double refine_tolerance, // do not refine if absolute disparity below
double disp_scale_main, // 1.0
double disp_scale_aux, // ~0.58
double disp_scale_inter, // ~4.86
// double scale_step, // scale for "unstable tiles"
int tileX,
int tileY,
int nTile) {
boolean debug_this = nTile==61924;
// check if it was measured (skip NAN)
if (Double.isNaN(src_bimap[ImageDtt.BI_TARGET_INDEX][nTile])) return false;
// check if it is infinity and change is prohibited
if (keep_inf && (src_bimap[ImageDtt.BI_TARGET_INDEX][nTile] == 0.0)) return false;
double diff_disp, strength, disp_scale, diff_prev;
switch (refine_mode) {
case 0:
diff_disp = src_bimap[ImageDtt.BI_DISP_FULL_INDEX][nTile];
diff_prev= (prev_bimap == null)? Double.NaN:prev_bimap[ImageDtt.BI_DISP_FULL_INDEX][nTile];
strength = src_bimap[ImageDtt.BI_STR_FULL_INDEX][nTile];
disp_scale = disp_scale_main;
break;
case 1:
diff_disp = src_bimap[ImageDtt.BI_ADISP_FULL_INDEX][nTile];
diff_prev= (prev_bimap == null)? Double.NaN:prev_bimap[ImageDtt.BI_ADISP_FULL_INDEX][nTile];
strength = src_bimap[ImageDtt.BI_ASTR_FULL_INDEX][nTile];
disp_scale = disp_scale_aux;
break;
default:
diff_disp = src_bimap[ImageDtt.BI_DISP_CROSS_INDEX][nTile];
diff_prev= (prev_bimap == null)? Double.NaN:prev_bimap[ImageDtt.BI_DISP_CROSS_INDEX][nTile];
strength = src_bimap[ImageDtt.BI_STR_CROSS_INDEX][nTile];
disp_scale = disp_scale_inter;
}
// strong enough?
if (strength < refine_min_strength) return false;
// residual disparity large enough to bother
if (Math.abs(diff_disp) < refine_tolerance) return false;
tile_op[tileY][tileX] = tile_op_all;
// or use extrapolate too?
if (debug_this) {
System.out.println("disp_scale="+disp_scale);
if (prev_bimap != null) {
System.out.print("prepRefineTile(): prev_bimap[ImageDtt.BI_TARGET_INDEX][nTile] = "+prev_bimap[ImageDtt.BI_TARGET_INDEX][nTile]+
", src_bimap[ImageDtt.BI_TARGET_INDEX][nTile]="+src_bimap[ImageDtt.BI_TARGET_INDEX][nTile]+", diff_prev="+diff_prev+", diff_disp="+diff_disp);
} else {
System.out.print("prepRefineTile(): src_bimap[ImageDtt.BI_TARGET_INDEX][nTile]="+src_bimap[ImageDtt.BI_TARGET_INDEX][nTile]+", diff_prev="+diff_prev+", diff_disp="+diff_disp);
}
}
if (Double.isNaN(diff_prev) || (diff_prev * diff_disp > 0)) {
disparity_array[tileY][tileX] = src_bimap[ImageDtt.BI_TARGET_INDEX][nTile] + diff_disp*disp_scale;
if (debug_this) System.out.println(" >> 1 => disparity_array["+tileY+"]["+tileX+"]="+disparity_array[tileY][tileX]);
} else { // interpolate
disparity_array[tileY][tileX] = (src_bimap[ImageDtt.BI_TARGET_INDEX][nTile]*diff_prev - prev_bimap[ImageDtt.BI_TARGET_INDEX][nTile]*diff_disp)/(diff_prev-diff_disp);
if (debug_this) System.out.println(" >> 2 => disparity_array["+tileY+"]["+tileX+"]="+disparity_array[tileY][tileX]);
}
return true;
}
public double [][] measureRig(
private double [][] measureRig(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
double [][][][] double_stacks,
......@@ -923,7 +1378,7 @@ public class TwoQuadCLT {
image_dtt.clt_bi_quad (
clt_parameters, // final EyesisCorrectionParameters.CLTParameters clt_parameters,
tile_op, // final int [][] tile_op_main, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
tile_op, // final int [][] tile_op_aux, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
// tile_op, // final int [][] tile_op_aux, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
disparity_array, // final double [][] disparity_array, // [tilesY][tilesX] - individual per-tile expected disparity
double_stacks[0], // final double [][][] image_data_main, // first index - number of image in a quad
double_stacks[1], // final double [][][] image_data_aux, // first index - number of image in a quad
......@@ -944,24 +1399,24 @@ public class TwoQuadCLT {
clt_parameters.corr_magic_scale, // final double corr_magic_scale, // still not understood coefficient that reduces reported disparity value. Seems to be around 0.85
false, // true, // final boolean keep_clt_data,
threadsMax, // final int threadsMax, // maximal number of threads to launch
debugLevel); // final int globalDebugLevel);
debugLevel-2); // final int globalDebugLevel);
return disparity_bimap;
}
ArrayList<Integer> selectInfinityTiles(
ArrayList<Integer> selectRigTiles(
EyesisCorrectionParameters.CLTParameters clt_parameters,
boolean select_infinity,
boolean select_noninfinity,
double[][] disparity_bimap,
int tilesX,
boolean debug
){
int tilesX)
{
ArrayList<Integer> tilesList = new ArrayList<Integer>();
int numTiles = disparity_bimap[ImageDtt.BI_STR_FULL_INDEX].length;
if (select_infinity) {
for (int nTile = 0; nTile < numTiles; nTile++) {
if ((disparity_bimap[ImageDtt.BI_STR_FULL_INDEX][nTile] >= clt_parameters.rig.inf_min_strength_main)&&
if ( (disparity_bimap[ImageDtt.BI_TARGET_INDEX][nTile] == 0.0 ) && // expected disparity was 0.0 (infinity)
(disparity_bimap[ImageDtt.BI_STR_FULL_INDEX][nTile] >= clt_parameters.rig.inf_min_strength_main)&&
(disparity_bimap[ImageDtt.BI_ASTR_FULL_INDEX][nTile] >= clt_parameters.rig.inf_min_strength_aux)&&
(disparity_bimap[ImageDtt.BI_STR_CROSS_INDEX][nTile] >= clt_parameters.rig.inf_min_strength_rig)&&
(Math.abs(disparity_bimap[ImageDtt.BI_DISP_FULL_INDEX][nTile]) <= clt_parameters.rig.inf_max_disp_main)&&
......@@ -970,34 +1425,55 @@ public class TwoQuadCLT {
tilesList.add(nTile);
}
}
if (debug) {
String [] titles = {"disparity", "dx","dy","strength"};
double [][] dbg_inf = new double [4][numTiles];
}
if (select_noninfinity) {
for (int nTile = 0; nTile < numTiles; nTile++) {
if ( (disparity_bimap[ImageDtt.BI_TARGET_INDEX][nTile] > 0.0 ) && // expected disparity was > 0.0 (not infinity)
(disparity_bimap[ImageDtt.BI_STR_FULL_INDEX][nTile] >= clt_parameters.rig.inf_min_strength_main)&&
(disparity_bimap[ImageDtt.BI_ASTR_FULL_INDEX][nTile] >= clt_parameters.rig.inf_min_strength_aux)&&
(disparity_bimap[ImageDtt.BI_STR_CROSS_INDEX][nTile] >= clt_parameters.rig.inf_min_strength_rig)&&
(Math.abs(disparity_bimap[ImageDtt.BI_DISP_FULL_INDEX][nTile]) <= clt_parameters.rig.near_max_disp_main)&&
(Math.abs(disparity_bimap[ImageDtt.BI_ADISP_FULL_INDEX][nTile]) <= clt_parameters.rig.near_max_disp_aux)&&
(Math.abs(disparity_bimap[ImageDtt.BI_DISP_CROSS_INDEX][nTile]) <= clt_parameters.rig.near_max_disp_rig)) {
tilesList.add(nTile);
}
}
}
return tilesList;
}
public void showListedRigTiles(
String title,
ArrayList<Integer> tile_list,
double[][] disparity_bimap,
int tilesX ){
int numTiles = disparity_bimap[ImageDtt.BI_STR_FULL_INDEX].length;
String [] titles = {"disparity", "dx","dy","strength","target"};
double [][] dbg_inf = new double [5][numTiles];
for (int nTile = 0; nTile < numTiles; nTile++){
dbg_inf[0][nTile] = Double.NaN;
dbg_inf[1][nTile] = Double.NaN;
dbg_inf[2][nTile] = Double.NaN;
dbg_inf[3][nTile] = Double.NaN; // 0.0;
dbg_inf[4][nTile] = Double.NaN; // 0.0;
}
for (int nTile:tilesList) {
for (int nTile:tile_list) {
dbg_inf[0][nTile] = disparity_bimap[ImageDtt.BI_DISP_CROSS_INDEX][nTile];
dbg_inf[1][nTile] = disparity_bimap[ImageDtt.BI_DISP_CROSS_DX_INDEX][nTile];
dbg_inf[2][nTile] = disparity_bimap[ImageDtt.BI_DISP_CROSS_DY_INDEX][nTile];
dbg_inf[3][nTile] = disparity_bimap[ImageDtt.BI_STR_CROSS_INDEX][nTile];
dbg_inf[4][nTile] = disparity_bimap[ImageDtt.BI_TARGET_INDEX][nTile];
}
(new showDoubleFloatArrays()).showArrays(
dbg_inf,
tilesX,
numTiles/tilesX,
true,
"Infinity_selected_data",
title,
titles );
}
//new showDoubleFloatArrays()
return tilesList;
}
......
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