Commit f2095295 authored by Andrey Filippov's avatar Andrey Filippov

Refactoring, extracting methods from buildSeries

parent 93ac2c14
......@@ -44,6 +44,7 @@ import com.elphel.imagej.tileprocessor.ImageDtt;
import com.elphel.imagej.tileprocessor.ImageDttParameters;
import com.elphel.imagej.tileprocessor.IntersceneLmaParameters;
import com.elphel.imagej.tileprocessor.IntersceneMatchParameters;
import com.elphel.imagej.tileprocessor.LWIRWorldParameters;
import com.elphel.imagej.tileprocessor.MeasuredLayersFilterParameters;
import com.elphel.imagej.tileprocessor.OpticalFlowParameters;
import com.elphel.imagej.tileprocessor.PoleProcessorParameters;
......@@ -372,7 +373,8 @@ public class CLTParameters {
// to the next sequence and saved with corr-xml configuration. It is always
// propagated when calibration is run manually with photo_en = true
public int photo_num_full = 3; // Number of full recalibrations with re-processing of the images
public int photo_num_refines = 3; // Calibrate, remove outliers, recalibrate, ...
public int photo_num_refines = 3; // Calibrate, remove outliers, recalibrate, ...
public int photo_min_good = 1000; // Minimal number of good pixels for photometric calibration
public double photo_min_strength = 0.0; // maybe add to filter out weak tiles
public double photo_max_diff = 40.0; // To filter mismatches. Normal (adjusted) have RMSE ~9
public int photo_order = 2; // Approximation order: 0 - just offset, 1 - linear, 2 - quadratic
......@@ -1016,6 +1018,7 @@ public class CLTParameters {
public IntersceneMatchParameters imp = new IntersceneMatchParameters();
public IntersceneLmaParameters ilp = new IntersceneLmaParameters();
public InterNoiseParameters inp = new InterNoiseParameters();
public LWIRWorldParameters lwp = new LWIRWorldParameters();
public HashMap<String,Double> z_corr_map = new HashMap<String,Double>(); //old one
public HashMap<String,Double> infinity_distace_map = new HashMap<String,Double>(); //new one
......@@ -1395,6 +1398,7 @@ public class CLTParameters {
properties.setProperty(prefix+"photo_to_main", this.photo_to_main+""); // boolean
properties.setProperty(prefix+"photo_num_full", this.photo_num_full+""); // int
properties.setProperty(prefix+"photo_num_refines", this.photo_num_refines+""); // int
properties.setProperty(prefix+"photo_min_good", this.photo_min_good+""); // int
properties.setProperty(prefix+"photo_min_strength", this.photo_min_strength+""); // double
properties.setProperty(prefix+"photo_max_diff", this.photo_max_diff+""); // double
properties.setProperty(prefix+"photo_order", this.photo_order+""); // int
......@@ -1999,6 +2003,7 @@ public class CLTParameters {
imp.setProperties (prefix+"_imp_", properties);
ilp.setProperties (prefix+"_ilp_", properties);
inp.setProperties (prefix+"_inp_", properties);
lwp.setProperties (prefix+"_lwp_", properties);
}
......@@ -2295,6 +2300,8 @@ public class CLTParameters {
if (properties.getProperty(prefix+"photo_to_main")!=null) this.photo_to_main=Boolean.parseBoolean(properties.getProperty(prefix+"photo_to_main"));
if (properties.getProperty(prefix+"photo_num_full")!=null) this.photo_num_full=Integer.parseInt(properties.getProperty(prefix+"photo_num_full"));
if (properties.getProperty(prefix+"photo_num_refines")!=null) this.photo_num_refines=Integer.parseInt(properties.getProperty(prefix+"photo_num_refines"));
if (properties.getProperty(prefix+"photo_min_good")!=null) this.photo_min_good=Integer.parseInt(properties.getProperty(prefix+"photo_min_good"));
if (properties.getProperty(prefix+"photo_min_strength")!=null) this.photo_min_strength=Double.parseDouble(properties.getProperty(prefix+"photo_min_strength"));
if (properties.getProperty(prefix+"photo_max_diff")!=null) this.photo_max_diff=Double.parseDouble(properties.getProperty(prefix+"photo_max_diff"));
if (properties.getProperty(prefix+"photo_order")!=null) this.photo_order=Integer.parseInt(properties.getProperty(prefix+"photo_order"));
......@@ -2915,6 +2922,7 @@ public class CLTParameters {
imp.getProperties (prefix+"_imp_", properties);
ilp.getProperties (prefix+"_ilp_", properties);
inp.getProperties (prefix+"_inp_", properties);
lwp.getProperties (prefix+"_lwp_", properties);
}
public boolean showJDialog() {
......@@ -3337,6 +3345,9 @@ public class CLTParameters {
"Full recalibratrions include re-importing raw images with updated offsets/gains");
gd.addNumericField("Refines", this.photo_num_refines, 0,3,"",
"Calculate calibration, remove outliers (e.g. FG/BG) and repeat");
gd.addNumericField("Minimal number of good pixels", this.photo_min_good, 0,3,"",
"Minimal number of good pixels for photomeric calibration.");
gd.addNumericField("Minimal DSI strength", this.photo_min_strength, 5,7,"",
"Do not use weak tiles.");
gd.addNumericField("Maximal channel mismatch", this.photo_max_diff, 5,7,"",
......@@ -4090,6 +4101,8 @@ public class CLTParameters {
this.ofp.dialogQuestions(gd);
this.imp.dialogQuestions(gd);
this.lwp.dialogQuestions(gd);
gd.addTab ("Inter-LMA", "parameters for the interscene LMA fitting");
this.ilp.dialogQuestions(gd);
......@@ -4423,6 +4436,7 @@ public class CLTParameters {
this.photo_to_main = gd.getNextBoolean();
this.photo_num_full = (int) gd.getNextNumber();
this.photo_num_refines = (int) gd.getNextNumber();
this.photo_min_good = (int) gd.getNextNumber();
this.photo_min_strength = gd.getNextNumber();
this.photo_max_diff = gd.getNextNumber();
this.photo_order = (int) gd.getNextNumber();
......@@ -4982,6 +4996,7 @@ public class CLTParameters {
this.lwir.dialogAnswers(gd);
this.ofp.dialogAnswers(gd);
this.imp.dialogAnswers(gd);
this.lwp.dialogAnswers(gd);
this.ilp.dialogAnswers(gd);
this.inp.dialogAnswers(gd);
......
......@@ -104,6 +104,7 @@ import com.elphel.imagej.tileprocessor.MultisceneLY;
import com.elphel.imagej.tileprocessor.QuadCLT;
import com.elphel.imagej.tileprocessor.SymmVector;
import com.elphel.imagej.tileprocessor.TwoQuadCLT;
import com.elphel.imagej.tileprocessor.lwoc.LwirWorld;
import ij.CompositeImage;
import ij.IJ;
......@@ -142,7 +143,7 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
// private static final long serialVersionUID = -1507307664341265263L;
private Panel panel1, panel2, panel3, panel4, panel5, panel5a, panel6, panel7, panelPostProcessing1,
panelPostProcessing2, panelPostProcessing3, panelDct1, panelClt1, panelClt2, panelClt3, panelClt4,
panelClt5, panelClt5aux, panelClt_GPU, panelLWIR, panelLWIR16;
panelClt5, panelClt5aux, panelClt_GPU, panelLWIR, panelLWIR16, panelLWIRWorld;
JP46_Reader_camera JP4_INSTANCE = null;
// private deBayerScissors debayer_instance;
......@@ -507,7 +508,7 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
plugInFrame.addKeyListener(IJ.getInstance());
// int menuRows=4 + (ADVANCED_MODE?4:0) + (MODE_3D?3:0) + (DCT_MODE?6:0) + (GPU_MODE?1:0) +(LWIR_MODE?2:0);
int menuRows = 4 + (ADVANCED_MODE ? 4 : 0) + (MODE_3D ? 3 : 0) + (DCT_MODE ? 7 : 0) + (GPU_MODE ? 1 : 0)
+ (LWIR_MODE ? 2 : 0);
+ (LWIR_MODE ? 3 : 0);
plugInFrame.setLayout(new GridLayout(menuRows, 1));
panel6 = new Panel();
panel6.setLayout(new GridLayout(1, 0, 5, 5));
......@@ -811,9 +812,14 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
addButton("Illustrations Configure", panelLWIR16, color_conf_process);
addButton("Footage Organize", panelLWIR16, color_conf_process);
addButton("Super batch", panelLWIR16, color_process);
plugInFrame.add(panelLWIR16);
panelLWIRWorld = new Panel();
panelLWIRWorld.setLayout(new GridLayout(1, 0, 5, 5)); // rows, columns, vgap, hgap
addButton("Aux Build Series", panelLWIRWorld, color_stop);
addButton("Build World", panelLWIRWorld, color_process);
plugInFrame.add(panelLWIRWorld);
}
plugInFrame.pack();
//"LWIR batch"
......@@ -5491,6 +5497,14 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
}
}
(new JP46_Reader_camera(false)).encodeProperiesToInfo(imp_sel);
return;
} else if (label.equals("Build World")) {
DEBUG_LEVEL = MASTER_DEBUG_LEVEL;
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
CLT_PARAMETERS.batch_run = true;
buildLWIRWorld(true);
return;
//JTabbedTest
// End of buttons code
}
......@@ -6787,7 +6801,100 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
return true;
}
public boolean buildLWIRWorld(boolean use_aux) {
long startTime = System.nanoTime();
// load needed sensor and kernels files
if (!prepareRigImages())
return false;
String configPath = getSaveCongigPath();
if (configPath.equals("ABORT"))
return false;
setAllProperties(PROPERTIES); // batchRig may save properties with the model. Extrinsics will be updated,
// others should be set here
if (DEBUG_LEVEL > -2) {
System.out.println("++++++++++++++ Building series from scratch ++++++++++++++");
}
if (CLT_PARAMETERS.useGPU()) { // only init GPU instances if it is used
if (GPU_TILE_PROCESSOR == null) {
try {
GPU_TILE_PROCESSOR = new GPUTileProcessor(CORRECTION_PARAMETERS.tile_processor_gpu);
} catch (Exception e) {
System.out.println("Failed to initialize GPU class");
// TODO Auto-generated catch block
e.printStackTrace();
return false;
} // final int debugLevel);
}
if (use_aux) {
if (CLT_PARAMETERS.useGPU(true) && (QUAD_CLT_AUX != null) && (GPU_QUAD_AUX == null)) { // if GPU AUX is
// needed
try {
GPU_QUAD_AUX = new GpuQuad(//
GPU_TILE_PROCESSOR, QUAD_CLT_AUX, CLT_PARAMETERS.gpu_debug_level);
} catch (Exception e) {
System.out.println("Failed to initialize GpuQuad class");
// TODO Auto-generated catch block
e.printStackTrace();
return false;
} // final int debugLevel);
QUAD_CLT_AUX.setGPU(GPU_QUAD_AUX);
}
} else {
if (CLT_PARAMETERS.useGPU(false) && (QUAD_CLT != null) && (GPU_QUAD == null)) { // if GPU main is needed
try {
GPU_QUAD = new GpuQuad(GPU_TILE_PROCESSOR, QUAD_CLT, CLT_PARAMETERS.gpu_debug_level);
} catch (Exception e) {
System.out.println("Failed to initialize GpuQuad class");
// TODO Auto-generated catch block
e.printStackTrace();
return false;
} // final int debugLevel);
QUAD_CLT.setGPU(GPU_QUAD);
}
}
}
QuadCLT quadCLT = use_aux ? QUAD_CLT_AUX : QUAD_CLT;
ColorProcParameters colorProcParameters = use_aux ? COLOR_PROC_PARAMETERS_AUX : COLOR_PROC_PARAMETERS;
CLT_PARAMETERS.setColorProcParameters(COLOR_PROC_PARAMETERS, false);
CLT_PARAMETERS.setColorProcParameters(COLOR_PROC_PARAMETERS_AUX, true);
CLT_PARAMETERS.setRGBParameters(RGB_PARAMETERS);
try {
LwirWorld.buildWorld(
quadCLT, // QUAD_CLT, // QuadCLT quadCLT_main,
-1, // int ref_index,
0, // int ref_step,
// QUAD_CLT_AUX, // QuadCLT quadCLT_aux,
CLT_PARAMETERS, // EyesisCorrectionParameters.DCTParameters dct_parameters,
DEBAYER_PARAMETERS, // EyesisCorrectionParameters.DebayerParameters debayerParameters,
colorProcParameters, // COLOR_PROC_PARAMETERS, //EyesisCorrectionParameters.ColorProcParameters
// colorProcParameters,
CHANNEL_GAINS_PARAMETERS, // CorrectionColorProc.ColorGainsParameters channelGainParameters,
RGB_PARAMETERS, // EyesisCorrectionParameters.RGBParameters rgbParameters,
EQUIRECTANGULAR_PARAMETERS, // EyesisCorrectionParameters.EquirectangularParameters
// equirectangularParameters,
PROPERTIES, // Properties properties,
true, // false, // boolean reset_from_extrinsics,
THREADS_MAX, // final int threadsMax, // maximal number of threads to launch
UPDATE_STATUS, // final boolean updateStatus,
DEBUG_LEVEL);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} // final int debugLevel);
saveTimestampedProperties( // save config again
configPath, // full path or null
null, // use as default directory if path==null
true, PROPERTIES);
System.out.println("buildLWIRWorld(): Processing finished at "
+ IJ.d2s(0.000000001 * (System.nanoTime() - startTime), 3) + " sec, --- Free memory="
+ Runtime.getRuntime().freeMemory() + " (of " + Runtime.getRuntime().totalMemory() + ")");
return true;
}
public boolean testInterLMA(boolean use_aux) {
long startTime = System.nanoTime();
// load needed sensor and kernels files
......
......@@ -356,7 +356,7 @@ public class ErsCorrection extends GeometryCorrection {
//propertyNames()
public double [] parseDoublesCSV(String s) {
public static double [] parseDoublesCSV(String s) {
String[] snumbers = s.split(",");
double [] data = new double [snumbers.length];
for (int i = 0; i < data.length; i++) {
......@@ -440,163 +440,6 @@ public class ErsCorrection extends GeometryCorrection {
/**
* Position+orientation (world XYZ, Azimuth, Tilt, Roll) of other scenes relative to the position of this camera.
* Positions/orientations are sampled during scanning of the center line
*/
public class XyzAtr {
double [] xyz;
double [] atr;
double [] ers_xyz_dt; // world camera Vx, Vy, Vz (m/s)
double [] ers_atr_dt; // camera rotaions (az, tilt, roll in radians/s, corresponding to the frame center)
double [] ers_atr_d2t; // camera rotaions (az, tilt, roll in radians/s, corresponding to the frame center)
double [] ers_xyz_d2t; // world camera Vx, Vy, Vz (m/s^2)
public XyzAtr() {
xyz = new double[3];
atr = new double[3];
}
public XyzAtr(double [] xyz, double [] atr) {
this.xyz = xyz;
this.atr = atr;
this.ers_xyz_dt = new double[3];
this.ers_atr_dt = new double[3];
this.ers_xyz_d2t = new double[3];
this.ers_atr_d2t = new double[3];
}
public XyzAtr(
double [] xyz,
double [] atr,
double [] ers_xyz_dt,
double [] ers_atr_dt) {
this.xyz = xyz;
this.atr = atr;
this.ers_xyz_dt = ers_xyz_dt;
this.ers_atr_dt = ers_atr_dt;
this.ers_xyz_d2t = new double[3];
this.ers_atr_d2t = new double[3];
}
public XyzAtr(
double [] xyz,
double [] atr,
double [] ers_xyz_dt,
double [] ers_atr_dt,
double [] ers_xyz_d2t,
double [] ers_atr_d2t
) {
this.xyz = xyz;
this.atr = atr;
this.ers_xyz_dt = ers_xyz_dt;
this.ers_atr_dt = ers_xyz_dt;
this.ers_xyz_d2t = ers_xyz_d2t;
this.ers_atr_d2t = ers_xyz_d2t;
}
public XyzAtr(String s) {
double [] d = parseDoublesCSV(s);
xyz = new double [] {d[0], d[1], d[2]};
atr = new double [] {d[3], d[4], d[5]};
}
public XyzAtr(String [] ss) {
if (ss[0] != null) {
double [] d = parseDoublesCSV(ss[0]);
xyz = new double [] {d[0], d[1], d[2]};
atr = new double [] {d[3], d[4], d[5]};
this.ers_xyz_dt = new double[3];
this.ers_atr_dt = new double[3];
this.ers_xyz_d2t = new double[3];
this.ers_atr_d2t = new double[3];
if (ss.length > 1) {
if (ss[1] != null) {
d = parseDoublesCSV(ss[1]);
ers_xyz_dt = new double [] {d[0], d[1], d[2]};
ers_atr_dt = new double [] {d[3], d[4], d[5]};
}
if (ss.length > 2) {
if (ss[2] != null) {
d = parseDoublesCSV(ss[2]);
ers_xyz_d2t = new double [] {d[0], d[1], d[2]};
ers_atr_d2t = new double [] {d[3], d[4], d[5]};
}
}
}
}
}
public String toString() {
return String.format("%f, %f, %f, %f, %f, %f",xyz[0],xyz[1],xyz[2],atr[0],atr[1],atr[2]);
}
public String [] toStrings() {
return new String[] {
String.format("%f, %f, %f, %f, %f, %f",xyz[0], xyz[1], xyz[2], atr[0], atr[1], atr[2]),
String.format("%f, %f, %f, %f, %f, %f",ers_xyz_dt[0], ers_xyz_dt[1], ers_xyz_dt[2], ers_atr_dt[0], ers_atr_dt[1], ers_atr_dt[2]),
String.format("%f, %f, %f, %f, %f, %f",ers_xyz_d2t[0], ers_xyz_d2t[1], ers_xyz_d2t[2], ers_atr_d2t[0], ers_atr_d2t[1], ers_atr_d2t[2])};
}
public double [] getXYZ() {
return xyz;
}
public double [] getATR() {
return atr;
}
public void setXYZ(double [] d) {
xyz[0] = d[0];
xyz[1] = d[1];
xyz[2] = d[2];
}
public void setATR(double [] d) {
atr[0] = d[0];
atr[1] = d[1];
atr[2] = d[2];
}
public double [] getErsXYZ_dt() {
return ers_xyz_dt;
}
public double [] getErsATR_dt() {
return ers_atr_dt;
}
public double [] getErsXYZ_d2t() {
return ers_xyz_d2t;
}
public double [] getErsATR_d2t() {
return ers_atr_d2t;
}
public void setErsXYZ_dt(double [] d) {
ers_xyz_dt[0] = d[0];
ers_xyz_dt[1] = d[1];
ers_xyz_dt[2] = d[2];
}
public void setErsATR_dt(double [] d) {
ers_atr_dt[0] = d[0];
ers_atr_dt[1] = d[1];
ers_atr_dt[2] = d[2];
}
public void setErsXYZ_d2t(double [] d) {
ers_xyz_d2t[0] = d[0];
ers_xyz_d2t[1] = d[1];
ers_xyz_d2t[2] = d[2];
}
public void setErsATR_d2t(double [] d) {
ers_atr_d2t[0] = d[0];
ers_atr_d2t[1] = d[1];
ers_atr_d2t[2] = d[2];
}
}
/**
* Calculate rotational matrix and its derivatives by az, tl and rl
* @param atr
......
package com.elphel.imagej.tileprocessor;
/**
**
** IntersceneMatchParameters - Class for handling multiple configuration parameters
** related to the interscene match
**
** Copyright (C) 202 Elphel, Inc.
** Copyright (C) 2022 Elphel, Inc.
**
** -----------------------------------------------------------------------------**
**
......@@ -23,7 +22,7 @@ package com.elphel.imagej.tileprocessor;
** -----------------------------------------------------------------------------**
**
*/
package com.elphel.imagej.tileprocessor;
import java.awt.Color;
import java.io.IOException;
import java.util.Properties;
......@@ -320,7 +319,7 @@ public class IntersceneMatchParameters {
public void dialogQuestions(GenericJTabbedDialog gd) {
// gd.addMessage ("Scene parameters selection");
// gd.addTab ("Inter-Match", "Parameters for full-resolution (no decimation/macrotiles) scene matching");
gd.addTab ("Scene Series", "Processing os series of scene and multi-series sets");
gd.addTab ("Scene Series", "Processing series of scenes and multi-series sets");
gd.addMessage ("Build series options");
gd.addCheckbox ("Force reference scene DSI calculation", this.force_ref_dsi,
"Calculate reference scene DSI even if the file exists.");
......@@ -847,11 +846,6 @@ public class IntersceneMatchParameters {
this.generate_fg = gd.getNextBoolean();
this.generate_bg = gd.getNextBoolean();
this.generate_stereo = gd.getNextBoolean();
/*
for (int i = 0; i < stereo_bases.length; i++) {
this.generate_stereo_var[i] = gd.getNextBoolean();
}
*/
for (int i = 0; i < stereo_views.length; i++) {
this.generate_stereo_var[i] = gd.getNextBoolean();
}
......
/**
**
** LWIRWorldParameters - Class for handling multiple configuration parameters
** related to the octree-based world(s) parameters
**
** Copyright (C) 2022 Elphel, Inc.
**
** -----------------------------------------------------------------------------**
**
** LWIRWorldParameters.java is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
** -----------------------------------------------------------------------------**
**
*/
package com.elphel.imagej.tileprocessor;
import java.util.Properties;
import com.elphel.imagej.common.GenericJTabbedDialog;
public class LWIRWorldParameters {
public double world_hsize = 1000.0; // m
public double min_hsize = 0.3; // m
public double max_hsize = 10000.0; // m
public int max_mesh_centers = 10; //
public int max_cameras = 10; //
public LWIRWorldParameters() {
}
public void dialogQuestions(GenericJTabbedDialog gd) {
gd.addTab ("LWIR World", "Building 3D World from multiple scenes/ scenes series");
gd.addMessage ("Octree world parameters");
gd.addNumericField("World half-size", this.world_hsize, 1,7,"m",
"Initial half-size of the world (it may grow if needed).");
gd.addNumericField("Minimal node half-size", this.min_hsize, 1,7,"m",
"Do not subdivide nodes if its half-size is smaller than this.");
gd.addNumericField("Maximal node half-size", this.max_hsize, 1,7,"m",
"Do not grow the root node (whole world) if its half-size is >= this.");
gd.addNumericField("Maximal number of mesh centers", this.max_mesh_centers, 0,3,"",
"Subdivide octree node that has more than this number of mesh centers.");
gd.addNumericField("Maximal number of scenes/cameras", this.max_cameras, 0,3,"",
"Subdivide octree node that has more than this number of scenes/cameras.");
}
public void dialogAnswers(GenericJTabbedDialog gd) {
this.world_hsize = gd.getNextNumber();
this.min_hsize = gd.getNextNumber();
this.max_hsize = gd.getNextNumber();
this.max_mesh_centers = (int) gd.getNextNumber();
this.max_cameras = (int) gd.getNextNumber();
}
public void setProperties(String prefix,Properties properties){
properties.setProperty(prefix+"world_hsize", this.world_hsize+""); // double
properties.setProperty(prefix+"min_hsize", this.min_hsize+""); // double
properties.setProperty(prefix+"max_hsize", this.max_hsize+""); // double
properties.setProperty(prefix+"max_mesh_centers", this.max_mesh_centers+""); // int
properties.setProperty(prefix+"max_cameras", this.max_cameras+""); // int
}
public void getProperties(String prefix,Properties properties){
if (properties.getProperty(prefix+"world_hsize")!=null) this.world_hsize=Double.parseDouble(properties.getProperty(prefix+"world_hsize"));
if (properties.getProperty(prefix+"min_hsize")!=null) this.min_hsize=Double.parseDouble(properties.getProperty(prefix+"min_hsize"));
if (properties.getProperty(prefix+"max_hsize")!=null) this.max_hsize=Double.parseDouble(properties.getProperty(prefix+"max_hsize"));
if (properties.getProperty(prefix+"max_mesh_centers")!=null) this.max_mesh_centers=Integer.parseInt(properties.getProperty(prefix+"max_mesh_centers"));
if (properties.getProperty(prefix+"max_cameras")!=null) this.max_cameras=Integer.parseInt(properties.getProperty(prefix+"max_cameras"));
}
@Override
public LWIRWorldParameters clone() throws CloneNotSupportedException {
LWIRWorldParameters lwp = new LWIRWorldParameters();
lwp.world_hsize = this.world_hsize;
lwp.min_hsize = this.min_hsize;
lwp.max_hsize = this.max_hsize;
lwp.max_mesh_centers = this.max_mesh_centers;
lwp.max_cameras = this.max_cameras;
return lwp;
}
}
......@@ -92,7 +92,7 @@ public class QuadCLT extends QuadCLTCPU {
}
QuadCLT saveQuadClt() {
public QuadCLT saveQuadClt() {
if (gpuQuad == null) {
return null;
}
......@@ -110,7 +110,7 @@ public class QuadCLT extends QuadCLTCPU {
}
}
void setQuadClt() {
public void setQuadClt() {
if (gpuQuad != null) {
gpuQuad.updateQuadCLT(this); // to re-load new set of Bayer images to the GPU
}
......@@ -845,6 +845,7 @@ public class QuadCLT extends QuadCLTCPU {
final int photo_offs_set, // 0; // 0 - keep weighted offset average, 1 - balance result image, 2 - set weighted average to specific value
final double photo_offs, // 21946; // weighted average offset target value, if photo_offs_set (and not photo_offs_balance)
final int num_refines, // 2
final int min_good, // minimal number of "good" pixels
final double [][] combo_dsn_final, // double [][] combo_dsn_final, // dls,
int threadsMax,
final boolean debug)
......@@ -919,6 +920,11 @@ public class QuadCLT extends QuadCLTCPU {
num_good++;
}
}
if (num_good < min_good) {
System.out.println("calibratePhotometric2(): Too few good pixels for calibration: "+
num_good+" < "+min_good+", abandoning photometric calibration.");
return false;
}
avg_img /= num_good;
double wavg_offs = photo_offs;
boolean set_offs = true;
......@@ -1021,6 +1027,10 @@ public class QuadCLT extends QuadCLTCPU {
s += pa_data[nsens][i][0] - pa_data[nsens][i][1]/b;
}
c = -s/num_good*b;
if (Double.isNaN(c)) {
System.out.println("calibratePhotometric2().1 c=NaN");
return false;
}
} else {
// need to balance quadratic so their average is 0
// linear or quadratic
......@@ -1028,9 +1038,18 @@ public class QuadCLT extends QuadCLTCPU {
c = pa_coeff[nsens][0];
b = pa_coeff[nsens][1];
a = (pa_coeff[nsens].length > 2) ? pa_coeff[nsens][2] : 0.0;
if (Double.isNaN(c)) {
System.out.println("calibratePhotometric2().2 c=NaN");
return false;
}
}
double A = a;
double C = -c/b;
if (Double.isNaN(C)) {
System.out.println("calibratePhotometric2().3 C=NaN");
return false;
}
if (Math.abs(a) >= min_abs_a) {
double d2 = b*b - 4*a*c;
if (d2 < 0) {
......@@ -1038,6 +1057,10 @@ public class QuadCLT extends QuadCLTCPU {
return false;
}
C = (-b + Math.sqrt(d2))/(2 * a);
if (Double.isNaN(C)) {
System.out.println("calibratePhotometric2().4 C=NaN");
return false;
}
}
double B = 2 * C * a + b;
scales2_new[nsens] = A;
......@@ -1094,6 +1117,11 @@ public class QuadCLT extends QuadCLTCPU {
double b = pa_coeff[nsens][1];
scales_new [nsens] = b;
offs_new[nsens] = -c/b;
if (Double.isNaN(offs_new[nsens])) {
System.out.println("calibratePhotometric2().5 offs_new[nsens]=NaN");
return false;
}
}
// re-normalize scales_new
double scales_avg = 1.0;
......@@ -4270,7 +4298,6 @@ if (debugLevel < -100) {
null, // final QuadCLTCPU ref_scene, // may be null if scale_fpn <= 0
threadsMax,
debugLevel);
// return quadCLT;
}
......
......@@ -1025,10 +1025,6 @@ public class QuadCLTCPU {
ers.getPropertiesERS(prefix, properties);
ers.getPropertiesScenes(prefix, properties);
ers.getPropertiesLineTime(prefix, properties); // will set old value if not in the file
System.out.println("Restored interframe properties from :"+path);
return properties;
}
......@@ -1348,7 +1344,7 @@ public class QuadCLTCPU {
this.image_name, // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
correctionsParameters.jp4SubDir,
true, // smart,
true); //newAllowed, // save
true); // false); // true); //newAllowed, // save
String [] sourceFiles = correctionsParameters.selectSourceFileInSet(jp4_copy_path, debugLevel);
if (sourceFiles.length < getNumSensors()) {
if (sourceFiles.length > 0) {
......@@ -1390,22 +1386,6 @@ public class QuadCLTCPU {
threadsMax,
1); // debugLevel); // final int debug_level)
}
/*
// try to restore DSI generated from interscene if available, if not use single-scene -DSI_MAIN
if (restoreDSI(
"-DSI_INTER",
true // silent
) < 0) {
restoreDSI(
"-DSI_MAIN", // "-DSI_COMBO", "-DSI_MAIN" (DSI_COMBO_SUFFIX, DSI_MAIN_SUFFIX)
false); // silent
}
restoreInterProperties( // restore properties for interscene processing (extrinsics, ers, ...) // get relative poses (98)
null, // String path, // full name with extension or null to use x3d directory
false, // boolean all_properties,// null, // Properties properties, // if null - will only save extrinsics)
debugLevel);
// showDSIMain();
*/
return this; // can only be QuadCLT instance
}
......@@ -4706,8 +4686,8 @@ public class QuadCLTCPU {
return result;
}
class SetChannels{ // USED in lwir
String set_name; // set name (timestamp)
public class SetChannels{ // USED in lwir
public String set_name; // set name (timestamp)
int [] file_number; // array of file numbers for channels
public SetChannels(String name, int[] fn){ // USED in lwir
set_name = name;
......@@ -4724,7 +4704,7 @@ public class QuadCLTCPU {
}
}
SetChannels [] setChannels( // USED in lwir
public SetChannels [] setChannels( // USED in lwir
int debugLevel) {
return setChannels(null, debugLevel);
}
......
......@@ -921,7 +921,7 @@ public class TexturedModel {
scene_ers_atr_dt); // double [] ers_atr_dt)(ers_scene_original_xyz_dt);
}
double [][] dxyzatr_dt = null;
if (mb_en) {
if (mb_en) { // all scenes have the same name/path
dxyzatr_dt = OpticalFlow.getVelocities( // looks at previous/next scene poses
scenes, // QuadCLT [] quadCLTs,
nscene); // int nscene)
......@@ -976,7 +976,7 @@ public class TexturedModel {
if (slice_texture[tileY][tileX] != null) {
double w = 1.0;
if (tex_mb > 0.0) {
double mb_l2 = mb_tau2 * ( motion_blur[0][nTile]*motion_blur[0][nTile] +
double mb_l2 = mb_tau2 * ( motion_blur[0][nTile]*motion_blur[0][nTile] + // motion_blur == null;
motion_blur[1][nTile]*motion_blur[1][nTile]);
if (mb_l2 > 1.0) {
w /= mb_l2; // 1/(squared mb)
......
......@@ -2971,7 +2971,16 @@ if (debugLevel > -100) return true; // temporarily !
}
/**
* Copy source files to the model directory (above versions) and optionally extract location data to *.kml file
* @param set_name set name (timestamp)
* @param quadCLT_main RGB QuadCLT instance
* @param quadCLT_aux secondary RGB or LWIR QuadCLT instance
* @param clt_parameters CLT parameters
* @param skip_existing do not copy if destination files exist
* @param search_KML search fpr geo data and extract it to KML file if found
* @param debugLevel debug level
*/
public static void copyJP4src(
String set_name,
QuadCLT quadCLT_main, // tiles should be set
......@@ -2981,9 +2990,6 @@ if (debugLevel > -100) return true; // temporarily !
boolean search_KML,
final int debugLevel) // throws Exception
{
// quadCLT_main.writeKml(debugLevel);
// quadCLT_main.writeRatingFile(debugLevel);
String [] sourceFiles_main=quadCLT_main.correctionsParameters.getSourcePaths();
//
......@@ -8482,7 +8488,6 @@ if (debugLevel > -100) return true; // temporarily !
if (min_num_scenes < 1) {
min_num_scenes = 1;
}
long start_time_all = System.nanoTime();
OpticalFlow opticalFlow = new OpticalFlow(
quadCLT_main.getNumSensors(),
......@@ -8499,6 +8504,7 @@ if (debugLevel > -100) return true; // temporarily !
num_seq = pathFirstLast.length;
}
}
class VideoSet {
String [] video_paths;
int [] stereo_widths;
......@@ -8520,12 +8526,6 @@ if (debugLevel > -100) return true; // temporarily !
ArrayList<VideoSet> video_sets_list = new ArrayList<VideoSet>();
// String [][] video_lists = new String [num_seq][];
// int [] earliest_scene_pointer = new int[1];
// int [][] stereo_widths = new int [num_seq][];
for (int nseq = 0; nseq < num_seq; nseq++) {
long start_time_seq = System.nanoTime();
System.out.println("\nSTARTED PROCESSING SCENE SEQUENCE "+nseq+" (last is "+(num_seq-1)+")");
......@@ -8609,6 +8609,10 @@ if (debugLevel > -100) return true; // temporarily !
}
}
// combine videos if generated
if ((video_sets_list.size() > 1) &&
(video_sets_list.get(0).getVideoPaths() != null) &&
......
/**
**
** XyzAtr - store position+orientation (world XYZ, Azimuth, Tilt, Roll)
** of other scenes relative to the position of this camera.
** Positions/orientations are sampled during scanning of the center line
**
**
** Copyright (C) 2022 Elphel, Inc.
**
** -----------------------------------------------------------------------------**
**
** XyzAtr.java is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
** -----------------------------------------------------------------------------**
**
*/
package com.elphel.imagej.tileprocessor;
public class XyzAtr {
double [] xyz;
double [] atr;
double [] ers_xyz_dt; // world camera Vx, Vy, Vz (m/s)
double [] ers_atr_dt; // camera rotations (az, tilt, roll in radians/s, corresponding to the frame center)
double [] ers_atr_d2t; // camera rotations (az, tilt, roll in radians/s, corresponding to the frame center)
double [] ers_xyz_d2t; // world camera Vx, Vy, Vz (m/s^2)
public XyzAtr() {
xyz = new double[3];
atr = new double[3];
}
public XyzAtr(double [] xyz, double [] atr) {
this.xyz = xyz;
this.atr = atr;
this.ers_xyz_dt = new double[3];
this.ers_atr_dt = new double[3];
this.ers_xyz_d2t = new double[3];
this.ers_atr_d2t = new double[3];
}
public XyzAtr(
double [] xyz,
double [] atr,
double [] ers_xyz_dt,
double [] ers_atr_dt) {
this.xyz = xyz;
this.atr = atr;
this.ers_xyz_dt = ers_xyz_dt;
this.ers_atr_dt = ers_atr_dt;
this.ers_xyz_d2t = new double[3];
this.ers_atr_d2t = new double[3];
}
public XyzAtr(
double [] xyz,
double [] atr,
double [] ers_xyz_dt,
double [] ers_atr_dt,
double [] ers_xyz_d2t,
double [] ers_atr_d2t
) {
this.xyz = xyz;
this.atr = atr;
this.ers_xyz_dt = ers_xyz_dt;
this.ers_atr_dt = ers_xyz_dt;
this.ers_xyz_d2t = ers_xyz_d2t;
this.ers_atr_d2t = ers_xyz_d2t;
}
public XyzAtr(String s) {
double [] d = ErsCorrection.parseDoublesCSV(s);
xyz = new double [] {d[0], d[1], d[2]};
atr = new double [] {d[3], d[4], d[5]};
}
public XyzAtr(String [] ss) {
if (ss[0] != null) {
double [] d = ErsCorrection.parseDoublesCSV(ss[0]);
xyz = new double [] {d[0], d[1], d[2]};
atr = new double [] {d[3], d[4], d[5]};
this.ers_xyz_dt = new double[3];
this.ers_atr_dt = new double[3];
this.ers_xyz_d2t = new double[3];
this.ers_atr_d2t = new double[3];
if (ss.length > 1) {
if (ss[1] != null) {
d = ErsCorrection.parseDoublesCSV(ss[1]);
ers_xyz_dt = new double [] {d[0], d[1], d[2]};
ers_atr_dt = new double [] {d[3], d[4], d[5]};
}
if (ss.length > 2) {
if (ss[2] != null) {
d = ErsCorrection.parseDoublesCSV(ss[2]);
ers_xyz_d2t = new double [] {d[0], d[1], d[2]};
ers_atr_d2t = new double [] {d[3], d[4], d[5]};
}
}
}
}
}
public String toString() {
return String.format("%f, %f, %f, %f, %f, %f",xyz[0],xyz[1],xyz[2],atr[0],atr[1],atr[2]);
}
public String [] toStrings() {
return new String[] {
String.format("%f, %f, %f, %f, %f, %f",xyz[0], xyz[1], xyz[2], atr[0], atr[1], atr[2]),
String.format("%f, %f, %f, %f, %f, %f",ers_xyz_dt[0], ers_xyz_dt[1], ers_xyz_dt[2], ers_atr_dt[0], ers_atr_dt[1], ers_atr_dt[2]),
String.format("%f, %f, %f, %f, %f, %f",ers_xyz_d2t[0], ers_xyz_d2t[1], ers_xyz_d2t[2], ers_atr_d2t[0], ers_atr_d2t[1], ers_atr_d2t[2])};
}
public double [] getXYZ() {
return xyz;
}
public double [] getATR() {
return atr;
}
public void setXYZ(double [] d) {
xyz[0] = d[0];
xyz[1] = d[1];
xyz[2] = d[2];
}
public void setATR(double [] d) {
atr[0] = d[0];
atr[1] = d[1];
atr[2] = d[2];
}
public double [] getErsXYZ_dt() {
return ers_xyz_dt;
}
public double [] getErsATR_dt() {
return ers_atr_dt;
}
public double [] getErsXYZ_d2t() {
return ers_xyz_d2t;
}
public double [] getErsATR_d2t() {
return ers_atr_d2t;
}
public void setErsXYZ_dt(double [] d) {
ers_xyz_dt[0] = d[0];
ers_xyz_dt[1] = d[1];
ers_xyz_dt[2] = d[2];
}
public void setErsATR_dt(double [] d) {
ers_atr_dt[0] = d[0];
ers_atr_dt[1] = d[1];
ers_atr_dt[2] = d[2];
}
public void setErsXYZ_d2t(double [] d) {
ers_xyz_d2t[0] = d[0];
ers_xyz_d2t[1] = d[1];
ers_xyz_d2t[2] = d[2];
}
public void setErsATR_d2t(double [] d) {
ers_atr_d2t[0] = d[0];
ers_atr_d2t[1] = d[1];
ers_atr_d2t[2] = d[2];
}
}
\ No newline at end of file
......@@ -127,11 +127,12 @@ public class LwocOctree implements Serializable {
infinity = 0;
double max_hsize = world.getMaxHsize();
LwocOctree lwoc_root = world.getLwocRoot();
double [] root_center = (lwoc_root == null)?center:lwoc_root.center;
for (int dm = 0; dm < center.length; dm++) {
if ((center[dm] - hsize) <= (lwoc_root.center[dm] - max_hsize)) {
if ((center[dm] - hsize) <= (root_center[dm] - max_hsize)) {
infinity |= (1 << (2 * dm));
}
if ((center[dm] + hsize) >= (lwoc_root.center[dm] + max_hsize)) {
if ((center[dm] + hsize) >= (root_center[dm] + max_hsize)) {
infinity |= (1 << (2 * dm + 1));
}
}
......
......@@ -24,28 +24,33 @@
package com.elphel.imagej.tileprocessor.lwoc;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicInteger;
import java.io.Serializable;
import java.util.HashMap;
import com.elphel.imagej.tileprocessor.GeometryCorrection;
public class LwocScene {
import com.elphel.imagej.tileprocessor.QuadCLT;
import com.elphel.imagej.tileprocessor.XyzAtr;
//https://www.baeldung.com/java-treemap-vs-hashmap
public class LwocScene implements Serializable {
private static final long serialVersionUID = 1L;
static AtomicInteger SCENE_ID = new AtomicInteger();
static ArrayList<LwocScene> LWOC_SCENES;
int id; // assign unique ID
static HashMap<String, LwocScene> LWOC_SCENES;
// int id; // assign unique ID
String stimestamp;
GeometryCorrection geometryCorrection;
GeometryCorrection geometryCorrection; // serialize?
double [] camera_xyz;
double [] camera_atr;
double [] camera_xyz_dt;
double [] camera_atr_dt;
double [][][] tile_layers_dsm; // per tile, per layer, {disparity, strength, mode}. For mode -
HashMap<String, XyzAtr> other_scenes;
transient QuadCLT quadCLT; // use QuadCLT to restore
// will be stored as Tiff
transient double [][][] tile_layers_dsm; // per tile, per layer, {disparity, strength, mode}. For mode -
// interpret as Double doubleToLongBits(), [22] - used LMA, 0..15 - which sensors were used
public static void resetScenes() {
SCENE_ID.set(0);
LWOC_SCENES = new ArrayList<LwocScene>();
// SCENE_ID.set(0);
// LWOC_SCENES = new ArrayList<LwocScene>();
LWOC_SCENES = new HashMap<String, LwocScene>();
}
public LwocScene (
......@@ -64,8 +69,9 @@ public class LwocScene {
this.camera_xyz_dt = camera_xyz_dt;
this.camera_atr_dt = camera_atr_dt;
this.tile_layers_dsm = tile_layers_dsm;
id = SCENE_ID.getAndIncrement();
LWOC_SCENES.add(this);
// id = SCENE_ID.getAndIncrement();
// LWOC_SCENES.add(this);
LWOC_SCENES.put(stimestamp, this);
};
// add functionality to save/restore
public double [] getCameraXYZ() {
......
......@@ -170,6 +170,14 @@ public class LwocWorld implements Serializable {
lwoc_worlds.add(new_world);
return new_world;
}
public static LwocWorld getWorld() {
return getWorld(lwoc_worlds.size()-1);
}
public static LwocWorld getWorld(int indx) {
return lwoc_worlds.get(indx);
}
/**
* Delete world from the universe (if existed)
......
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