Commit 41b89aee authored by Andrey Filippov's avatar Andrey Filippov

Working on pole detection

parent 3967e7b5
......@@ -151,6 +151,9 @@ public class BiQuadParameters {
public double pf_new_diff = 0.5; // Minimal disparity (in master camera pixels) difference between the new suggested and the already tried/measured one
public int pf_min_new = 5; // Minimal number of he new tiles during rig refine for plane filter
public double lonefg_rstrength = 0.4; // Minimal relative strength of the lone FG tiles
public double lonefg_disp_incr = 1.0; // Maximal disparity of the lone FG tile over maximum of its neighbors
public boolean ltavg_en = true; // apply low texture correlation averaging
public int ltavg_radius = 1; // low texture averaging radius
public boolean ltavg_dens_strong = true; // density calculation - consider only strong tiles
......@@ -470,7 +473,14 @@ public class BiQuadParameters {
gd.addNumericField("Minimal refined tiles during plane filter", this.pf_min_new, 0,3,"",
"Repeat refine antill less tiles are updated");
gd.addTab("LT Avg","Low texture correlatinaveraging");
gd.addMessage("Remove lone FG tiles, that have disparity exceeding maximal neighbor by a margin");
gd.addNumericField("Minimal relative strength of the lone FG tiles", this.lonefg_rstrength, 4,6,"",
"Tile will be removed if it is closer than closest neighbor and is weaker than that neighbor or this value");
gd.addNumericField("Maximal disparity of the lone FG tile over maximum of its neighbors", this.lonefg_disp_incr, 4,6,"pix",
"Tile will be removed if it has disparity higher by this margin that highest neighbor and is weak enough");
gd.addTab("LT Avg","Low texture correlation averaging");
gd.addCheckbox ("Apply low texture correlation averaging", this.ltavg_en,
"Improve low textures by averaging 2-d correlation results");
......@@ -731,6 +741,9 @@ public class BiQuadParameters {
this.pf_new_diff= gd.getNextNumber();
this.pf_min_new= (int) gd.getNextNumber();
this.lonefg_rstrength= gd.getNextNumber();
this.lonefg_disp_incr= gd.getNextNumber();
this.ltavg_en= gd.getNextBoolean();
this.ltavg_radius= (int) gd.getNextNumber();
this.ltavg_dens_strong= gd.getNextBoolean();
......@@ -918,6 +931,8 @@ public class BiQuadParameters {
properties.setProperty(prefix+"pf_new_diff", this.pf_new_diff+"");
properties.setProperty(prefix+"pf_min_new", this.pf_min_new+"");
properties.setProperty(prefix+"lonefg_rstrength", this.lonefg_rstrength+"");
properties.setProperty(prefix+"lonefg_disp_incr", this.lonefg_disp_incr+"");
properties.setProperty(prefix+"ltavg_en", this.ltavg_en+"");
properties.setProperty(prefix+"ltavg_radius", this.ltavg_radius+"");
......@@ -1107,7 +1122,8 @@ public class BiQuadParameters {
if (properties.getProperty(prefix+"pf_new_diff")!=null) this.pf_new_diff=Double.parseDouble(properties.getProperty(prefix+"pf_new_diff"));
if (properties.getProperty(prefix+"pf_min_new")!=null) this.pf_min_new=Integer.parseInt(properties.getProperty(prefix+"pf_min_new"));
if (properties.getProperty(prefix+"lonefg_rstrength")!=null) this.lonefg_rstrength=Double.parseDouble(properties.getProperty(prefix+"lonefg_rstrength"));
if (properties.getProperty(prefix+"lonefg_disp_incr")!=null) this.lonefg_disp_incr=Double.parseDouble(properties.getProperty(prefix+"lonefg_disp_incr"));
if (properties.getProperty(prefix+"ltavg_en")!=null) this.ltavg_en=Boolean.parseBoolean(properties.getProperty(prefix+"ltavg_en"));
if (properties.getProperty(prefix+"ltavg_radius")!=null) this.ltavg_radius=Integer.parseInt(properties.getProperty(prefix+"ltavg_radius"));
......@@ -1298,6 +1314,9 @@ public class BiQuadParameters {
bqp.pf_new_diff= this.pf_new_diff;
bqp.pf_min_new= this.pf_min_new;
bqp.lonefg_rstrength= this.lonefg_rstrength;
bqp.lonefg_disp_incr= this.lonefg_disp_incr;
bqp.ltavg_en= this.ltavg_en;
bqp.ltavg_radius= this.ltavg_radius;
bqp.ltavg_dens_strong= this.ltavg_dens_strong;
......
/**
** BiCamScan - calss to represent bultiple bi-quad camera measurements
** BiCamScan - class to represent multiple bi-quad camera measurements
**
** Copyright (C) 2018 Elphel, Inc.
**
......@@ -36,7 +36,7 @@ public class BiScan {
boolean [] strong_trusted; // sufficient strength without neighbors
boolean [] trusted;
boolean [] cond_trusted;
boolean [] disabled_measurement; // should disable source also
boolean [] disabled_measurement; // should disable source, not this!
int [] src_index; // index of the source scan which measured data is used here (applies to disparity_measured, strength_measured, disabled_measurement
int list_index = -1;
int scan_type = -1;
......@@ -100,7 +100,7 @@ public class BiScan {
// disabled[nTile] = true;
// if ((src_index[nTile] >= 0) && (src_index[nTile] != list_index)) {
if (src_index[nTile] >= 0) {
biCamDSI.getBiScan(src_index[nTile]).disabled_measurement[nTile] = false; // may be source tile or this tile
biCamDSI.getBiScan(src_index[nTile]).disabled_measurement[nTile] = true; // false; // may be source tile or this tile
}
}
/**
......@@ -1267,6 +1267,71 @@ public class BiScan {
return numTrustedAll;
}
/**
* Remove stray tiles that are closer than closest neighbor and weaker than it or
* trusted_strength * min_rstrength
* @param trusted_strength absolute raw strength to trust
* @param min_rstrength minimal strength to allow lone FG, relative to trusted_strength
* @param max_disp_inc maximal disparity difference between this tile and the nearest neighbor
* @param dbg_x
* @param dbg_y
* @param debugLevel
* @return number of disabled tiles
*/
int trimWeakLoneFG(
final double trusted_strength, // trusted correlation strength
final double min_rstrength, // strength floor - relative to trusted
final double max_disp_inc,
final int dbg_x,
final int dbg_y,
final int debugLevel
) {
final AtomicInteger ai_trimmed = new AtomicInteger(0);
final double min_strength = trusted_strength * min_rstrength;
final TileNeibs tnImage = biCamDSI.tnImage;
final int num_tiles = tnImage.sizeX * tnImage.sizeY;
final Thread[] threads = ImageDtt.newThreadArray(biCamDSI.threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
final double [][] ds = getDisparityStrength( // already has disabled zeroed
false, // final boolean only_strong,
false, // final boolean only_trusted,
true) ; // final boolean only_enabled);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
for (int nTile = ai.getAndIncrement(); nTile < num_tiles; nTile = ai.getAndIncrement()) if (!Double.isNaN(ds[0][nTile])){
double max_disp = 0;
double max_disp_w = 0;
double d_lim = ds[0][nTile] - max_disp_inc;
double w = ds[1][nTile];
for (int dir = 0; dir < 8; dir++) {
int nTile1 = tnImage.getNeibIndex(nTile, dir);
if ((nTile1 >=0) && (ds[0][nTile1] > max_disp)){
max_disp = ds[0][nTile1];
max_disp_w = ds[1][nTile1];
}
if (max_disp > d_lim) {
break;
}
}
if ((max_disp <= d_lim) && ((w < max_disp_w) || (w < min_strength))) {
disableTile(nTile);
ai_trimmed.getAndIncrement();
if (debugLevel > -4) {
System.out.println("trimWeakLoneFG: removing tile "+nTile+" ("+(nTile%tnImage.sizeX)+":"+(nTile/tnImage.sizeX));
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
return ai_trimmed.get();
}
// FG edge should be strong
// Trimming(disabling) weak (trusted but not strong_trusted) tiles if on any one side:
// a) there are no same plane or closer tiles
......
......@@ -4254,10 +4254,14 @@ private Panel panel1,
/// ============================================
} else if (label.equals("CLT 3D") || label.equals("CLT Extrinsics") || label.equals("CLT Poly corr")) {
boolean adjust_extrinsics = label.equals("CLT Extrinsics") || label.equals("CLT Poly corr");
boolean adjust_poly = label.equals("CLT Poly corr");
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
clt3d(adjust_extrinsics, adjust_poly);
/*
if (QUAD_CLT == null){
QUAD_CLT = new QuadCLT (
QuadCLT.PREFIX,
......@@ -4327,6 +4331,7 @@ private Panel panel1,
true,
PROPERTIES);
}
*/
return;
} else if (label.equals("AUX Extrinsics") || label.equals("AUX Poly corr")) {
boolean adjust_extrinsics = label.equals("AUX Extrinsics") || label.equals("AUX Poly corr");
......@@ -5125,11 +5130,11 @@ private Panel panel1,
if (configPath.equals("ABORT")) return false;
if (DEBUG_LEVEL > -2){
System.out.println("++++++++++++++ Enhancing single-camera DSI by the dual-camera rig using planes ++++++++++++++");
System.out.println("++++++++++++++ Generating GT data for street poles ++++++++++++++");
}
TWO_QUAD_CLT.processPoles( // actually there is no sense to process multiple image sets. Combine with other processing?
// QUAD_CLT, // QuadCLT quadCLT_main,
// QUAD_CLT_AUX, // QuadCLT quadCLT_aux,
QUAD_CLT, // QuadCLT quadCLT_main,
QUAD_CLT_AUX, // QuadCLT quadCLT_aux,
TWO_QUAD_CLT.biCamDSI_persistent, // BiCamDSI biCamDSI,
CLT_PARAMETERS, // EyesisCorrectionParameters.DCTParameters dct_parameters,
THREADS_MAX, //final int threadsMax, // maximal number of threads to launch
......@@ -5157,13 +5162,97 @@ private Panel panel1,
QUAD_CLT.resetGroundTruthByRig();
return true;
}
// boolean adjust_extrinsics = label.equals("CLT Extrinsics") || label.equals("CLT Poly corr");
// boolean adjust_poly = label.equals("CLT Poly corr");
public boolean clt3d(
boolean adjust_extrinsics,
boolean adjust_poly
) {
if (QUAD_CLT == null){
QUAD_CLT = new QuadCLT (
QuadCLT.PREFIX,
PROPERTIES,
EYESIS_CORRECTIONS,
CORRECTION_PARAMETERS);
if (DEBUG_LEVEL > 0){
System.out.println("Created new QuadCLT instance, will need to read CLT kernels");
}
}
String configPath=getSaveCongigPath();
if (configPath.equals("ABORT")) return false;
EYESIS_CORRECTIONS.initSensorFiles(DEBUG_LEVEL);
int numChannels=EYESIS_CORRECTIONS.getNumChannels();
CHANNEL_GAINS_PARAMETERS.modifyNumChannels(numChannels);
if (!QUAD_CLT.CLTKernelsAvailable()){
if (DEBUG_LEVEL > 0){
System.out.println("Reading CLT kernels");
}
QUAD_CLT.readCLTKernels(
CLT_PARAMETERS,
THREADS_MAX,
UPDATE_STATUS, // update status info
DEBUG_LEVEL);
if (DEBUG_LEVEL > 1){
QUAD_CLT.showCLTKernels(
THREADS_MAX,
UPDATE_STATUS, // update status info
DEBUG_LEVEL);
}
}
if (!QUAD_CLT.geometryCorrectionAvailable()){
if (DEBUG_LEVEL > 0){
System.out.println("Calculating geometryCorrection");
}
if (!QUAD_CLT.initGeometryCorrection(DEBUG_LEVEL+2)){
return false;
}
}
QUAD_CLT.processCLTQuads3d(
adjust_extrinsics, // boolean adjust_extrinsics,
adjust_poly, // boolean adjust_poly,
CLT_PARAMETERS, // EyesisCorrectionParameters.DCTParameters dct_parameters,
DEBAYER_PARAMETERS, //EyesisCorrectionParameters.DebayerParameters debayerParameters,
// NONLIN_PARAMETERS, //EyesisCorrectionParameters.NonlinParameters nonlinParameters,
COLOR_PROC_PARAMETERS, //EyesisCorrectionParameters.ColorProcParameters colorProcParameters,
CHANNEL_GAINS_PARAMETERS, //CorrectionColorProc.ColorGainsParameters channelGainParameters,
RGB_PARAMETERS, //EyesisCorrectionParameters.RGBParameters rgbParameters,
EQUIRECTANGULAR_PARAMETERS, // EyesisCorrectionParameters.EquirectangularParameters equirectangularParameters,
// CONVOLVE_FFT_SIZE, //int convolveFFTSize, // 128 - fft size, kernel size should be size/2
THREADS_MAX, //final int threadsMax, // maximal number of threads to launch
UPDATE_STATUS, //final boolean updateStatus,
DEBUG_LEVEL); //final int debugLevel);
if (configPath!=null) {
saveTimestampedProperties( // save config again
configPath, // full path or null
null, // use as default directory if path==null
true,
PROPERTIES);
}
return true;
}
public boolean enhanceByRig( boolean use_planes) {
long startTime=System.nanoTime();
if ((QUAD_CLT == null) || (QUAD_CLT.tp == null) || (QUAD_CLT.tp.clt_3d_passes == null)) {
String msg = "DSI data is not available. Please run \"CLT 3D\" first";
IJ.showMessage("Error",msg);
System.out.println(msg);
return false;
boolean OK = clt3d(
false, // boolean adjust_extrinsics,
false); // boolean adjust_poly);
if (! OK) {
String msg = "DSI data is not available and \"CLT 3D\" failed";
IJ.showMessage("Error",msg);
System.out.println(msg);
return false;
}
}
if (!prepareRigImages()) return false;
String configPath=getSaveCongigPath();
......
This diff is collapsed.
......@@ -25,6 +25,20 @@ import java.util.Arrays;
*/
public class TileNeibs{
final static int DIR_N = 0; // UP
final static int DIR_NE = 1;
final static int DIR_E = 2; // Right
final static int DIR_SE = 3;
final static int DIR_S = 4; // Down
final static int DIR_SW = 5;
final static int DIR_W = 6; // Left
final static int DIR_NW = 7;
final static int DIR_CENTER = -1;
final static int DIR_UP = 0; // UP
final static int DIR_LEFT = 2; // Right
final static int DIR_DOWN = 4; // Down
final static int DIR_RIGHT = 6; // Left
int sizeX;
int sizeY;
public int dirs = 8;
......
This diff is collapsed.
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