Commit e57130aa authored by Andrey Filippov's avatar Andrey Filippov

improving multi-tile averaging

parent 17f7b343
......@@ -938,6 +938,116 @@ public class GpuQuad{ // quad camera description
return task_list.toArray(new TpTask[task_list.size()]);
}
/**
* Set a single task
* @param num_cams number of sensors in a system
* @param task_code task code (need to be re-defined, currently is mostly zero/non-zero
* @param tileX integer tile X coordinate
* @param tileY integer tile X coordinate
* @param target_disparity target disparity (should include disparity_corr if used)
* @param corr_rots Array of rotational matrices, may be null, but it is more efficient to calculate it once
* @param transform_size CLT transform size (==8)
* @param geometryCorrection instance of GeometryCorrection class fro the scene
* @return TpTask instance, compatible with both CPU and GPU processing
*/
public static TpTask setTask(
int num_cams,
int transform_size,
int task_code,
int tileX,
int tileY,
double target_disparity, // include disparity_corr
// use geometryCorrection.getCorrVector().getRotMatrices(); once per whole image set
Matrix [] corr_rots, // if null, will be calculated
GeometryCorrection geometryCorrection)
{
if (corr_rots == null) {
corr_rots = geometryCorrection.getCorrVector().getRotMatrices(); // get array of per-sensor rotation matrices
}
TpTask tp_task = new TpTask(num_cams, tileX, tileY);
tp_task.task = task_code;
// double disparity = pXpYD[nTile][2] + disparity_corr;
tp_task.target_disparity = (float) target_disparity; // will it be used?
double centerX = tileX * transform_size + transform_size/2;
double centerY = tileY * transform_size + transform_size/2;
double [][] disp_dist = new double[num_cams][]; // used to correct 3D correlations (not yet used here)
double [][] centersXY_main = geometryCorrection.getPortsCoordinatesAndDerivatives(
geometryCorrection, // GeometryCorrection gc_main,
false, // boolean use_rig_offsets,
corr_rots, // Matrix [] rots,
null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv,
disp_dist, // used to correct 3D correlations
centerX,
centerY,
tp_task.target_disparity); // + disparity_corr);
tp_task.setDispDist(disp_dist);
tp_task.xy = new float [centersXY_main.length][2];
for (int i = 0; i < centersXY_main.length; i++) {
tp_task.xy[i][0] = (float) centersXY_main[i][0];
tp_task.xy[i][1] = (float) centersXY_main[i][1];
}
return tp_task;
}
public static TpTask[] setTasks(
final int num_cams,
final int transform_size,
final double [][] disparity_array, // [tilesY][tilesX] - individual per-tile expected disparity
final double disparity_corr,
final int [][] tile_op, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
final GeometryCorrection geometryCorrection,
final int threadsMax) // maximal number of threads to launch
{
final int tilesY = disparity_array.length;
int tx = -1;
for (int i = 0; i < disparity_array.length; i++) if (disparity_array[i] != null) {
tx = disparity_array[i].length;
break;
}
if (tx < 0) {
return new TpTask[0];
}
final int tilesX = tx;
final Matrix [] corr_rots = geometryCorrection.getCorrVector().getRotMatrices(); // get array of per-sensor rotation matrices
final TpTask[] tp_tasks_xy = new TpTask[tilesY * tilesX];
final AtomicInteger ai = new AtomicInteger(0);
final AtomicInteger anum_tiles = new AtomicInteger(0);
final Thread[] threads = ImageDtt.newThreadArray(threadsMax);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
for (int iTile = ai.getAndIncrement(); iTile < tp_tasks_xy.length; iTile = ai.getAndIncrement()) {
int tileY = iTile /tilesX;
int tileX = iTile % tilesX;
if ((tile_op[tileY][tileX] != 0) && !Double.isNaN(disparity_array[tileY][tileX])) {
tp_tasks_xy[iTile] = setTask(
num_cams, // int num_cams,
transform_size, // int transform_size,
tile_op[tileY][tileX], // int task_code,
tileX, // int tileX,
tileY, // int tileY,
disparity_array[tileY][tileX] + disparity_corr, // double target_disparity, // include disparity_corr
corr_rots, // Matrix [] corr_rots, // if null, will be calculated
geometryCorrection); // GeometryCorrection geometryCorrection)
anum_tiles.getAndIncrement();
}
}
}
};
}
ImageDtt.startAndJoin(threads);
final TpTask[] tp_tasks = new TpTask[anum_tiles.get()];
int indx = 0;
for (int i = 0; i < tp_tasks_xy.length; i++) if (tp_tasks_xy[i] != null) {
tp_tasks[indx++] = tp_tasks_xy[i];
}
return tp_tasks;
}
/**
......@@ -2330,11 +2440,11 @@ public class GpuQuad{ // quad camera description
// for (int indx = ai.getAndIncrement(); indx < tp_tasks.length; indx = ai.getAndIncrement()) {
// int nTile = tile_indices[indx];
for (int nTile = ai.getAndIncrement(); nTile < tiles; nTile = ai.getAndIncrement()) if (pXpYD[nTile] != null) {
TpTask tp_task = new TpTask();
int tileY = nTile / tilesX;
int tileX = nTile % tilesX;
tp_task.ty = tileY;
tp_task.tx = tileX;
TpTask tp_task = new TpTask(num_cams, tileX, tileY);
// tp_task.ty = tileY;
// tp_task.tx = tileX;
tp_task.task = task_code;
double disparity = pXpYD[nTile][2] + disparity_corr;
tp_task.target_disparity = (float) disparity; // will it be used?
......@@ -2381,6 +2491,11 @@ public class GpuQuad{ // quad camera description
public void setLpfRbg(
float [][] lpf_rbg, // 4 64-el. arrays: r,b,g,m
boolean debug)
......
......@@ -9,7 +9,16 @@ public class TpTask {
public float[][] xy = null;
public float[][] xy_aux = null;
public float [][] disp_dist = null;
public TpTask() {}
// public float weight;
public TpTask(
int num_sensors,
int tileX,
int tileY) {
this.num_sensors = num_sensors;
this.ty = tileY;
this.tx = tileX;
}
public TpTask(int num_sensors, int tx, int ty, float target_disparity, int task ) {
this.tx = tx;
......
......@@ -416,6 +416,9 @@ public class CLTPass3d{
double [] disparity,
double [] strength)
{
if ((disparity == null) || (strength == null)) {
return;
}
// depends on direction, but that is OK - just converge faster when smoothing
int tilesX = tileProcessor.getTilesX();
int tilesY = tileProcessor.getTilesY();
......@@ -1000,7 +1003,9 @@ public class CLTPass3d{
{
final double [][] diffs = getDiffs();
if (diffs == null) return null;
for (int i = 0; i < diffs.length; i++) {
if (diffs[i] == null) return null;
}
final int tilesX = tileProcessor.getTilesX();
final int tilesY = tileProcessor.getTilesY();
final int num_tiles = tilesX * tilesY;
......
......@@ -3681,7 +3681,7 @@ public class Correlation2d {
boolean adjust_ly, // adjust Lazy Eye
double [][] corr_wnd, // correlation window to save on re-calculation of the window
double [] corr_wnd_inv_limited, // correlation window, limited not to be smaller than threshold - used for finding max/convex areas (or null)
double [][] corrs,
double [][] corrs, // may have more elements than pair_mask (corrs may have combo as last elements)
double [][] disp_dist, // per camera disparity matrix as a 1d (linescan order)
double [][] rXY, // non-distorted X,Y offset per nominal pixel of disparity
boolean [] pair_mask, // which pairs to process
......@@ -3732,7 +3732,7 @@ public class Correlation2d {
// for (int npair = 0; npair < corrs.length; npair++) if ((corrs[npair] != null) && (((pair_mask >> npair) & 1) !=0)){
double [][] filtWeight = new double [corrs.length][];
for (int npair = 0; npair < corrs.length; npair++) if ((corrs[npair] != null) && (pair_mask[npair])){
for (int npair = 0; npair < pair_mask.length; npair++) if ((corrs[npair] != null) && (pair_mask[npair])){
// double[] corr = corrs[npair].clone();
double [] corr_blur = corrs[npair].clone();
......
......@@ -5465,6 +5465,7 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad
final float [][][][] fcorr_td_acc = new float [tilesY][tilesX][][];
final int [][][] num_acc = new int [tilesY][tilesX][num_pairs];
double fat_zero_single = clt_parameters.getGpuFatZero(ref_scene.isMonochrome()); // for single scene
// TODO: make per-tile variable
double scaled_fat_zero = fat_zero_single / (scenes.length);
boolean show_accumulated_correlations =debug_level > -5;
boolean show_reference_correlations =debug_level > -5;
......
......@@ -8311,7 +8311,12 @@ if (debugLevel > -100) return true; // temporarily !
threadsMax, // int threadsMax, // maximal number of threads to launch
updateStatus, // boolean updateStatus,
debugLevel); // int debugLevel)
/// quadCLTs[i].showDSIMain();
if (debugLevel > -10) {
quadCLTs[i].showDSIMain();
quadCLTs[i].testAltCorr (
clt_parameters, // CLTParameters clt_parameters,
this.dsi); // double [][] dsi);
}
}
......@@ -8341,9 +8346,9 @@ if (debugLevel > -100) return true; // temporarily !
System.out.println("End of test");
}
}
public void interPairsLMA(
QuadCLT quadCLT_main, // tiles should be set
......
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