Commit c8fd13f4 authored by Andrey Filippov's avatar Andrey Filippov

Tested rig (2 quad cameras) matrices and manual adjustment

parent e59c6d14
......@@ -731,6 +731,7 @@ public class AlignmentCorrection {
double centerY = tileY * qc.tp.getTileSize() + qc.tp.getTileSize()/2;//- shiftY;
double [][] centersXY_disp = qc.geometryCorrection.getPortsCoordinatesAndDerivatives(
false, // boolean use_rig_offsets,
corr_rots, // Matrix [] rots,
null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][]
......@@ -738,6 +739,7 @@ public class AlignmentCorrection {
centerY,
disp_strength[2 * s.series + 0][s.tile]/magic_coeff); // disparity
double [][] centersXY_inf = qc.geometryCorrection.getPortsCoordinatesAndDerivatives(
false, // boolean use_rig_offsets,
corr_rots, // Matrix [] rots,
null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][]
......@@ -2434,6 +2436,7 @@ System.out.println("test1234");
double [][] deriv = new double [2 * NUM_SENSORS][];
int dbg_index =dbg_index (pXY, dbg_decimate);
geometryCorrection.getPortsCoordinatesAndDerivatives(
false, // boolean use_rig_offsets,
corr_rots, // Matrix [] rots,
deriv_rots, // Matrix [][] deriv_rots,
deriv, // boolean calc_deriv,
......@@ -2458,6 +2461,7 @@ System.out.println("test1234");
double [][] deriv_dbg = new double [2 * NUM_SENSORS][];
double [] dbg_a_vector= null;
geometryCorrection.getPortsCoordinatesAndDerivatives(
false, // boolean use_rig_offsets,
dbg_a_vector, // double [] dbg_a_vector, // replace actual radial distortion coefficients
1E-9, // 1E-8, //6, // double delta, // 1e-6
corr_vector, // CorrVector corr_vector,
......@@ -2596,6 +2600,7 @@ System.out.println("test1234");
Mismatch mm = mismatch_list.get(indx);
double [] pXY = mm.getPXY();
double [][] f = geometryCorrection.getPortsCoordinatesAndDerivatives( // 4x2
false, // boolean use_rig_offsets,
corr_rots, // Matrix [] rots,
null, // Matrix [][] deriv_rots,
null, // boolean calc_deriv,
......
......@@ -730,7 +730,7 @@ public class EyesisCorrectionParameters {
updateAuxFromMain();
gd.addTab ("File paths", "Select files and directories paths (common to main and optional auxilliary)");
gd.addTab ("File paths", "Select files and directories paths (common to main and optional auxiliary)");
gd.addMessage ("============ Common to the main and optional auxiliary camera============");
gd.addCheckbox ("Save current settings with results", this.saveSettings); // 1
......
......@@ -578,6 +578,7 @@ private Panel panel1,
panelClt4.setLayout(new GridLayout(1, 0, 5, 5)); // rows, columns, vgap, hgap
addButton("Import Aux", panelClt4, color_restore);
addButton("Setup CLT Batch parameters", panelClt4, color_configure);
addButton("CLT rig edit", panelClt4, color_configure);
addButton("CLT 2*4 images", panelClt4, color_conf_process);
addButton("CLT 2*4 images - 2", panelClt4, color_conf_process);
addButton("CLT 2*4 images - 3", panelClt4, color_conf_process);
......@@ -4490,11 +4491,28 @@ private Panel panel1,
}
}
QUAD_CLT_AUX.showExtrinsicCorr("aux");// show_fine_corr("aux");
// QuadCLT dbg_QUAD_CLT = QUAD_CLT;
// QuadCLT dbg_QUAD_CLT_AUX = QUAD_CLT_AUX;
QuadCLT dbg_QUAD_CLT = QUAD_CLT;
QuadCLT dbg_QUAD_CLT_AUX = QUAD_CLT_AUX;
return;
/* ======================================================================== */
} else if (label.equals("CLT rig edit")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
if (QUAD_CLT_AUX == null){
if (EYESIS_CORRECTIONS_AUX == null) {
EYESIS_CORRECTIONS_AUX = new EyesisCorrections(SYNC_COMMAND.stopRequested,CORRECTION_PARAMETERS.getAux());
}
QUAD_CLT_AUX = new QuadCLT (
QuadCLT.PREFIX_AUX,
PROPERTIES,
EYESIS_CORRECTIONS_AUX,
CORRECTION_PARAMETERS.getAux());
if (DEBUG_LEVEL > 0){
System.out.println("Created new QuadCLT instance, will need to read CLT kernels for aux camera");
}
}
QUAD_CLT_AUX.editRig();
return;
//JTabbedTest
// End of buttons code
}
......@@ -4559,8 +4577,6 @@ private Panel panel1,
CHANNEL_GAINS_PARAMETERS_AUX = new CorrectionColorProc.ColorGainsParameters();
}
CHANNEL_GAINS_PARAMETERS_AUX.getProperties("CHANNEL_GAINS_PARAMETERS.", aux_properties);
// QUAD_CLT_AUX.getProperties(QuadCLT.PREFIX);
// QUAD_CLT_AUX.setProperties(QuadCLT.PREFIX_AUX);
/*
* public void copyPropertiesFrom(Properties other_properties, String other_prefix, String this_prefix){ // save
......@@ -4834,6 +4850,9 @@ private Panel panel1,
TWO_QUAD_CLT = new TwoQuadCLT();
}
if (new_mode) {
if (DEBUG_LEVEL > -2){
System.out.println("++++++++++++++ Calculating combined correlations ++++++++++++++");
}
try {
TWO_QUAD_CLT.processCLTQuadCorrPairs(
QUAD_CLT, // QuadCLT quadCLT_main,
......@@ -4852,6 +4871,9 @@ private Panel panel1,
e.printStackTrace();
} //final int debugLevel);
} else {
if (DEBUG_LEVEL > -2){
System.out.println("++++++++++++++ Calculating per quad camera correlations ++++++++++++++");
}
try {
TWO_QUAD_CLT.processCLTQuadCorrs(
QUAD_CLT, // QuadCLT quadCLT_main,
......
import java.util.Properties;
import Jama.Matrix;
import ij.IJ;
......@@ -27,6 +29,7 @@ import ij.IJ;
*/
public class GeometryCorrection {
public static String RIG_PREFIX = "rig-";
static double SCENE_UNITS_SCALE = 0.001;
static String SCENE_UNITS_NAME = "m";
static final String [] CORR_NAMES = {"tilt0","tilt1","tilt2","azimuth0","azimuth1","azimuth2","roll0","roll1","roll2","roll3","zoom0","zoom1","zoom2"};
......@@ -66,7 +69,7 @@ public class GeometryCorrection {
private double [][] rXY_ideal = {{-0.5, -0.5}, {0.5,-0.5}, {-0.5, 0.5}, {0.5,0.5}};
public double cameraRadius=0; // average distance from the "mass center" of the sensors to the sensors
public double disparityRadius=0; // distance between cameras to normalize disparity units to. sqrt(2)*disparityRadius for quad camera (~=150mm)?
public double disparityRadius=150.0; // distance between cameras to normalize disparity units to. sqrt(2)*disparityRadius for quad camera (~=150mm)?
private double [] rByRDist=null;
private double stepR=0.001;
......@@ -74,11 +77,29 @@ public class GeometryCorrection {
public CorrVector extrinsic_corr;
public RigOffset rigOffset = null;
public GeometryCorrection(double [] extrinsic_corr)
{
this.extrinsic_corr = new CorrVector(extrinsic_corr);
}
public boolean isInitialized() {
return roll != null;
}
public double [][] getRXY(boolean use_rig){
return (use_rig && (rigOffset != null)) ? rigOffset.rXY_aux: rXY ;
}
public Matrix getRotMatrix(boolean use_rig){
return (use_rig && (rigOffset != null)) ? rigOffset.getRotMatrix(): null ;
}
public double getDisparityRadius() {
return disparityRadius;
}
// correction of cameras mis-alignment
public CorrVector getCorrVector(double [] vector){
return new CorrVector(vector);
......@@ -124,7 +145,182 @@ public class GeometryCorrection {
manual_par_sel); // Manually select the parameter mask bit 0 - sym0, bit1 - sym1, ... (0 - use boolean flags, != 0 - ignore boolean flags)
}
/**
* Position of the auxiliary camera relative to the main one (uses main camera CS)
*/
public class RigOffset{
static final double ROT_AZ_SGN = -1.0; // sign of first sin for azimuth rotation
static final double ROT_TL_SGN = 1.0; // sign of first sin for tilt rotation
static final double ROT_RL_SGN = 1.0; // sign of first sin for roll rotation
public double baseline = 1256.0; // mm, distance between camera centers
public double aux_angle = 0.0; // radians, 0 - aux camera to the right of the main, pi/2 - up
// consider aux_z small enough for now, will need for SfM
public double aux_z = 0.0; // mm auxiliary camera distance from the plane of the main one (positive towards the scene)
public double aux_azimuth = 0.0; // radians, azimuth of the auxiliary camera (positive - looks to the right)
public double aux_tilt = 0.0; // radians, tilt of the auxiliary camera (positive - looks up)
public double aux_roll = 0.0; // radians, roll of the auxiliary camera (positive - looks clockwise)
public double aux_zoom = 0.0; // relative global zoom of the aux camera relative to the main one, difference from 1.0
public double [][] rXY_aux = null; // XY pairs of the in a normal plane, relative to disparityRadius
/*
private double [][] rXY = null; // XY pairs of the in a normal plane, relative to disparityRadius
private double [][] rXY_ideal = {{-0.5, -0.5}, {0.5,-0.5}, {-0.5, 0.5}, {0.5,0.5}};
*/
public RigOffset () {
System.out.println("created RigOffset");
}
public void recalcRXY() {
if (rXY != null) {
// rXY_aux = rXY; // FIXME: put real stuff !!!
double xc_pix = baseline * Math.cos(aux_angle)/getDisparityRadius();
double yc_pix = baseline * Math.sin(aux_angle)/getDisparityRadius();
rXY_aux = new double [rXY.length][2];
double ssr = 1.0;
for (int i = 0; i <rXY.length;i++) {
rXY_aux[i][0] = xc_pix + Math.cos(aux_roll)*rXY[i][0] + ssr*Math.sin(aux_roll)*rXY[i][1];
rXY_aux[i][1] = yc_pix - ssr*Math.sin(aux_roll)*rXY[i][0] + Math.cos(aux_roll)*rXY[i][1];
}
if (debugLevel > -2) {
System.out.println("Auxiliary camera offsets per 1 nominal disparity pixel");
for (int i = 0; i <rXY_aux.length;i++) {
System.out.println(String.format("Camera %1d x = %8f y = %8f",i,rXY_aux[i][0],rXY_aux[i][1]));
}
}
}
}
public Matrix getRotMatrix()
{
// Matrix [] rots = new Matrix [4];
// double [] azimuths = getAzimuths();
// double [] tilts = getTilts();
// double [] rolls = getFullRolls();
// double [] zooms = getZooms();
double ca = Math.cos(aux_azimuth);
double sa = Math.sin(aux_azimuth);
double ct = Math.cos(aux_tilt);
double st = Math.sin(aux_tilt);
double zoom = (1.0 + aux_zoom);
double cr = Math.cos(aux_roll) * zoom;
double sr = Math.sin(aux_roll) * zoom;
double [][] a_az = { // inverted - OK
{ ca, 0.0, sa * ROT_AZ_SGN },
{ 0.0, 1.0, 0.0},
{ -sa* ROT_AZ_SGN, 0.0, ca}};
double [][] a_t = { // inverted - OK
{ 1.0, 0.0, 0.0},
{ 0.0, ct, st * ROT_TL_SGN},
{ 0.0, -st * ROT_TL_SGN, ct}};
double [][] a_r = { // inverted OK
{ cr, sr * ROT_RL_SGN, 0.0},
{ -sr * ROT_RL_SGN, cr, 0.0},
{ 0.0, 0.0, 1.0}};
Matrix rot = (new Matrix(a_r).times(new Matrix(a_t).times(new Matrix(a_az))));
return rot;
}
public void setProperties(String parent_prefix,Properties properties){
String prefix = parent_prefix + RIG_PREFIX;
properties.setProperty(prefix+"baseline", this.baseline+"");
properties.setProperty(prefix+"aux_angle", this.aux_angle+"");
properties.setProperty(prefix+"aux_z", this.aux_z+"");
properties.setProperty(prefix+"aux_azimuth", this.aux_azimuth+"");
properties.setProperty(prefix+"aux_tilt", this.aux_tilt+"");
properties.setProperty(prefix+"aux_roll", this.aux_roll+"");
properties.setProperty(prefix+"aux_zoom", this.aux_zoom+"");
}
public boolean getProperties(String parent_prefix,Properties properties){
String prefix = parent_prefix + RIG_PREFIX;
boolean got_data = false;
if (properties.getProperty(prefix+"baseline")!=null) {this.baseline=Double.parseDouble(properties.getProperty(prefix+"baseline")); got_data=true;}
if (properties.getProperty(prefix+"aux_angle")!=null) {this.aux_angle=Double.parseDouble(properties.getProperty(prefix+"aux_angle"));got_data=true;}
if (properties.getProperty(prefix+"aux_z")!=null) {this.aux_z=Double.parseDouble(properties.getProperty(prefix+"aux_z"));got_data=true;}
if (properties.getProperty(prefix+"aux_azimuth")!=null) {this.aux_azimuth=Double.parseDouble(properties.getProperty(prefix+"aux_azimuth"));got_data=true;}
if (properties.getProperty(prefix+"aux_tilt")!=null) {this.aux_tilt=Double.parseDouble(properties.getProperty(prefix+"aux_tilt"));got_data=true;}
if (properties.getProperty(prefix+"aux_roll")!=null) {this.aux_roll=Double.parseDouble(properties.getProperty(prefix+"aux_roll"));got_data=true;}
if (properties.getProperty(prefix+"aux_zoom")!=null) {this.aux_zoom=Double.parseDouble(properties.getProperty(prefix+"aux_zoom"));got_data=true;}
recalcRXY();
return got_data;
}
// 9:%8.5f° 10: %8.5f‰
public boolean editOffsetsDegrees() {
GenericJTabbedDialog gd = new GenericJTabbedDialog("Set CLT parameters",800,900);
gd.addNumericField("Baseline", this.baseline, 1,6,"mm",
"Distance between quad camera centers");
gd.addNumericField("Angle to the aux camera from the main", 180.0/Math.PI*this.aux_angle, 4,9,"°",
"Directly to the right - 0°, directly up - 90°, ...");
gd.addNumericField("Auxilliary camera forward from the plane of the main one (not used)", this.aux_z, 3,6,"mm",
"Distance from the plane perpendicualr to the main camera axis to the auxiliary camera (positive for aux moved forward)");
gd.addNumericField("Auxilliary camera azimuth (positive - to the right)", 180.0/Math.PI*this.aux_azimuth, 3,6,"°",
"Relative to the main camera axis");
gd.addNumericField("Auxilliary camera tilt (positive - looking up)", 180.0/Math.PI*this.aux_tilt, 3,6,"°",
"Relative to the main camera");
gd.addNumericField("Auxilliary camera roll (positive - clockwise)", 180.0/Math.PI*this.aux_roll, 3,6,"°",
"Roll of a camera as a whole relative to the main camera");
gd.addNumericField("Relative zoom", 1000.0*this.aux_zoom, 3,6,"‰",
"Zoom ratio minus 1.0 multiplied by 1000.0");
gd.showDialog();
if (gd.wasCanceled()) return false;
this.baseline= gd.getNextNumber();
this.aux_angle= gd.getNextNumber() * Math.PI/180;
this.aux_z= gd.getNextNumber();
this.aux_azimuth= gd.getNextNumber() * Math.PI/180;
this.aux_tilt= gd.getNextNumber() * Math.PI/180;
this.aux_roll= gd.getNextNumber() * Math.PI/180;
this.aux_zoom= gd.getNextNumber()/1000.0;
recalcRXY();
return true;
}
public boolean editOffsetsPixels() {
GenericJTabbedDialog gd = new GenericJTabbedDialog("Set dual camera rig parameters (auxiliary camera relative to the main one)",800,300);
gd.addNumericField("Baseline", this.baseline, 1,6,"mm",
"Distance between quad camera centers");
gd.addNumericField("Angle to the aux camera from the main", 180.0/Math.PI*this.aux_angle, 4,9,"°",
"Directly to the right - 0°, directly up - 90°, ...");
gd.addNumericField("Auxilliary camera forward from the plane of the main one (not used)", this.aux_z, 3,6,"mm",
"Distance from the plane perpendicualr to the main camera axis to the auxiliary camera (positive for aux moved forward)");
gd.addNumericField("Auxilliary camera azimuth (positive - to the right)", 1000.0*focalLength/pixelSize * this.aux_azimuth, 3,6,"pix",
"Relative to the main camera axis, shift of the center of the image in pixels");
gd.addNumericField("Auxilliary camera tilt (positive - looking up)", 1000.0*focalLength/pixelSize * this.aux_tilt, 3,6,"pix",
"Relative to the main camera, shift of the center of the image in pixels");
gd.addNumericField("Auxilliary camera roll (positive - clockwise)", 1000.0*distortionRadius/pixelSize * this.aux_roll, 3,6,"pix",
"Roll of a camera as a whole relative to the main camera, shift at the image half-width from the center");
gd.addNumericField("Relative zoom - difference from 1.0 in parts parts per 1/1000", 1000.0*distortionRadius/pixelSize * this.aux_zoom, 3,6,"pix",
"Zoom ratio, shift at the image half-width from the center");
gd.showDialog();
if (gd.wasCanceled()) return false;
this.baseline= gd.getNextNumber();
this.aux_angle= gd.getNextNumber() * Math.PI/180;
this.aux_z= gd.getNextNumber();
this.aux_azimuth= gd.getNextNumber()/(1000.0*focalLength/pixelSize) ;
this.aux_tilt= gd.getNextNumber()/(1000.0*focalLength/pixelSize);
this.aux_roll= gd.getNextNumber()/(1000.0*distortionRadius/pixelSize);
this.aux_zoom= gd.getNextNumber()/(1000.0*distortionRadius/pixelSize);
recalcRXY();
return true;
}
}
public boolean editRig() {
if (this.rigOffset == null) {
this.rigOffset = new RigOffset();
}
return this.rigOffset.editOffsetsPixels();
}
public boolean setRigOffsetFromProperies(String parent_prefix,Properties properties) {
RigOffset rigOffset = new RigOffset();
boolean gotit = rigOffset.getProperties(parent_prefix, properties);
if (gotit) {
this.rigOffset = rigOffset;
}
return gotit;
}
public class CorrVector{
......@@ -139,6 +335,16 @@ public class GeometryCorrection {
static final double ROT_RL_SGN = 1.0; // sign of first sin for roll rotation
double [] vector;
public Matrix [] getRotMatrices(Matrix rigMatrix)
{
Matrix [] rots = getRotMatrices();
if (rigMatrix != null) {
for (int chn = 0; chn < rots.length; chn++) {
rots[chn] = rigMatrix.times(rots[chn]);
}
}
return rots;
}
public Matrix [] getRotMatrices()
{
Matrix [] rots = new Matrix [4];
......@@ -389,8 +595,8 @@ public class GeometryCorrection {
s = String.format("tilt (up): %8.5fpx %8.5fpx %8.5fpx %8.5fpx (shift of he image center)\n" , v[0], v[1], v[2], -(v[0] + v[1] + v[2]) );
s += String.format("azimuth (right): %8.5fpx %8.5fpx %8.5fpx %8.5fpx (shift of he image center)\n" , v[3], v[4], v[5], -(v[3] + v[4] + v[5]) );
s += String.format("roll (CW): %8.5fpx %8.5fpx %8.5fpx %8.5fpx (shift at the imge half-width from the center)\n" , v[6], v[7], v[8], v[9] );
s += String.format("diff zoom (in): %8.5fpx %8.5fpx %8.5fpx %8.5fpx (shift at the imge half-width from the center)\n" , v[10], v[11], v[12], -(v[10] + v[11] + v[12]) );
s += String.format("roll (CW): %8.5fpx %8.5fpx %8.5fpx %8.5fpx (shift at the image half-width from the center)\n" , v[6], v[7], v[8], v[9] );
s += String.format("diff zoom (in): %8.5fpx %8.5fpx %8.5fpx %8.5fpx (shift at the image half-width from the center)\n" , v[10], v[11], v[12], -(v[10] + v[11] + v[12]) );
s += "Symmetrical vector:\n";
s += " |↘ ↙| |↘ ↗| |↗ ↘| |↙ ↘| |↙ ↗| |↖ ↘| 6: common roll 7:(r0-r3)/2, |- +| |- -| |- +|\n";
s += " 0: |↗ ↖| 1: |↙ ↖| 2: |↖ ↙| 3: |↖ ↗| 4: |↗ ↙| 5: |↘ ↖| 8:(r1-r2)/2 9:(r0+r3-r1-r2)/4 10: |- +| 11: |+ +| 12: |+ -|\n";
......@@ -859,6 +1065,9 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
for (int j = 0; j<3;j++) this.XYZ_her[i][j] = mXYZ_her.get(j, 0);
for (int j = 0; j<2;j++) this.rXY[i][j] = this.XYZ_her[i][j]/this.disparityRadius;
}
if (rigOffset != null) {
rigOffset.recalcRXY();
}
}
public void listGeometryCorrection(boolean showAll){
......@@ -1217,6 +1426,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
/**
* Calculate pixel coordinates for each of numSensors images, for a given (px,py) of the idealized "center" (still distorted) image
* and generic disparity, measured in pixels
* @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 px pixel X coordinate
......@@ -1226,6 +1436,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
*/
public double [][] getPortsCoordinatesAndDerivatives(
boolean use_rig_offsets,
Matrix [] rots,
Matrix [][] deriv_rots,
double [][] pXYderiv, // if not null, should be double[8][]
......@@ -1241,6 +1452,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
* 4) re-apply distortion
* 5) return port center X and Y
*/
double [][] rXY = getRXY(use_rig_offsets); // may include rig offsets
double [][] pXY = new double [numSensors][2];
......@@ -1256,8 +1468,8 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
for (int i = 0; i < numSensors; i++){
// non-distorted XY of the shifted location of the individual sensor
double pXci0 = pXc - disparity * this.rXY[i][0]; // in pixels
double pYci0 = pYc - disparity * this.rXY[i][1];
double pXci0 = pXc - disparity * rXY[i][0]; // in pixels
double pYci0 = pYc - disparity * rXY[i][1];
// Convert a 2-d non-distorted vector to 3d at fl_pix distance in z direction
double [][] avi = {{pXci0}, {pYci0},{fl_pix}};
......@@ -1373,6 +1585,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
public double [][] getPortsCoordinatesAndDerivatives( // uses rotations - used in AlignmentCorrection class
boolean use_rig_offsets,
double [] dbg_a_vector, // replace actual radial distortion coefficients (not currently used)
double delta, // 1e-6
CorrVector corr_vector,
......@@ -1384,6 +1597,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
// slower, will re-calculate matrices for each tile, but for debug - that is OK
Matrix [] corr_rots = corr_vector.getRotMatrices(); // get array of per-sensor rotation matrices
double [][] rslt = getPortsCoordinatesAndDerivatives(
use_rig_offsets,
corr_rots, // Matrix [] rots,
null, // deriv_rots, // Matrix [][] deriv_rots,
null, // pXYderiv0, // null, // false, // boolean calc_deriv,
......@@ -1404,6 +1618,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
Matrix [] corr_rots_m = cv_delta_m.getRotMatrices(); // get array of per-sensor rotation matrices
double [][] rslt_p = getPortsCoordinatesAndDerivatives(
use_rig_offsets,
corr_rots_p, // Matrix [] rots,
null, // Matrix [][] deriv_rots,
null, // boolean calc_deriv,
......@@ -1412,6 +1627,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
disparity // double disparity
);
double [][] rslt_m = getPortsCoordinatesAndDerivatives(
use_rig_offsets,
corr_rots_m, // Matrix [] rots,
null, // Matrix [][] deriv_rots,
null, // boolean calc_deriv,
......
......@@ -971,6 +971,7 @@ public class ImageDtt {
// centerY,
// disparity);
double [][] centersXY = geometryCorrection.getPortsCoordinatesAndDerivatives(
false, // boolean use_rig_offsets,
corr_rots, // Matrix [] rots,
null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][]
......@@ -1689,8 +1690,8 @@ public class ImageDtt {
double [][] tcorr_combo = null; // [15*15] pixel space
double [][][] tcorr_partial = null; // [quad][numcol+1][15*15]
double [][][][] tcorr_tpartial = null; // [quad][numcol+1][4][8*8]
PolynomialApproximation pa = null;
if (corr_max_weights_poly !=null) pa = new PolynomialApproximation(0); // debug level
// PolynomialApproximation pa = null;
// if (corr_max_weights_poly !=null) pa = new PolynomialApproximation(0); // debug level
Correlation2d corr2d = new Correlation2d(
imgdtt_params, // ImageDttParameters imgdtt_params,
transform_size, // int transform_size,
......@@ -1738,6 +1739,7 @@ public class ImageDtt {
} else {
centersXY = geometryCorrection.getPortsCoordinatesAndDerivatives(
false, // boolean use_rig_offsets,
corr_rots, // Matrix [] rots,
null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][]
......@@ -5956,6 +5958,7 @@ public class ImageDtt {
} else {
centersXY = geometryCorrection.getPortsCoordinatesAndDerivatives(
false, // boolean use_rig_offsets,
corr_rots, // Matrix [] rots,
null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][]
......@@ -7205,14 +7208,35 @@ public class ImageDtt {
dir_corr_strength[0][0],dir_corr_strength[0][1],dir_corr_strength[1][0],dir_corr_strength[1][1],
dir_corr_strength[2][0],dir_corr_strength[2][1],dir_corr_strength[3][0],dir_corr_strength[3][1]));
}
result[DISP_HOR_INDEX] = dir_corr_strength[0][0];
result[STR_HOR_INDEX] = dir_corr_strength[0][1];
result[DISP_VERT_INDEX] = dir_corr_strength[1][0];
result[STR_VERT_INDEX] = dir_corr_strength[1][1];
result[DISP_DIAGM_INDEX] = dir_corr_strength[2][0];
result[STR_DIAGM_INDEX] = dir_corr_strength[2][1];
result[DISP_DIAGM_INDEX] = dir_corr_strength[3][0];
result[STR_DIAGO_INDEX] = dir_corr_strength[3][1];
if (dir_corr_strength[0] != null) {
result[DISP_HOR_INDEX] = dir_corr_strength[0][0];
result[STR_HOR_INDEX] = dir_corr_strength[0][1];
} else {
result[DISP_HOR_INDEX] = Double.NaN;
result[STR_HOR_INDEX] = 0.0;
}
if (dir_corr_strength[1] != null) {
result[DISP_VERT_INDEX] = dir_corr_strength[1][0];
result[STR_VERT_INDEX] = dir_corr_strength[1][1];
} else {
result[DISP_VERT_INDEX] = Double.NaN;
result[STR_VERT_INDEX] = 0.0;
}
if (dir_corr_strength[2] != null) {
result[DISP_DIAGM_INDEX] = dir_corr_strength[2][0];
result[STR_DIAGM_INDEX] = dir_corr_strength[2][1];
} else {
result[DISP_DIAGM_INDEX] = Double.NaN;
result[STR_DIAGM_INDEX] = 0.0;
}
if (dir_corr_strength[3] != null) {
result[DISP_DIAGO_INDEX] = dir_corr_strength[3][0];
result[STR_DIAGO_INDEX] = dir_corr_strength[3][1];
} else {
result[DISP_DIAGO_INDEX] = Double.NaN;
result[STR_DIAGO_INDEX] = 0.0;
}
mod_disparity_diff = corr2d.foregroundCorrect(
clt_parameters.img_dtt.fo_far, // boolean bg,
......@@ -7385,8 +7409,6 @@ public class ImageDtt {
public double [][][][][][][] clt_bi_quad(
final EyesisCorrectionParameters.CLTParameters clt_parameters,
// final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
// final int macro_scale, // to correlate tile data instead of the pixel data: 1 - pixels, 8 - tiles
final int [][] tile_op_main, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
final int [][] tile_op_aux, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
final double [][] disparity_array, // [tilesY][tilesX] - individual per-tile expected disparity
......@@ -7419,7 +7441,7 @@ public class ImageDtt {
final int debug_tileX = clt_parameters.tileX;
final int debug_tileY = clt_parameters.tileY;
// final boolean debug_ports_coordinates = (debug_tileX == -1234);
final double poly_corr = clt_parameters.img_dtt.poly_corr_scale; // maybe add per-tile task bits to select none/near/far
// final double poly_corr = clt_parameters.img_dtt.poly_corr_scale; // maybe add per-tile task bits to select none/near/far
final int quad_main = image_data_main.length; // number of subcameras
final int quad_aux = image_data_aux.length; // number of subcameras
final int numcol = 3; // number of colors
......@@ -7474,11 +7496,13 @@ public class ImageDtt {
System.out.println("clt_aberrations_quad_corr(): width="+width+" height="+height+" transform_size="+clt_parameters.transform_size+
" debug_tileX="+debug_tileX+" debug_tileY="+debug_tileY+" globalDebugLevel="+globalDebugLevel);
}
/*
final int [][] zi =
{{ 0, 1, 2, 3},
{-1, 0, -3, 2},
{-2, -3, 0, 1},
{ 3, -2, -1, 0}};
*/
final int [][] corr_pairs ={ // {first, second, rot} rot: 0 - as is, 1 - swap y,x
{0,1,0},
{2,3,0},
......@@ -7543,8 +7567,8 @@ public class ImageDtt {
}
}
final double [] corr_max_weights_poly =(((clt_parameters.max_corr_sigma > 0) && (disparity_bimap != null))?
setMaxXYWeights(clt_parameters.max_corr_sigma,max_search_radius_poly): null); // here use square anyway
// final double [] corr_max_weights_poly =(((clt_parameters.max_corr_sigma > 0) && (disparity_bimap != null))?
// setMaxXYWeights(clt_parameters.max_corr_sigma,max_search_radius_poly): null); // here use square anyway
dtt.set_window(clt_parameters.clt_window);
final double [] lt_window = dtt.getWin2d(); // [256]
......@@ -7558,7 +7582,9 @@ public class ImageDtt {
}
final Matrix [] corr_rots_main = geometryCorrection_main.getCorrVector().getRotMatrices(); // get array of per-sensor rotation matrices
final Matrix [] corr_rots_aux = geometryCorrection_aux.getCorrVector().getRotMatrices(); // get array of per-sensor rotation matrices
final Matrix rigMatrix = geometryCorrection_aux.getRotMatrix(true);
final Matrix [] corr_rots_aux = geometryCorrection_aux.getCorrVector().getRotMatrices(rigMatrix); // get array of per-sensor rotation matrices
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
......@@ -7572,14 +7598,14 @@ public class ImageDtt {
double [][] fract_shiftsXY_main = new double[quad_main][];
double [][] fract_shiftsXY_aux = new double[quad_aux][];
double [][] tcorr_combo = null; // [15*15] pixel space
double [][][] tcorr_partial = null; // [quad][numcol+1][15*15]
double [][][][] tcorr_tpartial = null; // [quad][numcol+1][4][8*8]
// double [][][] tcorr_partial = null; // [quad][numcol+1][15*15]
// double [][][][] tcorr_tpartial = null; // [quad][numcol+1][4][8*8]
double [][][][] clt_data_main = new double[quad_main][nChn][][];
double [][][][] clt_data_aux = new double[quad_aux][nChn][][];
PolynomialApproximation pa = null;
if (corr_max_weights_poly !=null) pa = new PolynomialApproximation(0); // debug level
// PolynomialApproximation pa = null;
// if (corr_max_weights_poly !=null) pa = new PolynomialApproximation(0); // debug level
Correlation2d corr2d = new Correlation2d(
clt_parameters.img_dtt, // ImageDttParameters imgdtt_params,
clt_parameters.transform_size, // int transform_size,
......@@ -7608,7 +7634,7 @@ public class ImageDtt {
corr_mask_aux &= ~ (1 << i);
}
}
boolean debugTile =(tileX == debug_tileX) && (tileY == debug_tileY);
// boolean debugTile =(tileX == debug_tileX) && (tileY == debug_tileY);
final int [] overexp_main = (saturation_main != null) ? ( new int [2]): null;
final int [] overexp_aux = (saturation_aux != null) ? ( new int [2]): null;
......@@ -7619,21 +7645,25 @@ public class ImageDtt {
// TODO: move port coordinates out of color channel loop
double [][] centersXY_main;
double [][] centersXY_aux;
double disparity_main = disparity_array[tileY][tileX];
double disparity_aux = disparity_main * geometryCorrection_aux.getDisparityRadius()/geometryCorrection_main.getDisparityRadius();
centersXY_main = geometryCorrection_main.getPortsCoordinatesAndDerivatives(
false, // boolean use_rig_offsets,
corr_rots_main, // Matrix [] rots,
null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][]
null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][]
centerX,
centerY,
disparity_array[tileY][tileX]); // + disparity_corr);
disparity_main); // + disparity_corr);
centersXY_aux = geometryCorrection_aux.getPortsCoordinatesAndDerivatives(
corr_rots_aux, // Matrix [] rots,
null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][]
true, // boolean use_rig_offsets,
corr_rots_aux, // Matrix [] rots,
null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][]
centerX,
centerY,
disparity_array[tileY][tileX]); // + disparity_corr);
disparity_aux); // + disparity_corr);
if ((globalDebugLevel > 0) && (tileX == debug_tileX) && (tileY == debug_tileY)) {
for (int i = 0; i < quad_main; i++) {
......
......@@ -67,6 +67,7 @@ public class QuadCLT {
String image_name = null;
double [][][] image_data = null;
boolean [][] saturation_imp = null; // (near) saturated pixels or null
boolean is_aux = false;
// magic scale should be set before using TileProcessor (calculated disparities depend on it)
......@@ -96,6 +97,7 @@ public class QuadCLT {
this.eyesisCorrections= eyesisCorrections;
this.correctionsParameters = correctionsParameters;
this.properties = properties;
is_aux = prefix.equals(PREFIX_AUX);
// this.properties_prefix = prefix;
// System.out.println("new QuadCLT(), prefix = "+prefix);
getProperties(prefix);
......@@ -125,6 +127,9 @@ public class QuadCLT {
properties.setProperty(name, gc.getCorrVector().toArray()[i]+"");
// System.out.println("setProperties():"+i+": setProperty("+name+","+gc.getCorrVector().toArray()[i]+"");
}
if (is_aux && (gc.rigOffset != null)) {
gc.rigOffset.setProperties(prefix,properties);
}
}
......@@ -197,8 +202,17 @@ public class QuadCLT {
}
}
}
}
// if (is_aux && (geometryCorrection != null)) {
// geometryCorrection.setRigOffsetFromProperies(prefix, properties);
// }
if (geometryCorrection == null) {
geometryCorrection = new GeometryCorrection(this.extrinsic_corr);
}
if (is_aux) {
geometryCorrection.setRigOffsetFromProperies(prefix, properties);
}
}
public void setKernelImageFile(ImagePlus img_kernels){
eyesisKernelImage = img_kernels;
......@@ -212,10 +226,13 @@ public class QuadCLT {
return clt_kernels != null;
}
public boolean geometryCorrectionAvailable(){
return geometryCorrection != null;
return (geometryCorrection != null) && geometryCorrection.isInitialized();
}
public boolean initGeometryCorrection(int debugLevel){
geometryCorrection = new GeometryCorrection(extrinsic_corr);
// keep rig offsets if edited
if (geometryCorrection == null) {
geometryCorrection = new GeometryCorrection(extrinsic_corr);
}
PixelMapping.SensorData [] sensors = eyesisCorrections.pixelMapping.sensors;
// verify that all sensors have the same distortion parameters
int numSensors = sensors.length;
......@@ -4527,6 +4544,32 @@ public class QuadCLT {
System.out.println(geometryCorrection.getCorrVector().toString());
}
}
public boolean editRig()
{
if (!is_aux) {
System.out.println("Rig offsets can only be edited for the auxiliary camera, not for the amin one");
return false;
}
// GeometryCorrection gc = this.geometryCorrection;
if (this.geometryCorrection == null){
System.out.println("geometryCorrection is not set, creating one");
this.geometryCorrection = new GeometryCorrection(this.extrinsic_corr);
}
boolean edited = this.geometryCorrection.editRig();
// if (edited) {
// gc.rigOffset.setProperties(prefix,properties);
// }
return edited;
}
/*
if (is_aux && (gc.rigOffset != null)) {
gc.rigOffset.setProperties(prefix,properties);
}
*/
public void resetExtrinsicCorr(
EyesisCorrectionParameters.CLTParameters clt_parameters)
{
......
......@@ -381,7 +381,7 @@ public class TwoQuadCLT {
quadCLT_main.getGeometryCorrection(), // final GeometryCorrection geometryCorrection_main,
quadCLT_aux.getGeometryCorrection(), // final GeometryCorrection geometryCorrection_aux,
quadCLT_main.getCLTKernels(), // final double [][][][][][] clt_kernels_main, // [channel_in_quad][color][tileY][tileX][band][pixel] , size should match image (have 1 tile around)
quadCLT_main.getCLTKernels(), // final double [][][][][][] clt_kernels_aux, // [channel_in_quad][color][tileY][tileX][band][pixel] , size should match image (have 1 tile around)
quadCLT_aux.getCLTKernels(), // final double [][][][][][] clt_kernels_aux, // [channel_in_quad][color][tileY][tileX][band][pixel] , size should match image (have 1 tile around)
clt_parameters.corr_magic_scale, // final double corr_magic_scale, // still not understood coefficient that reduces reported disparity value. Seems to be around 0.85
true, // final boolean keep_clt_data,
threadsMax, // final int threadsMax, // maximal number of threads to launch
......@@ -496,7 +496,7 @@ public class TwoQuadCLT {
colorProcParameters,
rgbParameters,
name+"-texture", // String name,
"-D"+clt_parameters.disparity, //String suffix, // such as disparity=...
"-D"+clt_parameters.disparity+"-MAIN", //String suffix, // such as disparity=...
toRGB,
!quadCLT_main.correctionsParameters.jpeg, // boolean bpp16, // 16-bit per channel color mode for result
true, // boolean saveShowIntermediate, // save/show if set globally
......@@ -511,7 +511,7 @@ public class TwoQuadCLT {
colorProcParameters,
rgbParameters,
name+"-texture", // String name,
"-D"+clt_parameters.disparity, //String suffix, // such as disparity=...
"-D"+clt_parameters.disparity+"-AUX", //String suffix, // such as disparity=...
toRGB,
!quadCLT_aux.correctionsParameters.jpeg, // boolean bpp16, // 16-bit per channel color mode for result
true, // boolean saveShowIntermediate, // save/show if set globally
......
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