Commit d23797ed authored by Andrey Filippov's avatar Andrey Filippov
Browse files

Started correction of the tiles distortions for lens distortions during

correlation
parent 69057bd5
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -733,6 +733,9 @@ public class GPUTileProcessor {
						// TODO: move port coordinates out of color channel loop
						double [][] centersXY_main = 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) {
							centersXY_main = geometryCorrection_main.getPortsCoordinatesAndDerivatives(
									geometryCorrection_main, //			GeometryCorrection gc_main,
@@ -740,6 +743,7 @@ public class GPUTileProcessor {
									corr_rots_main, // Matrix []   rots,
									null,           //  Matrix [][] deriv_rots,
									null,           // double [][] pXYderiv, // if not null, should be double[8][]
									disp_dist_main,       // used to correct 3D correlations
									centerX,
									centerY,
									disparity_main); //  + disparity_corr);
@@ -756,6 +760,7 @@ public class GPUTileProcessor {
									corr_rots_aux,   // Matrix []   rots,
									null,            //  Matrix [][] deriv_rots,
									null,            // double [][] pXYderiv, // if not null, should be double[8][]
									disp_dist_aux,   // used to correct 3D correlations
									centerX,
									centerY,
									disparity_aux); //  + disparity_corr);
+9 −3
Original line number Diff line number Diff line
@@ -743,6 +743,7 @@ public class AlignmentCorrection {
					corr_rots, // Matrix []   rots,
					null,      //  Matrix [][] deriv_rots,
					null,      // double [][] pXYderiv, // if not null, should be double[8][]
					null,      // double [][] disp_dist used to correct 3D correlations
					centerX,
					centerY,
					disp_strength[2 * s.series + 0][s.tile]/magic_coeff); // disparity
@@ -752,6 +753,7 @@ public class AlignmentCorrection {
					corr_rots, // Matrix []   rots,
					null,      //  Matrix [][] deriv_rots,
					null,      // double [][] pXYderiv, // if not null, should be double[8][]
					null,      // double [][] disp_dist used to correct 3D correlations
					centerX,
					centerY,
					0.0); // disparity
@@ -3089,12 +3091,14 @@ B = |+dy0 -dy1 -2*dy3 |
			double [] pXY = mm.getPXY();
			double [][] deriv = new double [2 * NUM_SENSORS][];
			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, //			GeometryCorrection gc_main,
					false,       // boolean use_rig_offsets,
					corr_rots,   //  Matrix []   rots,
					deriv_rots,  //  Matrix [][] deriv_rots,
					deriv,       // 	boolean calc_deriv,
					disp_dist,   // used to correct 3D correlations
					pXY[0],      // double px,
					pXY[1],      // double py,
					mm.getDisparityMeas()); // getDisparityTask()); // double disparity)
@@ -3124,6 +3128,7 @@ B = |+dy0 -dy1 -2*dy3 |
						1E-9, // 1E-8, //6,    // double delta, // 1e-6
						corr_vector, // CorrVector corr_vector,
						deriv_dbg, // j_partial_debug, //
						null, // disp_dist,       // used to correct 3D correlations
						pXY[0],      // double px,
						pXY[1],      // double py,
						mm.getDisparityMeas()); // Task()); // double disparity)
@@ -3263,6 +3268,7 @@ B = |+dy0 -dy1 -2*dy3 |
					corr_rots,   //  Matrix []   rots,
					null,        //  Matrix [][] deriv_rots,
					null,        //	boolean calc_deriv,
					null,        // disp_dist,       // used to correct 3D correlations
					pXY[0],      // double px,
					pXY[1],      // double py,
					mm.getDisparityMeas()); // getDisparityTask()); // double disparity)
+36 −2
Original line number Diff line number Diff line
@@ -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 rots misalignment correction (now includes zoom in addition to rotations
	 * @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 py pixel Y coordinate
	 * @param disparity disparity
	 * @param disparity disparity (for non-distorted image space)
	 * @return array of per port pairs of pixel shifts
	 */
	public double [][] getPortsCoordinatesAndDerivatives(
@@ -2346,6 +2348,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
			Matrix []   rots,
			Matrix [][] deriv_rots,
			double [][] pXYderiv, // if not null, should be double[8][]
			double [][] disp_dist, //
			double px,
			double py,
			double disparity)
@@ -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
			}

			// 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 pYid = pYci * rD2rND;

@@ -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][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) {
@@ -2691,6 +2721,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
			double delta, // 1e-6
			CorrVector corr_vector,
			double [][] pXYderiv, // if not null, should be double[8][]
			double [][] disp_dist, //
			double px,
			double py,
			double disparity)
@@ -2703,6 +2734,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
				corr_rots, // Matrix []   rots,
				null, // deriv_rots, // Matrix [][] deriv_rots,
				null, // pXYderiv0, // null, // false, // boolean calc_deriv,
				disp_dist,
				px, // double px,
				py, // double py,
				disparity // double disparity
@@ -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,
					null, // Matrix [][] deriv_rots,
					null, // boolean calc_deriv,
					disp_dist,
					px, // double px,
					py, // double py,
					disparity // double disparity
@@ -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,
					null, // Matrix [][] deriv_rots,
					null, // boolean calc_deriv,
					disp_dist,
					px, // double px,
					py, // double py,
					disparity // double disparity
+19 −4
Original line number Diff line number Diff line
@@ -1046,6 +1046,7 @@ public class ImageDtt {
								corr_rots, // Matrix []   rots,
								null,      //  Matrix [][] deriv_rots,
								null,      // double [][] pXYderiv, // if not null, should be double[8][]
								null,      // double [][] disp_dist used to correct 3D correlations
								centerX,
								centerY,
								disparity);
@@ -1822,6 +1823,7 @@ public class ImageDtt {
						centerY = tileY * transform_size + transform_size/2 - shiftY;
						// TODO: move port coordinates out of color channel loop
						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]))) {
							System.out.println("Bug with disparity_array !!!");
@@ -1846,6 +1848,7 @@ public class ImageDtt {
										corr_rots,       // Matrix []   rots,
										null,            //  Matrix [][] deriv_rots,
										null,            // double [][] pXYderiv, // if not null, should be double[8][]
										disp_dist,       // used to correct 3D correlations
										centerX,
										centerY,
										disparity_array[tileY][tileX] + disparity_corr); // _aux); //  + disparity_corr);
@@ -1858,6 +1861,7 @@ public class ImageDtt {
										corr_rots,       // Matrix []   rots,
										null,            //  Matrix [][] deriv_rots,
										null,            // double [][] pXYderiv, // if not null, should be double[8][]
										disp_dist,       // used to correct 3D correlations
										centerX,
										centerY,
										disparity_array[tileY][tileX] + disparity_corr);
@@ -6447,6 +6451,7 @@ public class ImageDtt {
									corr_rots, // Matrix []   rots,
									null,      //  Matrix [][] deriv_rots,
									null,      // double [][] pXYderiv, // if not null, should be double[8][]
									null,      // double [][] disp_dist used to correct 3D correlations
									centerX,
									centerY,
									disparity_array[tileY][tileX] + disparity_corr);
@@ -8225,12 +8230,16 @@ public class ImageDtt {
						if (disparity_bimap != null){
							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(
								geometryCorrection_main, //			GeometryCorrection gc_main,
								false,          // boolean use_rig_offsets,
								corr_rots_main, // Matrix []   rots,
								null,           //  Matrix [][] deriv_rots,
								null,           // double [][] pXYderiv, // if not null, should be double[8][]
								disp_dist_main, // used to correct 3D correlations
								centerX,
								centerY,
								disparity_main); //  + disparity_corr);
@@ -8241,6 +8250,7 @@ public class ImageDtt {
								corr_rots_aux,   // Matrix []   rots,
								null,            //  Matrix [][] deriv_rots,
								null,            // double [][] pXYderiv, // if not null, should be double[8][]
								disp_dist_aux,   // used to correct 3D correlations
								centerX,
								centerY,
								disparity_aux); //  + disparity_corr);
@@ -9023,6 +9033,8 @@ public class ImageDtt {
						if (disparity_bimap != null){
							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) {
							centersXY_main = geometryCorrection_main.getPortsCoordinatesAndDerivatives(
									geometryCorrection_main, //			GeometryCorrection gc_main,
@@ -9030,6 +9042,7 @@ public class ImageDtt {
									corr_rots_main, // Matrix []   rots,
									null,           //  Matrix [][] deriv_rots,
									null,           // double [][] pXYderiv, // if not null, should be double[8][]
									disp_dist_main, // used to correct 3D correlations
									centerX,
									centerY,
									disparity_main); //  + disparity_corr);
@@ -9042,6 +9055,7 @@ public class ImageDtt {
										corr_rots_aux,   // Matrix []   rots,
										null,            //  Matrix [][] deriv_rots,
										null,            // double [][] pXYderiv, // if not null, should be double[8][]
										disp_dist_aux, // used to correct 3D correlations
										centerX,
										centerY,
										disparity_aux); //  + disparity_corr);
@@ -9052,6 +9066,7 @@ public class ImageDtt {
										corr_rots_aux,   // Matrix []   rots,
										null,            //  Matrix [][] deriv_rots,
										null,            // double [][] pXYderiv, // if not null, should be double[8][]
										disp_dist_aux, // used to correct 3D correlations
										centerX,
										centerY,
										disparity_main); //  + disparity_corr);