Commit 90aa5914 authored by Andrey Filippov's avatar Andrey Filippov

tweaking confidence, LMA,

parent 681a226e
...@@ -2603,7 +2603,8 @@ public class Corr2dLMA { ...@@ -2603,7 +2603,8 @@ public class Corr2dLMA {
double lma_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point) double lma_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
double lma_max_area, // maximal half-area (if > 0.0) double lma_max_area, // maximal half-area (if > 0.0)
double lma_str_scale, // convert lma-generated strength to match previous ones - scale double lma_str_scale, // convert lma-generated strength to match previous ones - scale
double lma_str_offset // convert lma-generated strength to match previous ones - add to result double lma_str_offset, // convert lma-generated strength to match previous ones - add to result
double lma_ac_offset // add to a,c coefficients for near-lines where A,C could become negative because of window
){ ){
return lmaDisparityStrengths( return lmaDisparityStrengths(
lmas_min_amp, // double lmas_min_amp_fg, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude lmas_min_amp, // double lmas_min_amp_fg, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
...@@ -2615,7 +2616,8 @@ public class Corr2dLMA { ...@@ -2615,7 +2616,8 @@ public class Corr2dLMA {
lma_max_area, // maximal half-area (if > 0.0) lma_max_area, // maximal half-area (if > 0.0)
lma_str_scale, // convert lma-generated strength to match previous ones - scale lma_str_scale, // convert lma-generated strength to match previous ones - scale
lma_str_offset, // convert lma-generated strength to match previous ones - add to result lma_str_offset, // convert lma-generated strength to match previous ones - add to result
false // boolean dbg_mode false, // boolean dbg_mode
lma_ac_offset // add to a,c coefficients for near-lines where A,C could become negative because of window
)[0]; )[0];
} }
...@@ -2625,19 +2627,22 @@ public class Corr2dLMA { ...@@ -2625,19 +2627,22 @@ public class Corr2dLMA {
double lmas_min_amp_bg, // Same for bg correlation max (only used for multi-max) double lmas_min_amp_bg, // Same for bg correlation max (only used for multi-max)
double lma_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3) double lma_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
double lma_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS) double lma_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
double lma_min_max_ac, // minimal of A and C coefficients maximum (measures sharpest point/line) double lma_min_max_ac, // maximal of A and C coefficients minimum (measures sharpest point/line)
double lma_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point) double lma_min_min_ac, // minimal of A and C coefficients minimum
double lma_max_area, // maximal half-area (if > 0.0) // 20 double lma_max_area, // maximal half-area (if > 0.0) // 20
double lma_str_scale, // convert lma-generated strength to match previous ones - scale double lma_str_scale, // convert lma-generated strength to match previous ones - scale
double lma_str_offset, // convert lma-generated strength to match previous ones - add to result double lma_str_offset, // convert lma-generated strength to match previous ones - add to result
boolean dbg_mode boolean dbg_mode,
double lma_ac_offset // add to a,c coefficients for near-lines where A,C could become negative because of window
){ ){
double [][][] ds = new double[numMax][numTiles][dbg_mode? 6 : 3]; double [][][] ds = new double[numMax][numTiles][dbg_mode? 13 : 3];
double [] rms = getRmsTile(); double [] rms = getRmsTile();
for (int nmax = 0; nmax < numMax; nmax++) { for (int nmax = 0; nmax < numMax; nmax++) {
double [][] maxmin_amp = getMaxMinAmpTile(nmax); // nmax double [][] maxmin_amp = getMaxMinAmpTile(nmax); // nmax
double [][] abc = getABCTile(nmax); // nmax double [][] abc = getABCTile(nmax); // nmax
for (int tile = 0; tile < numTiles; tile++) { for (int tile = 0; tile < numTiles; tile++) {
abc[tile][0] += lma_ac_offset;
abc[tile][2] += lma_ac_offset;
int offs = (tile * numMax + nmax) * tile_params; int offs = (tile * numMax + nmax) * tile_params;
ds[nmax][tile][0] = Double.NaN; ds[nmax][tile][0] = Double.NaN;
if (Double.isNaN(maxmin_amp[tile][0])) { if (Double.isNaN(maxmin_amp[tile][0])) {
...@@ -2666,7 +2671,7 @@ public class Corr2dLMA { ...@@ -2666,7 +2671,7 @@ public class Corr2dLMA {
if ((lma_max_rel_rms > 0.00) && (rrms > lma_max_rel_rms)) { if ((lma_max_rel_rms > 0.00) && (rrms > lma_max_rel_rms)) {
continue; continue;
} }
if (Math.max(abc[tile][0], abc[tile][2]) < lma_min_max_ac) { if (Math.max(abc[tile][0], abc[tile][2]) < (lma_min_max_ac + lma_ac_offset)) { // so old lma_min_max_ac will stay
continue; continue;
} }
if ((lma_min_min_ac > 0.0) && ((abc[tile][0] < lma_min_min_ac) || (abc[tile][2] < lma_min_min_ac))){ if ((lma_min_min_ac > 0.0) && ((abc[tile][0] < lma_min_min_ac) || (abc[tile][2] < lma_min_min_ac))){
...@@ -2691,14 +2696,22 @@ public class Corr2dLMA { ...@@ -2691,14 +2696,22 @@ public class Corr2dLMA {
if (ac < 0) { if (ac < 0) {
continue; continue;
} }
strength = Math.sqrt(strength * Math.sqrt(ac)); // / area ); // new strength double strength1 = Math.sqrt(strength * Math.sqrt(ac)); // / area ); // new strength
ds[nmax][tile][0] = disparity; ds[nmax][tile][0] = disparity;
ds[nmax][tile][1] = (strength * lma_str_scale) + lma_str_offset; ds[nmax][tile][1] = (strength1 * lma_str_scale) + lma_str_offset;
ds[nmax][tile][2] = strength; // as is ds[nmax][tile][2] = strength1; // as is
if (ds[nmax][tile].length > 3) { if (ds[nmax][tile].length > 3) {
ds[nmax][tile][3] = area; ds[nmax][tile][3] = area;
ds[nmax][tile][4] = ac; ds[nmax][tile][4] = ac;
ds[nmax][tile][5] = Math.min(abc[tile][0],abc[tile][2]); ds[nmax][tile][5] = Math.min(abc[tile][0],abc[tile][2]);
ds[nmax][tile][6] = Math.max(abc[tile][0],abc[tile][2]);
ds[nmax][tile][7] = abc[tile][0];
ds[nmax][tile][8] = abc[tile][2];
ds[nmax][tile][9] = abc[tile][1];
ds[nmax][tile][10] = strength;
ds[nmax][tile][11] = rrms;
ds[nmax][tile][12] = rms[tile];
} }
} }
} }
...@@ -3053,7 +3066,7 @@ public class Corr2dLMA { ...@@ -3053,7 +3066,7 @@ public class Corr2dLMA {
} }
} }
if (debug_level > 0) { if (debug_level > 0) {
System.out.println("LMA: full RMS="+last_rms[0]+" ("+initial_rms[0]+"), pure RMS="+last_rms[1]+" ("+initial_rms[1]+") + lambda="+lambda); System.out.println("Corr2dLMA:LMA: full RMS="+last_rms[0]+" ("+initial_rms[0]+"), pure RMS="+last_rms[1]+" ("+initial_rms[1]+") + lambda="+lambda);
} }
return rslt[0]; return rslt[0];
......
...@@ -2860,8 +2860,12 @@ public class ImageDtt extends ImageDttCPU { ...@@ -2860,8 +2860,12 @@ public class ImageDtt extends ImageDttCPU {
// keep for now for mono, find out what do they mean for macro mode // keep for now for mono, find out what do they mean for macro mode
final int corr_size = transform_size * 2 - 1; final int corr_size = transform_size * 2 - 1;
final String[] debug_lma_titles_nobi = {"disp_samples","num_cnvx_samples","num_comb_samples", "num_lmas","num_iters","rms"};
final String[] debug_lma_titles_bi = {"disparity","strength_mod","strength", "area","ac","min(a,c)","max(a,c)","a","c","b","str1","rrms","rms"};
final String[] debug_lma_titles= imgdtt_params.bimax_dual_LMA? debug_lma_titles_bi:debug_lma_titles_nobi;
// final double [][] debug_lma = imgdtt_params.lmamask_dbg? (new double [6][tilesX*tilesY]):null;
final double [][] debug_lma = imgdtt_params.lmamask_dbg? (new double [debug_lma_titles.length][tilesX*tilesY]):null;
final double [][] debug_lma = imgdtt_params.lmamask_dbg? (new double [6][tilesX*tilesY]):null;
if (debug_lma != null) { if (debug_lma != null) {
for (int i = 0; i < debug_lma.length; i++) { for (int i = 0; i < debug_lma.length; i++) {
Arrays.fill(debug_lma[i], Double.NaN); Arrays.fill(debug_lma[i], Double.NaN);
...@@ -3026,7 +3030,8 @@ public class ImageDtt extends ImageDttCPU { ...@@ -3026,7 +3030,8 @@ public class ImageDtt extends ImageDttCPU {
} }
nTile = tileY * tilesX + tileX; nTile = tileY * tilesX + tileX;
if (tp_tasks[iTile].getTask() == 0) continue; // nothing to do for this tile if (tp_tasks[iTile].getTask() == 0) continue; // nothing to do for this tile
boolean debugTile0 =(tileX == debug_tileX) && (tileY == debug_tileY) && (globalDebugLevel > 1); // 0); boolean debugTile0 =(tileX == debug_tileX) && (tileY == debug_tileY) && (globalDebugLevel > 0); // 1);
debugTile0 |=(tileX == debug_tileX-1) && (tileY == debug_tileY) && (globalDebugLevel > 0); // 1);
boolean debugTile1 =(tileX == debug_tileX) && (tileY == debug_tileY) && (globalDebugLevel > -10); boolean debugTile1 =(tileX == debug_tileX) && (tileY == debug_tileY) && (globalDebugLevel > -10);
if (debugTile0) { if (debugTile0) {
System.out.println("clt_process_tl_correlations(): tileX="+tileX+", tileY="+tileY+", iTile="+iTile+", nTile="+nTile); System.out.println("clt_process_tl_correlations(): tileX="+tileX+", tileY="+tileY+", iTile="+iTile+", nTile="+nTile);
...@@ -3161,7 +3166,9 @@ public class ImageDtt extends ImageDttCPU { ...@@ -3161,7 +3166,9 @@ public class ImageDtt extends ImageDttCPU {
double [][] maxes = correlation2d.getDoublePoly( double [][] maxes = correlation2d.getDoublePoly(
disparity_scale, // double disparity_scale, disparity_scale, // double disparity_scale,
((corr_dia_tile != null) ? corr_dia_tile : corr_combo_tile), // double [] combo_corrs, ((corr_dia_tile != null) ? corr_dia_tile : corr_combo_tile), // double [] combo_corrs,
imgdtt_params.mcorr_dual_fract); //double min_fraction imgdtt_params.mcorr_dual_fract, //double min_fraction
imgdtt_params.mcorr_dual_min_max, // double min_max, // = 0.2; // Minimal absolute strength of the strongest in a dual-max to consider second one
imgdtt_params.mcorr_dual_min_min); // double min_min); // = 0.08; // Minimal absolute strength of a weakest in a dual-max to consider second one
if ((disparity_map != null) && (disparity_map[DISPARITY_VARIATIONS_INDEX] != null)) { if ((disparity_map != null) && (disparity_map[DISPARITY_VARIATIONS_INDEX] != null)) {
disparity_map[DISPARITY_VARIATIONS_INDEX ][nTile] = maxes.length; disparity_map[DISPARITY_VARIATIONS_INDEX ][nTile] = maxes.length;
} }
...@@ -3234,12 +3241,13 @@ public class ImageDtt extends ImageDttCPU { ...@@ -3234,12 +3241,13 @@ public class ImageDtt extends ImageDttCPU {
imgdtt_params.lmas_min_amp_bg, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude imgdtt_params.lmas_min_amp_bg, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3) imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS) imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
imgdtt_params.lmas_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line) imgdtt_params.lmas_min_max_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
imgdtt_params.lmas_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point) imgdtt_params.lmas_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
imgdtt_params.lmas_max_area, //double lma_max_area, // maximal half-area (if > 0.0) imgdtt_params.lmas_max_area, //double lma_max_area, // maximal half-area (if > 0.0)
imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
imgdtt_params.lma_str_offset, // convert lma-generated strength to match previous ones - add to result imgdtt_params.lma_str_offset, // convert lma-generated strength to match previous ones - add to result
dbg_dispStrs // false // boolean dbg_mode dbg_dispStrs, // false // boolean dbg_mode
imgdtt_params.lma_ac_offset // Add to A, C coefficients for near-lines where A,C could become negative because of window
); );
disp_str_lma = new double [dispStrs.length][]; // order matching input ones disp_str_lma = new double [dispStrs.length][]; // order matching input ones
for (int nmax = 0;nmax < dispStrs.length; nmax++) { for (int nmax = 0;nmax < dispStrs.length; nmax++) {
...@@ -3360,11 +3368,12 @@ public class ImageDtt extends ImageDttCPU { ...@@ -3360,11 +3368,12 @@ public class ImageDtt extends ImageDttCPU {
imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3) imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS) imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
imgdtt_params.lmas_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line) imgdtt_params.lmas_min_max_ac, // maximal of A and C coefficients minimum (measures sharpest point/line)
imgdtt_params.lmas_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point) imgdtt_params.lmas_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
imgdtt_params.lmas_max_area, //double lma_max_area, // maximal half-area (if > 0.0) imgdtt_params.lmas_max_area, //double lma_max_area, // maximal half-area (if > 0.0)
imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
imgdtt_params.lma_str_offset // convert lma-generated strength to match previous ones - add to result imgdtt_params.lma_str_offset, // convert lma-generated strength to match previous ones - add to result
imgdtt_params.lma_ac_offset // Add to A, C coefficients for near-lines where A,C could become negative because of window
); );
if (ds != null) { // always true if (ds != null) { // always true
// if (disparity_map!=null) { // if (disparity_map!=null) {
...@@ -3425,7 +3434,7 @@ public class ImageDtt extends ImageDttCPU { ...@@ -3425,7 +3434,7 @@ public class ImageDtt extends ImageDttCPU {
tilesY, tilesY,
true, true,
"lma_debug_dual_LMA", "lma_debug_dual_LMA",
new String[] {"disparity","strength_mod","strength", "area","ac","min(a,c)"} debug_lma_titles
); );
} else { } else {
(new ShowDoubleFloatArrays()).showArrays( (new ShowDoubleFloatArrays()).showArrays(
...@@ -3434,7 +3443,7 @@ public class ImageDtt extends ImageDttCPU { ...@@ -3434,7 +3443,7 @@ public class ImageDtt extends ImageDttCPU {
tilesY, tilesY,
true, true,
"lma_debug", "lma_debug",
new String[] {"disp_samples","num_cnvx_samples","num_comb_samples", "num_lmas","num_iters","rms"} debug_lma_titles
); );
} }
...@@ -4815,11 +4824,12 @@ public class ImageDtt extends ImageDttCPU { ...@@ -4815,11 +4824,12 @@ public class ImageDtt extends ImageDttCPU {
imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3) imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS) imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
imgdtt_params.lmas_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line) imgdtt_params.lmas_min_max_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
imgdtt_params.lmas_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point) imgdtt_params.lmas_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
imgdtt_params.lmas_max_area, // double lma_max_area, // maximal half-area (if > 0.0) imgdtt_params.lmas_max_area, // double lma_max_area, // maximal half-area (if > 0.0)
imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
imgdtt_params.lma_str_offset // convert lma-generated strength to match previous ones - add to result imgdtt_params.lma_str_offset, // convert lma-generated strength to match previous ones - add to result
imgdtt_params.lma_ac_offset // Add to A, C coefficients for near-lines where A,C could become negative because of window
)[0]; )[0];
if (tile_lma_debug_level > 0) { if (tile_lma_debug_level > 0) {
double [][] ds_dbg = {disp_str}; double [][] ds_dbg = {disp_str};
...@@ -5112,11 +5122,12 @@ public class ImageDtt extends ImageDttCPU { ...@@ -5112,11 +5122,12 @@ public class ImageDtt extends ImageDttCPU {
imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3) imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS) imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
imgdtt_params.lmas_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line) imgdtt_params.lmas_min_max_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
imgdtt_params.lmas_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point) imgdtt_params.lmas_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
imgdtt_params.lmas_max_area, // double lma_max_area, // maximal half-area (if > 0.0) imgdtt_params.lmas_max_area, // double lma_max_area, // maximal half-area (if > 0.0)
imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
imgdtt_params.lma_str_offset // convert lma-generated strength to match previous ones - add to result imgdtt_params.lma_str_offset, // convert lma-generated strength to match previous ones - add to result
imgdtt_params.lma_ac_offset // Add to A, C coefficients for near-lines where A,C could become negative because of window
)[0]; )[0];
if (tile_lma_debug_level > 0) { if (tile_lma_debug_level > 0) {
double [][] ds_dbg = {disp_str}; double [][] ds_dbg = {disp_str};
......
...@@ -2237,11 +2237,12 @@ public class ImageDttCPU { ...@@ -2237,11 +2237,12 @@ public class ImageDttCPU {
imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3) imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS) imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
imgdtt_params.lmas_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line) imgdtt_params.lmas_min_max_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
imgdtt_params.lmas_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point) imgdtt_params.lmas_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
imgdtt_params.lmas_max_area, // double lma_max_area, // maximal half-area (if > 0.0) imgdtt_params.lmas_max_area, // double lma_max_area, // maximal half-area (if > 0.0)
imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
imgdtt_params.lma_str_offset // convert lma-generated strength to match previous ones - add to result imgdtt_params.lma_str_offset, // convert lma-generated strength to match previous ones - add to result
imgdtt_params.lma_ac_offset // Add to A, C coefficients for near-lines where A,C could become negative because of window
)[0]; )[0];
if ((disp_str[cTile]!=null) && Double.isNaN(disp_str[cTile][1])) { if ((disp_str[cTile]!=null) && Double.isNaN(disp_str[cTile][1])) {
System.out.println(); System.out.println();
...@@ -2424,7 +2425,8 @@ public class ImageDttCPU { ...@@ -2424,7 +2425,8 @@ public class ImageDttCPU {
imgdtt_params.lma_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point) imgdtt_params.lma_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
imgdtt_params.lma_max_area, //double lma_max_area, // maximal half-area (if > 0.0) imgdtt_params.lma_max_area, //double lma_max_area, // maximal half-area (if > 0.0)
1.0, // imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale 1.0, // imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
0.0); // imgdtt_params.lma_str_offset); // convert lma-generated strength to match previous ones - add to result 0.0, // convert lma-generated strength to match previous ones - add to result
imgdtt_params.lma_ac_offset); // Add to A, C coefficients for near-lines where A,C could become negative because of window
// double [][] extra_stats = lma2.getTileStats(); // double [][] extra_stats = lma2.getTileStats();
if (debugCluster) { if (debugCluster) {
...@@ -3157,11 +3159,12 @@ public class ImageDttCPU { ...@@ -3157,11 +3159,12 @@ public class ImageDttCPU {
imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3) imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS) imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
imgdtt_params.lmas_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line) imgdtt_params.lmas_min_max_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
imgdtt_params.lmas_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point) imgdtt_params.lmas_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
imgdtt_params.lmas_max_area, //double lma_max_area, // maximal half-area (if > 0.0) imgdtt_params.lmas_max_area, //double lma_max_area, // maximal half-area (if > 0.0)
imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
imgdtt_params.lma_str_offset // convert lma-generated strength to match previous ones - add to result imgdtt_params.lma_str_offset, // convert lma-generated strength to match previous ones - add to result
imgdtt_params.lma_ac_offset // Add to A, C coefficients for near-lines where A,C could become negative because of window
); );
if (ds != null) { // always true if (ds != null) { // always true
disparity_map[DISPARITY_INDEX_POLY][tIndex] = ds[0][0]; disparity_map[DISPARITY_INDEX_POLY][tIndex] = ds[0][0];
...@@ -4262,11 +4265,12 @@ public class ImageDttCPU { ...@@ -4262,11 +4265,12 @@ public class ImageDttCPU {
imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3) imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS) imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
imgdtt_params.lmas_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line) imgdtt_params.lmas_min_max_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
imgdtt_params.lmas_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point) imgdtt_params.lmas_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
imgdtt_params.lmas_max_area, //double lma_max_area, // maximal half-area (if > 0.0) imgdtt_params.lmas_max_area, //double lma_max_area, // maximal half-area (if > 0.0)
imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
imgdtt_params.lma_str_offset // convert lma-generated strength to match previous ones - add to result imgdtt_params.lma_str_offset, // convert lma-generated strength to match previous ones - add to result
imgdtt_params.lma_ac_offset // Add to A, C coefficients for near-lines where A,C could become negative because of window
); );
if (ds != null) { // always true if (ds != null) { // always true
disp_lma[nTile] = ds[0][0]; disp_lma[nTile] = ds[0][0];
...@@ -5182,11 +5186,12 @@ public class ImageDttCPU { ...@@ -5182,11 +5186,12 @@ public class ImageDttCPU {
imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3) imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS) imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
imgdtt_params.lmas_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line) imgdtt_params.lmas_min_max_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
imgdtt_params.lmas_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point) imgdtt_params.lmas_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
imgdtt_params.lmas_max_area, //double lma_max_area, // maximal half-area (if > 0.0) imgdtt_params.lmas_max_area, //double lma_max_area, // maximal half-area (if > 0.0)
imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
imgdtt_params.lma_str_offset // convert lma-generated strength to match previous ones - add to result imgdtt_params.lma_str_offset, // convert lma-generated strength to match previous ones - add to result
imgdtt_params.lma_ac_offset // Add to A, C coefficients for near-lines where A,C could become negative because of window
); );
if (ds != null) { // always true if (ds != null) { // always true
disparity_map[DISPARITY_INDEX_POLY][nTileC] = ds[0][0]; disparity_map[DISPARITY_INDEX_POLY][nTileC] = ds[0][0];
...@@ -15608,11 +15613,12 @@ public class ImageDttCPU { ...@@ -15608,11 +15613,12 @@ public class ImageDttCPU {
imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3) imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS) imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
imgdtt_params.lmas_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line) imgdtt_params.lmas_min_max_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
imgdtt_params.lmas_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point) imgdtt_params.lmas_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
imgdtt_params.lmas_max_area, //double lma_max_area, // maximal half-area (if > 0.0) imgdtt_params.lmas_max_area, //double lma_max_area, // maximal half-area (if > 0.0)
imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
imgdtt_params.lma_str_offset // convert lma-generated strength to match previous ones - add to result imgdtt_params.lma_str_offset, // convert lma-generated strength to match previous ones - add to result
imgdtt_params.lma_ac_offset // Add to A, C coefficients for near-lines where A,C could become negative because of window
); );
lma2.printStats(ds,1); lma2.printStats(ds,1);
} }
...@@ -16618,11 +16624,12 @@ public class ImageDttCPU { ...@@ -16618,11 +16624,12 @@ public class ImageDttCPU {
imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3) imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS) imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
imgdtt_params.lmas_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line) imgdtt_params.lmas_min_max_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
imgdtt_params.lmas_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point) imgdtt_params.lmas_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
imgdtt_params.lmas_max_area, //double lma_max_area, // maximal half-area (if > 0.0) imgdtt_params.lmas_max_area, //double lma_max_area, // maximal half-area (if > 0.0)
imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
imgdtt_params.lma_str_offset // convert lma-generated strength to match previous ones - add to result imgdtt_params.lma_str_offset, // convert lma-generated strength to match previous ones - add to result
imgdtt_params.lma_ac_offset // Add to A, C coefficients for near-lines where A,C could become negative because of window
); );
if (ds != null) { // always true if (ds != null) { // always true
if (disparity_map!=null) { if (disparity_map!=null) {
......
...@@ -122,6 +122,120 @@ public class QuadCLT extends QuadCLTCPU { ...@@ -122,6 +122,120 @@ public class QuadCLT extends QuadCLTCPU {
} }
} }
/**
* Remove weak non-LMA tiles if they do not have any LMA or strong neighbors and
* too few weak neighbors. Single strong neighbor within range is enough, strong/LMA
* that are not within range are still counted towards total "good" neighbors. For
* example, weak tiles of the sky just above strong sky-line will survive if the
* number of similar weak neighbor tiles representing clouds plus number of sky-line
* tiles is sufficient. Range may be somewhat wider than that for stronger tiles.
* Strong neibs with lower disparity count as weak ones (towards number of good neibs).
* There should be at least one "near".
*
* @param dls {disparity, lma_disparity, strength} - not to be modified
* @param strong strength to be considered non weak
* @param weak strength to be considered weak, below - just delete (may be 0 if not used)
* @param min_neibs minimal number of neighbors (of 8) to survive
* @param tolerance_absolute - absolute tolerance
* @param tolerance_relative
* @param width
* @param max_iter
* @param threadsMax
* @param debug_level
* @return updated disparity with some tiles replaced with Double.NaN
*/
public static double [] removeFewWeak(
final double [][] dls,
final double strong,
final double weak,
final int min_neibs,
final double tolerance_absolute,
final double tolerance_relative,
final int width,
final int max_iter,
final int threadsMax,
final int debug_level)
{
final int tiles = dls[0].length;
final double [] disparity = dls[0].clone();
final double [] disparity_out = dls[0].clone();
final double [] disparity_lma = dls[1].clone();
final double [] strength = dls[2]; // will not be updated
final TileNeibs tn = new TileNeibs(width, tiles/width);
final Thread[] threads = ImageDtt.newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
final AtomicInteger anum_updated = new AtomicInteger(0);
final int dbg_tile = 2512;
for (int iter = 0; iter < max_iter; iter++) {
ai.set(0);
anum_updated.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nTile = ai.getAndIncrement(); nTile < tiles; nTile = ai.getAndIncrement()) {
if ((debug_level >0) && (nTile == dbg_tile)) {
System.out.println("removeFewWeak():removeDisparityOutliers() nTile="+nTile);
}
if ( !Double.isNaN(disparity[nTile]) &&
Double.isNaN(disparity_lma[nTile]) && // is not lma
(strength[nTile] < strong)) { // weak
if (strength[nTile] < weak) {
disparity_out[nTile] = Double.NaN;
anum_updated.getAndIncrement();
continue;
}
double tolerance = tolerance_absolute + ((disparity[nTile]>0)? disparity[nTile]*tolerance_relative:0);
double lim_max = disparity[nTile] + tolerance;
double lim_min = disparity[nTile] - tolerance;
int num_goog_neibs = 0; // strong or close
int num_near = 0;
boolean keep = false;
for (int dir = 0; dir < 8; dir++) {
int ineib = tn.getNeibIndex(nTile, dir);
if ((ineib >= 0) && !Double.isNaN(disparity[ineib])) {
boolean near = (disparity[ineib] >= lim_min) && (disparity[ineib] <= lim_max);
boolean is_strong = !Double.isNaN(disparity_lma[ineib]) ||
(strength[ineib] >= strong);
// Strong and near only counts for strong in FG (nearer), far ones same as weak
if (near && is_strong && (disparity[ineib] >= disparity[nTile])) {
keep = true;
break;
}
if (near || is_strong) {
num_goog_neibs++;
if (near) num_near++;
if ((num_goog_neibs >= min_neibs) && (num_near > 0)) {
keep = true;
break;
}
}
}
}
if (!keep) {
disparity_out[nTile] = Double.NaN;
anum_updated.getAndIncrement();
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
if (anum_updated.get() ==0) {
break;
}
System.arraycopy(disparity_out,0,disparity,0,tiles);
}
return disparity_out;
}
public static double [] removeDisparityLMAOutliers( // just LMA FG public static double [] removeDisparityLMAOutliers( // just LMA FG
final boolean non_lma, final boolean non_lma,
...@@ -144,7 +258,7 @@ public class QuadCLT extends QuadCLTCPU { ...@@ -144,7 +258,7 @@ public class QuadCLT extends QuadCLTCPU {
final Thread[] threads = ImageDtt.newThreadArray(threadsMax); final Thread[] threads = ImageDtt.newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0); final AtomicInteger ai = new AtomicInteger(0);
final AtomicInteger anum_updated = new AtomicInteger(0); final AtomicInteger anum_updated = new AtomicInteger(0);
final int dbg_tile = 989; final int dbg_tile = 2997;
for (int iter = 0; iter < max_iter; iter++) { for (int iter = 0; iter < max_iter; iter++) {
ai.set(0); ai.set(0);
anum_updated.set(0); anum_updated.set(0);
...@@ -157,7 +271,7 @@ public class QuadCLT extends QuadCLTCPU { ...@@ -157,7 +271,7 @@ public class QuadCLT extends QuadCLTCPU {
System.out.println("removeDisparityOutliers() nTile="+nTile); System.out.println("removeDisparityOutliers() nTile="+nTile);
} }
if ( !Double.isNaN(disparity[nTile]) && if ( !Double.isNaN(disparity[nTile]) &&
(!Double.isNaN(disparity_lma[nTile]) ^ non_lma) && (!Double.isNaN(disparity_lma[nTile]) ^ non_lma) && // is_lma
(strength[nTile] < max_strength)) { // weak LMA (strength[nTile] < max_strength)) { // weak LMA
Arrays.fill(neibs, Double.NaN); Arrays.fill(neibs, Double.NaN);
for (int dir = 0; dir < 8; dir++) { for (int dir = 0; dir < 8; dir++) {
...@@ -395,12 +509,13 @@ public class QuadCLT extends QuadCLTCPU { ...@@ -395,12 +509,13 @@ public class QuadCLT extends QuadCLTCPU {
final Thread[] threads = ImageDtt.newThreadArray(threadsMax); final Thread[] threads = ImageDtt.newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0); final AtomicInteger ai = new AtomicInteger(0);
final AtomicInteger anum_gaps = new AtomicInteger(0); final AtomicInteger anum_gaps = new AtomicInteger(0);
final int dbg_tile = 2191;
for (int ithread = 0; ithread < threads.length; ithread++) { for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() { threads[ithread] = new Thread() {
public void run() { public void run() {
for (int nTile = ai.getAndIncrement(); nTile < tiles; nTile = ai.getAndIncrement()) { for (int nTile = ai.getAndIncrement(); nTile < tiles; nTile = ai.getAndIncrement()) {
if (ds[0][nTile] < min_disparity) { if (ds[0][nTile] < min_disparity) {
ds[0][nTile] = min_disparity; ds[0][nTile] = Double.NaN; // min_disparity;
} }
if (Double.isNaN(ds[0][nTile]) || (ds[1][nTile] <= 0)) { if (Double.isNaN(ds[0][nTile]) || (ds[1][nTile] <= 0)) {
ds[0][nTile] = Double.NaN; ds[0][nTile] = Double.NaN;
...@@ -432,14 +547,23 @@ public class QuadCLT extends QuadCLTCPU { ...@@ -432,14 +547,23 @@ public class QuadCLT extends QuadCLTCPU {
double [] neibs_sorted = new double[8]; double [] neibs_sorted = new double[8];
for (int indx = ai.getAndIncrement(); indx < num_gaps; indx = ai.getAndIncrement()) { for (int indx = ai.getAndIncrement(); indx < num_gaps; indx = ai.getAndIncrement()) {
int nTile = tile_indices[indx]; int nTile = tile_indices[indx];
if ((debug_level >0) && (nTile == dbg_tile)) {
System.out.println("fillDisparityStrength() nTile="+nTile);
}
if (!fill_all[0] && !Double.isNaN(ds[0][nTile])) { if (!fill_all[0] && !Double.isNaN(ds[0][nTile])) {
continue; // fill only new continue; // fill only new
} }
Arrays.fill(neibs, Double.NaN); Arrays.fill(neibs, Double.NaN);
double swd = 0.0, sw = 0.0;
for (int dir = 0; dir < 8; dir++) { for (int dir = 0; dir < 8; dir++) {
int nt_neib = tn.getNeibIndex(nTile, dir); int nt_neib = tn.getNeibIndex(nTile, dir);
if (nt_neib >= 0) { if (nt_neib >= 0) {
neibs[dir] = ds[0][nt_neib]; neibs[dir] = ds[0][nt_neib];
if (! Double.isNaN(neibs[dir])) {
sw += neibw[dir];
swd += neibw[dir] * neibs[dir];
}
} }
} }
System.arraycopy(neibs, 0, neibs_sorted, 0, 8); System.arraycopy(neibs, 0, neibs_sorted, 0, 8);
...@@ -447,14 +571,17 @@ public class QuadCLT extends QuadCLTCPU { ...@@ -447,14 +571,17 @@ public class QuadCLT extends QuadCLTCPU {
if (Double.isNaN(neibs_sorted[min_defined - 1])) { if (Double.isNaN(neibs_sorted[min_defined - 1])) {
continue; // too few defined neighbors continue; // too few defined neighbors
} }
swd /= sw; // here = not zero;
if (!fill_all[0]) { if (!fill_all[0]) {
anum_gaps.getAndIncrement(); anum_gaps.getAndIncrement();
} }
double max_disp = neibs_sorted[num_bottom - 1]; double max_disp = neibs_sorted[num_bottom - 1];
if (!(ds[0][nTile] > max_sym_disparity)){ // if (!(ds[0][nTile] > max_sym_disparity)){
max_disp = Double.NaN; if (!(swd > max_sym_disparity)){ // here compare to average, not this!
max_disp = Double.NaN; // so it will average all
} }
double swd = 0.0, sw = 0.0; swd = 0.0;
sw = 0.0;
for (int dir = 0; dir < 8; dir++) { for (int dir = 0; dir < 8; dir++) {
if (!Double.isNaN(neibs[dir]) && !(neibs[dir] > max_disp)) { // handles NaNs if (!Double.isNaN(neibs[dir]) && !(neibs[dir] > max_disp)) { // handles NaNs
sw += neibw[dir]; sw += neibw[dir];
...@@ -486,6 +613,11 @@ public class QuadCLT extends QuadCLTCPU { ...@@ -486,6 +613,11 @@ public class QuadCLT extends QuadCLTCPU {
break; break;
} }
fill_all[0] = anum_gaps.get() == 0; // no new tiles filled fill_all[0] = anum_gaps.get() == 0; // no new tiles filled
if (npass == (num_passes-1)){
System.out.println("fillDisparityStrength() LAST PASS ! npass="+npass+", change="+Math.sqrt(amax_diff.get())+" ("+max_change+")");
System.out.println("fillDisparityStrength() LAST PASS ! npass="+npass+", change="+Math.sqrt(amax_diff.get())+" ("+max_change+")");
System.out.println("fillDisparityStrength() LAST PASS ! npass="+npass+", change="+Math.sqrt(amax_diff.get())+" ("+max_change+")");
}
} // for (int npass = 0; npass < num_passes; npass+= fill_all[0]? 1:0 ) } // for (int npass = 0; npass < num_passes; npass+= fill_all[0]? 1:0 )
return ds; return ds;
......
...@@ -172,8 +172,10 @@ public class QuadCLTCPU { ...@@ -172,8 +172,10 @@ public class QuadCLTCPU {
public void inc_accum() {num_accum++;} public void inc_accum() {num_accum++;}
public void set_orient(int num) {num_orient = num;} public void set_orient(int num) {num_orient = num;}
public void set_accum (int num) {num_accum = num;} public void set_accum (int num) {num_accum = num;}
public int getNumOrient() {return num_orient;} public int getNumOrient() {
public int getNumAccum() {return num_accum;} return num_orient;}
public int getNumAccum() {
return num_accum;}
public int getEarliestScene( public int getEarliestScene(
QuadCLT [] scenes) { QuadCLT [] scenes) {
...@@ -1241,6 +1243,7 @@ public class QuadCLTCPU { ...@@ -1241,6 +1243,7 @@ public class QuadCLTCPU {
public String saveAVIInModelDirectory( public String saveAVIInModelDirectory(
boolean dry_run,
String suffix, // null - use title from the imp String suffix, // null - use title from the imp
int mode_avi, int mode_avi,
int avi_JPEG_quality, int avi_JPEG_quality,
...@@ -1258,12 +1261,16 @@ public class QuadCLTCPU { ...@@ -1258,12 +1261,16 @@ public class QuadCLTCPU {
} }
file_path += ".avi"; file_path += ".avi";
imp.getCalibration().fps = fps; imp.getCalibration().fps = fps;
(new AVI_Writer()).writeImage ( if (dry_run) {
imp, // ImagePlus imp, System.out.println("saveAVIInModelDirectory(): simulated writing "+file_path);
file_path, // String path, } else {
mode_avi, // int compression, (new AVI_Writer()).writeImage (
avi_JPEG_quality); //int jpegQuality) imp, // ImagePlus imp,
System.out.println("saveAVIInModelDirectory(): saved "+file_path); file_path, // String path,
mode_avi, // int compression,
avi_JPEG_quality); //int jpegQuality)
System.out.println("saveAVIInModelDirectory(): saved "+file_path);
}
return file_path; return file_path;
} }
......
...@@ -8579,8 +8579,14 @@ if (debugLevel > -100) return true; // temporarily ! ...@@ -8579,8 +8579,14 @@ if (debugLevel > -100) return true; // temporarily !
final boolean updateStatus, final boolean updateStatus,
final int debugLevel) throws Exception final int debugLevel) throws Exception
{ {
int stereo_gap = clt_parameters.imp.stereo_gap;
double stereo_intereye = clt_parameters.imp.stereo_intereye;
double stereo_phone_width = clt_parameters.imp.stereo_phone_width; // 0 - no padding
boolean stereo_pad = (stereo_intereye > 0) && (stereo_phone_width > 0);
int video_crf = clt_parameters.imp.video_crf;
String video_codec = clt_parameters.imp.video_codec.toLowerCase();
long start_time_all = System.nanoTime(); long start_time_all = System.nanoTime();
OpticalFlow opticalFlow = new OpticalFlow( OpticalFlow opticalFlow = new OpticalFlow(
quadCLT_main.getNumSensors(), quadCLT_main.getNumSensors(),
...@@ -8597,7 +8603,8 @@ if (debugLevel > -100) return true; // temporarily ! ...@@ -8597,7 +8603,8 @@ if (debugLevel > -100) return true; // temporarily !
num_seq = pathFirstLast.length; num_seq = pathFirstLast.length;
} }
} }
String [][] video_lists = new String [num_seq][]; String [][] video_lists = new String [num_seq][];
int [][] stereo_widths = new int [num_seq][];
for (int nseq = 0; nseq < num_seq; nseq++) { for (int nseq = 0; nseq < num_seq; nseq++) {
long start_time_seq = System.nanoTime(); long start_time_seq = System.nanoTime();
System.out.println("\nSTARTED PROCESSING SCENE SEQUENCE "+nseq+" (last is "+(num_seq-1)+")"); System.out.println("\nSTARTED PROCESSING SCENE SEQUENCE "+nseq+" (last is "+(num_seq-1)+")");
...@@ -8609,6 +8616,7 @@ if (debugLevel > -100) return true; // temporarily ! ...@@ -8609,6 +8616,7 @@ if (debugLevel > -100) return true; // temporarily !
pathFirstLast[nseq].last); // int scene_last); // last scene to process (negative - add length pathFirstLast[nseq].last); // int scene_last); // last scene to process (negative - add length
} }
String [][] video_list = new String[1][]; String [][] video_list = new String[1][];
int [][] widths_list = new int [1][];
String model_directory = opticalFlow.buildSeries( String model_directory = opticalFlow.buildSeries(
(pathFirstLast != null), //boolean batch_mode, (pathFirstLast != null), //boolean batch_mode,
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
...@@ -8623,10 +8631,12 @@ if (debugLevel > -100) return true; // temporarily ! ...@@ -8623,10 +8631,12 @@ if (debugLevel > -100) return true; // temporarily !
properties, // Properties properties, properties, // Properties properties,
reset_from_extrinsics, // boolean reset_from_extrinsics, reset_from_extrinsics, // boolean reset_from_extrinsics,
video_list, // String [][] video_list, // null or list of generated avi or webm paths video_list, // String [][] video_list, // null or list of generated avi or webm paths
widths_list,
threadsMax, // final int threadsMax, // maximal number of threads to launch threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus, updateStatus, // final boolean updateStatus,
debugLevel+2); // final int debugLevel) debugLevel+2); // final int debugLevel)
video_lists[nseq] = video_list[0]; video_lists[nseq] = video_list[0];
stereo_widths[nseq] = widths_list[0];
System.out.println("PROCESSING SCENE SEQUENCE "+nseq+" (last is "+(num_seq-1)+") is FINISHED in "+ System.out.println("PROCESSING SCENE SEQUENCE "+nseq+" (last is "+(num_seq-1)+") is FINISHED in "+
IJ.d2s(0.000000001*(System.nanoTime()-start_time_seq),3)+" sec ("+ IJ.d2s(0.000000001*(System.nanoTime()-start_time_seq),3)+" sec ("+
IJ.d2s(0.000000001*(System.nanoTime()-start_time_all),3)+" sec from the overall start"); IJ.d2s(0.000000001*(System.nanoTime()-start_time_all),3)+" sec from the overall start");
...@@ -8647,7 +8657,6 @@ if (debugLevel > -100) return true; // temporarily ! ...@@ -8647,7 +8657,6 @@ if (debugLevel > -100) return true; // temporarily !
} }
// combine videos if generated // combine videos if generated
if ((video_lists.length > 1) && (video_lists[0] != null) && (video_lists[0].length > 1)) { // do not combine if single sequence or no videos if ((video_lists.length > 1) && (video_lists[0] != null) && (video_lists[0].length > 1)) { // do not combine if single sequence or no videos
String concat_list_name="concat.list";
concat_videos: { concat_videos: {
System.out.println("Generating "+(video_lists[0].length)+" combined video files."); System.out.println("Generating "+(video_lists[0].length)+" combined video files.");
String videoDirectory = quadCLT_main.correctionsParameters.selectVideoDirectory(true,true); String videoDirectory = quadCLT_main.correctionsParameters.selectVideoDirectory(true,true);
...@@ -8655,7 +8664,7 @@ if (debugLevel > -100) return true; // temporarily ! ...@@ -8655,7 +8664,7 @@ if (debugLevel > -100) return true; // temporarily !
break concat_videos; break concat_videos;
} }
File video_dir = new File (videoDirectory); File video_dir = new File (videoDirectory);
video_dir.mkdirs(); // SHould already exist actually video_dir.mkdirs(); // Should already exist actually
for (int nvideo = 0; nvideo < video_lists[0].length; nvideo++) { for (int nvideo = 0; nvideo < video_lists[0].length; nvideo++) {
// get name with <ts_sec_first>-<ts_sec_last> // get name with <ts_sec_first>-<ts_sec_last>
// String spath0 = video_lists[0][nvideo]; // String spath0 = video_lists[0][nvideo];
...@@ -8664,7 +8673,8 @@ if (debugLevel > -100) return true; // temporarily ! ...@@ -8664,7 +8673,8 @@ if (debugLevel > -100) return true; // temporarily !
String ts_sec0=name0.substring(0,name0.indexOf("_")); // seconds of the first timestamp String ts_sec0=name0.substring(0,name0.indexOf("_")); // seconds of the first timestamp
String ts_sec1=name1.substring(0,name1.indexOf("_")); // seconds of the last timestamp String ts_sec1=name1.substring(0,name1.indexOf("_")); // seconds of the last timestamp
String suffix0 = name0.substring(name0.indexOf("-")); // Skip timestamp String suffix0 = name0.substring(name0.indexOf("-")); // Skip timestamp
String combo_video_name = ts_sec0+"-"+ts_sec1+suffix0; String combo_video_name = ts_sec0+"-"+ts_sec1+suffix0;
String concat_list_name = combo_video_name.substring(0, combo_video_name.lastIndexOf("."))+".list";
File list_to_concat = new File (video_dir,concat_list_name); File list_to_concat = new File (video_dir,concat_list_name);
// delete if exists // delete if exists
if (list_to_concat.exists()) { if (list_to_concat.exists()) {
...@@ -8672,22 +8682,49 @@ if (debugLevel > -100) return true; // temporarily ! ...@@ -8672,22 +8682,49 @@ if (debugLevel > -100) return true; // temporarily !
} }
PrintWriter writer = new PrintWriter(list_to_concat, "UTF-8"); PrintWriter writer = new PrintWriter(list_to_concat, "UTF-8");
int this_stereo_width = 0;
int num_segments=0;
for (int i = 0; i <video_lists.length; i++) { for (int i = 0; i <video_lists.length; i++) {
if ((video_lists[i] != null) && (video_lists[i].length > nvideo)) { if ((video_lists[i] != null) && (video_lists[i].length > nvideo)) {
writer.println("file '"+video_lists[i][nvideo]+"'"); if ((new File(video_lists[i][nvideo])).exists()) {
writer.println("file '"+video_lists[i][nvideo]+"'");
if (stereo_pad) {
this_stereo_width = stereo_widths[i][nvideo];
}
num_segments++;
} else {
System.out.println("Missing video segment: "+video_lists[i][nvideo]);
}
} else { } else {
System.out.println("Specific video segment "+i+":"+nvideo+" is missing, skipping"); System.out.println("Specific video segment "+i+":"+nvideo+" is missing, skipping");
} }
} }
writer.close(); writer.close();
if (num_segments == 0) {
System.out.println("No segments found for "+combo_video_name);
continue;
}
if (this_stereo_width > 0) {
String combo_base = combo_video_name.substring(0,combo_video_name.lastIndexOf(".")) ;
String combo_ext = combo_video_name.substring(combo_video_name.lastIndexOf(".")) ;
combo_video_name = combo_base+"-"+stereo_phone_width+"mm"+combo_ext;
}
File video_out = new File (video_dir,combo_video_name); File video_out = new File (video_dir,combo_video_name);
if (video_out.exists()) { if (video_out.exists()) {
video_out.delete(); video_out.delete();
} }
double pts_scale = clt_parameters.imp.video_fps/clt_parameters.imp.sensor_fps; double pts_scale = clt_parameters.imp.video_fps/clt_parameters.imp.sensor_fps;
String shellCommand = String.format("ffmpeg -y -f concat -safe 0 -i %s -r 60 -vf setpts=%f*PTS %s", String shellCommand;
list_to_concat.toString(), pts_scale,video_out.toString()); if (this_stereo_width > 0) {// add padding to stereo video
int padded_width= 16* ( (int) Math.round((this_stereo_width + stereo_gap) * stereo_phone_width/stereo_intereye/32));
shellCommand = String.format(
"ffmpeg -y -f concat -safe 0 -i %s -r 60 -vf pad=width=%d:height=0:x=-1:y=-1:color=black,setpts=%f*PTS -b:v 0 -crf %d -c %s %s",
list_to_concat.toString(), padded_width, pts_scale, video_crf, video_codec, video_out.toString());
} else {
shellCommand = String.format("ffmpeg -y -f concat -safe 0 -i %s -r 60 -vf setpts=%f*PTS -b:v 0 -crf %d -c %s %s",
list_to_concat.toString(), pts_scale, video_crf, video_codec, video_out.toString());
}
Process p = null; Process p = null;
int exit_code = -1; int exit_code = -1;
......
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