Commit d23797ed authored by Andrey Filippov's avatar Andrey Filippov

Started correction of the tiles distortions for lens distortions during

correlation
parent 69057bd5
...@@ -732,7 +732,10 @@ public class GPUTileProcessor { ...@@ -732,7 +732,10 @@ public class GPUTileProcessor {
// TODO: move port coordinates out of color channel loop // TODO: move port coordinates out of color channel loop
double [][] centersXY_main = null; double [][] centersXY_main = null;
double [][] centersXY_aux = null; double [][] centersXY_aux = null;
double [][] disp_dist_main = new double[2 * quad_main][]; // used to correct 3D correlations
double [][] disp_dist_aux = new double[2 * quad_aux][]; // used to correct 3D correlations
if (geometryCorrection_main != null) { if (geometryCorrection_main != null) {
centersXY_main = geometryCorrection_main.getPortsCoordinatesAndDerivatives( centersXY_main = geometryCorrection_main.getPortsCoordinatesAndDerivatives(
geometryCorrection_main, // GeometryCorrection gc_main, geometryCorrection_main, // GeometryCorrection gc_main,
...@@ -740,6 +743,7 @@ public class GPUTileProcessor { ...@@ -740,6 +743,7 @@ public class GPUTileProcessor {
corr_rots_main, // Matrix [] rots, corr_rots_main, // Matrix [] rots,
null, // Matrix [][] deriv_rots, null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][] null, // double [][] pXYderiv, // if not null, should be double[8][]
disp_dist_main, // used to correct 3D correlations
centerX, centerX,
centerY, centerY,
disparity_main); // + disparity_corr); disparity_main); // + disparity_corr);
...@@ -756,6 +760,7 @@ public class GPUTileProcessor { ...@@ -756,6 +760,7 @@ public class GPUTileProcessor {
corr_rots_aux, // Matrix [] rots, corr_rots_aux, // Matrix [] rots,
null, // Matrix [][] deriv_rots, null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][] null, // double [][] pXYderiv, // if not null, should be double[8][]
disp_dist_aux, // used to correct 3D correlations
centerX, centerX,
centerY, centerY,
disparity_aux); // + disparity_corr); disparity_aux); // + disparity_corr);
......
...@@ -743,6 +743,7 @@ public class AlignmentCorrection { ...@@ -743,6 +743,7 @@ public class AlignmentCorrection {
corr_rots, // Matrix [] rots, corr_rots, // Matrix [] rots,
null, // Matrix [][] deriv_rots, null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][] null, // double [][] pXYderiv, // if not null, should be double[8][]
null, // double [][] disp_dist used to correct 3D correlations
centerX, centerX,
centerY, centerY,
disp_strength[2 * s.series + 0][s.tile]/magic_coeff); // disparity disp_strength[2 * s.series + 0][s.tile]/magic_coeff); // disparity
...@@ -752,6 +753,7 @@ public class AlignmentCorrection { ...@@ -752,6 +753,7 @@ public class AlignmentCorrection {
corr_rots, // Matrix [] rots, corr_rots, // Matrix [] rots,
null, // Matrix [][] deriv_rots, null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][] null, // double [][] pXYderiv, // if not null, should be double[8][]
null, // double [][] disp_dist used to correct 3D correlations
centerX, centerX,
centerY, centerY,
0.0); // disparity 0.0); // disparity
...@@ -3089,12 +3091,14 @@ B = |+dy0 -dy1 -2*dy3 | ...@@ -3089,12 +3091,14 @@ B = |+dy0 -dy1 -2*dy3 |
double [] pXY = mm.getPXY(); double [] pXY = mm.getPXY();
double [][] deriv = new double [2 * NUM_SENSORS][]; double [][] deriv = new double [2 * NUM_SENSORS][];
int dbg_index =dbg_index (pXY, dbg_decimate); int dbg_index =dbg_index (pXY, dbg_decimate);
double [][] disp_dist = new double[dbg_titles_xy.length][]; // used to correct 3D correlations
geometryCorrection.getPortsCoordinatesAndDerivatives( geometryCorrection.getPortsCoordinatesAndDerivatives(
geometryCorrection, // GeometryCorrection gc_main, geometryCorrection, // GeometryCorrection gc_main,
false, // boolean use_rig_offsets, false, // boolean use_rig_offsets,
corr_rots, // Matrix [] rots, corr_rots, // Matrix [] rots,
deriv_rots, // Matrix [][] deriv_rots, deriv_rots, // Matrix [][] deriv_rots,
deriv, // boolean calc_deriv, deriv, // boolean calc_deriv,
disp_dist, // used to correct 3D correlations
pXY[0], // double px, pXY[0], // double px,
pXY[1], // double py, pXY[1], // double py,
mm.getDisparityMeas()); // getDisparityTask()); // double disparity) mm.getDisparityMeas()); // getDisparityTask()); // double disparity)
...@@ -3124,6 +3128,7 @@ B = |+dy0 -dy1 -2*dy3 | ...@@ -3124,6 +3128,7 @@ B = |+dy0 -dy1 -2*dy3 |
1E-9, // 1E-8, //6, // double delta, // 1e-6 1E-9, // 1E-8, //6, // double delta, // 1e-6
corr_vector, // CorrVector corr_vector, corr_vector, // CorrVector corr_vector,
deriv_dbg, // j_partial_debug, // deriv_dbg, // j_partial_debug, //
null, // disp_dist, // used to correct 3D correlations
pXY[0], // double px, pXY[0], // double px,
pXY[1], // double py, pXY[1], // double py,
mm.getDisparityMeas()); // Task()); // double disparity) mm.getDisparityMeas()); // Task()); // double disparity)
...@@ -3260,9 +3265,10 @@ B = |+dy0 -dy1 -2*dy3 | ...@@ -3260,9 +3265,10 @@ B = |+dy0 -dy1 -2*dy3 |
double [][] f = geometryCorrection.getPortsCoordinatesAndDerivatives( // 4x2 double [][] f = geometryCorrection.getPortsCoordinatesAndDerivatives( // 4x2
geometryCorrection, // GeometryCorrection gc_main, geometryCorrection, // GeometryCorrection gc_main,
false, // boolean use_rig_offsets, false, // boolean use_rig_offsets,
corr_rots, // Matrix [] rots, corr_rots, // Matrix [] rots,
null, // Matrix [][] deriv_rots, null, // Matrix [][] deriv_rots,
null, // boolean calc_deriv, null, // boolean calc_deriv,
null, // disp_dist, // used to correct 3D correlations
pXY[0], // double px, pXY[0], // double px,
pXY[1], // double py, pXY[1], // double py,
mm.getDisparityMeas()); // getDisparityTask()); // double disparity) mm.getDisparityMeas()); // getDisparityTask()); // double disparity)
......
...@@ -2335,9 +2335,11 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0. ...@@ -2335,9 +2335,11 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
* @param use_rig_offsets - for the auxiliary camera - use offsets from the main one * @param use_rig_offsets - for the auxiliary camera - use offsets from the main one
* @param rots misalignment correction (now includes zoom in addition to rotations * @param rots misalignment correction (now includes zoom in addition to rotations
* @param deriv_rots derivatives by d_az, f_elev, d_rot, d_zoom * @param deriv_rots derivatives by d_az, f_elev, d_rot, d_zoom
* @param pXYderiv - null or double[2 * number_of_cameras][] array to accommodate derivatives of px, py by each of the parameters
* @param disp_dist - null or double[2 * number_of_cameras][] array to accommodate X,Y derivatives by disp and CCW90 of disp
* @param px pixel X coordinate * @param px pixel X coordinate
* @param py pixel Y coordinate * @param py pixel Y coordinate
* @param disparity disparity * @param disparity disparity (for non-distorted image space)
* @return array of per port pairs of pixel shifts * @return array of per port pairs of pixel shifts
*/ */
public double [][] getPortsCoordinatesAndDerivatives( public double [][] getPortsCoordinatesAndDerivatives(
...@@ -2346,6 +2348,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0. ...@@ -2346,6 +2348,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
Matrix [] rots, Matrix [] rots,
Matrix [][] deriv_rots, Matrix [][] deriv_rots,
double [][] pXYderiv, // if not null, should be double[8][] double [][] pXYderiv, // if not null, should be double[8][]
double [][] disp_dist, //
double px, double px,
double py, double py,
double disparity) double disparity)
...@@ -2405,7 +2408,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0. ...@@ -2405,7 +2408,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
rD2rND += rad_coeff[j]*(rri - 1.0); // Fixed rD2rND += rad_coeff[j]*(rri - 1.0); // Fixed
} }
// Get port pixel coordiantes by scaling the 2d vector with Rdistorted/Dnondistorted coefficient) // Get port pixel coordinates by scaling the 2d vector with Rdistorted/Dnondistorted coefficient)
double pXid = pXci * rD2rND; double pXid = pXci * rD2rND;
double pYid = pYci * rD2rND; double pYid = pYci * rD2rND;
...@@ -2414,6 +2417,33 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0. ...@@ -2414,6 +2417,33 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
pXY[i][0] = pXid + this.pXY0[i][0]; pXY[i][0] = pXid + this.pXY0[i][0];
pXY[i][1] = pYid + this.pXY0[i][1]; pXY[i][1] = pYid + this.pXY0[i][1];
if (disp_dist != null) {
disp_dist[2 * i] = new double [2]; // dx/d_disp, dx_d_ccw_disp
disp_dist[2 * i+1] = new double [2]; // dy/d_disp, dy_d_ccw_disp
double [][] add0 = {
{-disparity * rXY[i][0], disparity * rXY[i][1]},
{-disparity * rXY[i][1], -disparity * rXY[i][0]}};
Matrix dd0 = new Matrix(add0);
Matrix dd1 = rots[i].times(dd0).getMatrix(0, 1,0,1).times(norm_z); // get top left 2x2 sub-matrix
// unity vector in the direction of radius
double c_dist = pXci/rNDi;
double s_dist = pYci/rNDi;
double c2_dist = c_dist * c_dist;
double s2_dist = s_dist * s_dist;
double cs_dist = c_dist * s_dist;
double [][] adist_dcorr = {
{rD2rND * c2_dist + s2_dist, (rD2rND - 1)* cs_dist},
{(rD2rND - 1)* cs_dist, rD2rND * s2_dist + c2_dist}};
Matrix dist_dcorr = new Matrix(adist_dcorr);
Matrix dd2 = dist_dcorr.times(dd1);
disp_dist[2 * i ][0] = dd2.get(0, 0);
disp_dist[2 * i ][1] = dd2.get(0, 1);
disp_dist[2 * i+1][0] = dd2.get(1, 0);
disp_dist[2 * i+1][1] = dd2.get(1, 1);
}
if (pXYderiv != null) { if (pXYderiv != null) {
...@@ -2691,6 +2721,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0. ...@@ -2691,6 +2721,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
double delta, // 1e-6 double delta, // 1e-6
CorrVector corr_vector, CorrVector corr_vector,
double [][] pXYderiv, // if not null, should be double[8][] double [][] pXYderiv, // if not null, should be double[8][]
double [][] disp_dist, //
double px, double px,
double py, double py,
double disparity) double disparity)
...@@ -2703,6 +2734,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0. ...@@ -2703,6 +2734,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
corr_rots, // Matrix [] rots, corr_rots, // Matrix [] rots,
null, // deriv_rots, // Matrix [][] deriv_rots, null, // deriv_rots, // Matrix [][] deriv_rots,
null, // pXYderiv0, // null, // false, // boolean calc_deriv, null, // pXYderiv0, // null, // false, // boolean calc_deriv,
disp_dist,
px, // double px, px, // double px,
py, // double py, py, // double py,
disparity // double disparity disparity // double disparity
...@@ -2725,6 +2757,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0. ...@@ -2725,6 +2757,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
corr_rots_p, // Matrix [] rots, corr_rots_p, // Matrix [] rots,
null, // Matrix [][] deriv_rots, null, // Matrix [][] deriv_rots,
null, // boolean calc_deriv, null, // boolean calc_deriv,
disp_dist,
px, // double px, px, // double px,
py, // double py, py, // double py,
disparity // double disparity disparity // double disparity
...@@ -2735,6 +2768,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0. ...@@ -2735,6 +2768,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
corr_rots_m, // Matrix [] rots, corr_rots_m, // Matrix [] rots,
null, // Matrix [][] deriv_rots, null, // Matrix [][] deriv_rots,
null, // boolean calc_deriv, null, // boolean calc_deriv,
disp_dist,
px, // double px, px, // double px,
py, // double py, py, // double py,
disparity // double disparity disparity // double disparity
......
...@@ -1046,6 +1046,7 @@ public class ImageDtt { ...@@ -1046,6 +1046,7 @@ public class ImageDtt {
corr_rots, // Matrix [] rots, corr_rots, // Matrix [] rots,
null, // Matrix [][] deriv_rots, null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][] null, // double [][] pXYderiv, // if not null, should be double[8][]
null, // double [][] disp_dist used to correct 3D correlations
centerX, centerX,
centerY, centerY,
disparity); disparity);
...@@ -1822,6 +1823,7 @@ public class ImageDtt { ...@@ -1822,6 +1823,7 @@ public class ImageDtt {
centerY = tileY * transform_size + transform_size/2 - shiftY; centerY = tileY * transform_size + transform_size/2 - shiftY;
// TODO: move port coordinates out of color channel loop // TODO: move port coordinates out of color channel loop
double [][] centersXY; double [][] centersXY;
double [][] disp_dist = new double[2 * quad][]; // used to correct 3D correlations
if ((disparity_array == null) || (disparity_array[tileY] == null) || (Double.isNaN(disparity_array[tileY][tileX]))) { if ((disparity_array == null) || (disparity_array[tileY] == null) || (Double.isNaN(disparity_array[tileY][tileX]))) {
System.out.println("Bug with disparity_array !!!"); System.out.println("Bug with disparity_array !!!");
...@@ -1846,6 +1848,7 @@ public class ImageDtt { ...@@ -1846,6 +1848,7 @@ public class ImageDtt {
corr_rots, // Matrix [] rots, corr_rots, // Matrix [] rots,
null, // Matrix [][] deriv_rots, null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][] null, // double [][] pXYderiv, // if not null, should be double[8][]
disp_dist, // used to correct 3D correlations
centerX, centerX,
centerY, centerY,
disparity_array[tileY][tileX] + disparity_corr); // _aux); // + disparity_corr); disparity_array[tileY][tileX] + disparity_corr); // _aux); // + disparity_corr);
...@@ -1854,10 +1857,11 @@ public class ImageDtt { ...@@ -1854,10 +1857,11 @@ public class ImageDtt {
} else { } else {
centersXY = geometryCorrection.getPortsCoordinatesAndDerivatives( centersXY = geometryCorrection.getPortsCoordinatesAndDerivatives(
geometryCorrection, // GeometryCorrection gc_main, geometryCorrection, // GeometryCorrection gc_main,
false, // boolean use_rig_offsets, false, // boolean use_rig_offsets,
corr_rots, // Matrix [] rots, corr_rots, // Matrix [] rots,
null, // Matrix [][] deriv_rots, null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][] null, // double [][] pXYderiv, // if not null, should be double[8][]
disp_dist, // used to correct 3D correlations
centerX, centerX,
centerY, centerY,
disparity_array[tileY][tileX] + disparity_corr); disparity_array[tileY][tileX] + disparity_corr);
...@@ -6447,6 +6451,7 @@ public class ImageDtt { ...@@ -6447,6 +6451,7 @@ public class ImageDtt {
corr_rots, // Matrix [] rots, corr_rots, // Matrix [] rots,
null, // Matrix [][] deriv_rots, null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][] null, // double [][] pXYderiv, // if not null, should be double[8][]
null, // double [][] disp_dist used to correct 3D correlations
centerX, centerX,
centerY, centerY,
disparity_array[tileY][tileX] + disparity_corr); disparity_array[tileY][tileX] + disparity_corr);
...@@ -8225,12 +8230,16 @@ public class ImageDtt { ...@@ -8225,12 +8230,16 @@ public class ImageDtt {
if (disparity_bimap != null){ if (disparity_bimap != null){
disparity_bimap[BI_TARGET_INDEX][tIndex] = disparity_main; disparity_bimap[BI_TARGET_INDEX][tIndex] = disparity_main;
} }
double [][] disp_dist_main = new double[2 * quad_main][]; // used to correct 3D correlations
double [][] disp_dist_aux = new double[2 * quad_aux][]; // used to correct 3D correlations
centersXY_main = geometryCorrection_main.getPortsCoordinatesAndDerivatives( centersXY_main = geometryCorrection_main.getPortsCoordinatesAndDerivatives(
geometryCorrection_main, // GeometryCorrection gc_main, geometryCorrection_main, // GeometryCorrection gc_main,
false, // boolean use_rig_offsets, false, // boolean use_rig_offsets,
corr_rots_main, // Matrix [] rots, corr_rots_main, // Matrix [] rots,
null, // Matrix [][] deriv_rots, null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][] null, // double [][] pXYderiv, // if not null, should be double[8][]
disp_dist_main, // used to correct 3D correlations
centerX, centerX,
centerY, centerY,
disparity_main); // + disparity_corr); disparity_main); // + disparity_corr);
...@@ -8241,6 +8250,7 @@ public class ImageDtt { ...@@ -8241,6 +8250,7 @@ public class ImageDtt {
corr_rots_aux, // Matrix [] rots, corr_rots_aux, // Matrix [] rots,
null, // Matrix [][] deriv_rots, null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][] null, // double [][] pXYderiv, // if not null, should be double[8][]
disp_dist_aux, // used to correct 3D correlations
centerX, centerX,
centerY, centerY,
disparity_aux); // + disparity_corr); disparity_aux); // + disparity_corr);
...@@ -9023,6 +9033,8 @@ public class ImageDtt { ...@@ -9023,6 +9033,8 @@ public class ImageDtt {
if (disparity_bimap != null){ if (disparity_bimap != null){
disparity_bimap[BI_TARGET_INDEX][tIndex] = disparity_main; disparity_bimap[BI_TARGET_INDEX][tIndex] = disparity_main;
} }
double [][] disp_dist_main = new double[2 * quad_main][]; // used to correct 3D correlations
double [][] disp_dist_aux = new double[2 * quad_aux][]; // used to correct 3D correlations
if (calc_main) { if (calc_main) {
centersXY_main = geometryCorrection_main.getPortsCoordinatesAndDerivatives( centersXY_main = geometryCorrection_main.getPortsCoordinatesAndDerivatives(
geometryCorrection_main, // GeometryCorrection gc_main, geometryCorrection_main, // GeometryCorrection gc_main,
...@@ -9030,6 +9042,7 @@ public class ImageDtt { ...@@ -9030,6 +9042,7 @@ public class ImageDtt {
corr_rots_main, // Matrix [] rots, corr_rots_main, // Matrix [] rots,
null, // Matrix [][] deriv_rots, null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][] null, // double [][] pXYderiv, // if not null, should be double[8][]
disp_dist_main, // used to correct 3D correlations
centerX, centerX,
centerY, centerY,
disparity_main); // + disparity_corr); disparity_main); // + disparity_corr);
...@@ -9042,6 +9055,7 @@ public class ImageDtt { ...@@ -9042,6 +9055,7 @@ public class ImageDtt {
corr_rots_aux, // Matrix [] rots, corr_rots_aux, // Matrix [] rots,
null, // Matrix [][] deriv_rots, null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][] null, // double [][] pXYderiv, // if not null, should be double[8][]
disp_dist_aux, // used to correct 3D correlations
centerX, centerX,
centerY, centerY,
disparity_aux); // + disparity_corr); disparity_aux); // + disparity_corr);
...@@ -9052,6 +9066,7 @@ public class ImageDtt { ...@@ -9052,6 +9066,7 @@ public class ImageDtt {
corr_rots_aux, // Matrix [] rots, corr_rots_aux, // Matrix [] rots,
null, // Matrix [][] deriv_rots, null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][] null, // double [][] pXYderiv, // if not null, should be double[8][]
disp_dist_aux, // used to correct 3D correlations
centerX, centerX,
centerY, centerY,
disparity_main); // + disparity_corr); disparity_main); // + disparity_corr);
......
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