Commit 64394dd7 authored by Andrey Filippov's avatar Andrey Filippov

Bug fixes, added super-batch run (multiple configs)

parent cdd2bf43
......@@ -815,6 +815,7 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
addButton("Image Properties", panelLWIR16, color_conf_process);
addButton("Illustrations Configure", panelLWIR16, color_conf_process);
addButton("Footage Organize", panelLWIR16, color_conf_process);
addButton("Super batch", panelLWIR16, color_process);
plugInFrame.add(panelLWIR16);
......@@ -5433,6 +5434,41 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
FOOTAGE_ORGANIZE.OrganizeSeries(
CLT_PARAMETERS,
CALIBRATION_ILLUSTRATION);
} else if (label.equals("Super batch")) {
DEBUG_LEVEL = MASTER_DEBUG_LEVEL;
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
CLT_PARAMETERS.batch_run = true;
String [] configs = loadMultiProperties(
CORRECTION_PARAMETERS.resultsDirectory, // String directory,
true);// boolean useXML,
if (configs == null) {
return;
}
long startTime = System.nanoTime();
for (int nc = 0; nc < configs.length; nc++) {
long startTimeRun = System.nanoTime();
String config = configs[nc];
String path = loadProperties(config, CORRECTION_PARAMETERS.resultsDirectory, true, PROPERTIES);
System.out.println(path);
if (path != null) {
getAllProperties(PROPERTIES);
if (DEBUG_LEVEL > -3)
System.out.println("Configuration parameters are restored from " + path);
} else {
if (DEBUG_LEVEL > -10)
System.out.println("Failed to restore configuration parameters");
return;
}
batchLwir();
System.out.println("Super batch: processing of run "+ nc+" (of "+configs.length+"): "+config+ " finished in "
+ IJ.d2s(0.000000001 * (System.nanoTime() - startTimeRun), 3) + " sec, --- Free memory="
+ Runtime.getRuntime().freeMemory() + " (of " + Runtime.getRuntime().totalMemory() + ")");
}
System.out.println("Super batch: all (of "+configs.length+"): finished at "
+ IJ.d2s(0.000000001 * (System.nanoTime() - startTime), 3) + " sec, --- Free memory="
+ Runtime.getRuntime().freeMemory() + " (of " + Runtime.getRuntime().totalMemory() + ")");
return;
} else if (label.equals("Image Properties")) {
DEBUG_LEVEL = MASTER_DEBUG_LEVEL;
......@@ -9136,7 +9172,9 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
+ ")"), // filter
directory); // may be ""
} else
path += patterns[0];
if (!path.endsWith(patterns[0])) {
path += patterns[0]; // where was it used???
}
if (path == null)
return null;
InputStream is;
......@@ -9172,6 +9210,25 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
return path;
}
public String [] loadMultiProperties(
String directory,
boolean useXML) {
String[] XMLPatterns = { ".corr-xml", ".xml" };
String[] confPatterns = { ".conf" };
String[] patterns = useXML ? XMLPatterns : confPatterns;
String [] paths = selectFiles(
false, // boolean save,
"Multiple configuration file selection", // title
"Read configuration files", // button
new MultipleExtensionsFileFilter(patterns,
(useXML ? "XML " : "") + "Configuration files (" + (useXML ? "*.corr-xml" : "*.conf")
+ ")"), // filter
new String[] {directory}); // String[] defaultPaths)
return paths;
}
/* ======================================================================== */
public void setAllProperties(Properties properties) {
properties.setProperty("MASTER_DEBUG_LEVEL", MASTER_DEBUG_LEVEL + "");
......
......@@ -201,7 +201,9 @@ public class GpuQuad{ // quad camera description
resetGeometryCorrectionVector();
this.gpuTileProcessor.bayer_set = false;
}
public void resetBayer() {
this.gpuTileProcessor.bayer_set = false;
}
public QuadCLT getQuadCLT( ) {
return this.quadCLT;
}
......
......@@ -1972,6 +1972,21 @@ public class ErsCorrection extends GeometryCorrection {
}
public static double [][] invertXYZATR(
double [] source_xyz,
double [] source_atr)
{
Rotation scene_rotation= new Rotation(RotationOrder.YXZ, ROT_CONV, source_atr[0], source_atr[1], source_atr[2]);
Vector3D scene_offset = new Vector3D(-source_xyz[0], -source_xyz[1], -source_xyz[2]);
Rotation rotation = scene_rotation.revert(); //
Vector3D offset = rotation.applyTo(scene_offset); // junk
double [] angles = rotation.getAngles(RotationOrder.YXZ, ROT_CONV);
double [] xyz = offset.toArray();
return new double[][] {xyz,angles};
}
public double [] getImageCoordinatesERS(
double [] xyzw,
boolean correctDistortions, // correct distortion (will need corrected background too !)
......
......@@ -3090,6 +3090,26 @@ public class OpticalFlow {
double [] new_from_last_xyz = ers_scene_last_known.getSceneXYZ(scene_ts);
double [] new_from_last_atr = ers_scene_last_known.getSceneATR(scene_ts);
double [][] last_from_new = ErsCorrection.invertXYZATR(new_from_last_xyz, new_from_last_atr);
double [][] vfy_new_from_last = ErsCorrection.invertXYZATR(last_from_new[0], last_from_new[1]);
System.out.println(new_from_last_xyz[0]+","+new_from_last_xyz[1]+","+new_from_last_xyz[2]+","+
new_from_last_atr[0]+","+new_from_last_atr[1]+","+new_from_last_atr[2]);
System.out.println(last_from_new[0][0]+","+last_from_new[0][1]+","+last_from_new[0][2]+","+
last_from_new[1][0]+","+last_from_new[1][1]+","+last_from_new[1][2]);
System.out.println(vfy_new_from_last[0][0]+","+vfy_new_from_last[0][1]+","+vfy_new_from_last[0][2]+","+
vfy_new_from_last[1][0]+","+vfy_new_from_last[1][1]+","+vfy_new_from_last[1][2]);
/*
double [][] last_from_new1 = ErsCorrection.invertXYZATR(vfy_new_from_last[0],vfy_new_from_last[1]);
double [][] vfy_new_from_last1 = ErsCorrection.invertXYZATR(last_from_new1[0], last_from_new1[1]);
System.out.println(last_from_new1[0][0]+","+last_from_new1[0][1]+","+last_from_new1[0][2]+","+
last_from_new1[1][0]+","+last_from_new1[1][1]+","+last_from_new1[1][2]);
System.out.println(vfy_new_from_last1[0][0]+","+vfy_new_from_last1[0][1]+","+vfy_new_from_last1[0][2]+","+
vfy_new_from_last1[1][0]+","+vfy_new_from_last1[1][1]+","+vfy_new_from_last1[1][2]);
*/
// combine two rotations and two translations
System.out.println("Processing scene "+i+": "+scene_QuadClt.getImageName());
double [][] combo_XYZATR = ErsCorrection.combineXYZATR(
......@@ -3167,6 +3187,127 @@ public class OpticalFlow {
}
}
public void adjustSeries(
CLTParameters clt_parameters,
double k_prev,
QuadCLT [] scenes, // ordered by increasing timestamps
int ref_index,
int debug_level
)
{
double [][][] scenes_xyzatr = new double [scenes.length][][]; // previous scene relative to the next one
QuadCLT reference_QuadClt = scenes[ref_index]; // scenes.length-1]; // last acquired
ErsCorrection ers_reference = reference_QuadClt.getErsCorrection();
// modify LMA parameters to freeze reference ERS, remove pull on scene ERS
boolean[] param_select2 = clt_parameters.ilp.ilma_lma_select.clone(); // final boolean[] param_select,
double [] param_regweights2 = clt_parameters.ilp.ilma_regularization_weights; // final double [] param_regweights,
boolean delete_scene_asap = (debug_level < 10); // to save memory
// freeze reference ERS, free scene ERS
for (int j = 0; j <3; j++) {
param_select2[ErsCorrection.DP_DVX + j] = false;
param_select2[ErsCorrection.DP_DVAZ + j] = false;
param_regweights2[ErsCorrection.DP_DSVX + j] = 0.0;
param_regweights2[ErsCorrection.DP_DSVAZ + j] = 0.0;
}
// process scenes before reference
if (ref_index > 1) {
for (int i = ref_index - 2; i >=0 ; i--) {
QuadCLT scene_QuadClt = scenes[i];
String last_known_ts = scenes[i+1].getImageName(); // it should be present in the reference scene scenes
String scene_ts = scenes[i].getImageName(); // it should be present in the scenes[i+1] scenes
ErsCorrection ers_scene_last_known = scenes[i+1].getErsCorrection();
ErsCorrection ers_scene = scene_QuadClt.getErsCorrection();
double [] last_known_xyz = ers_reference.getSceneXYZ(last_known_ts);
double [] last_known_atr = ers_reference.getSceneATR(last_known_ts);
double [] new_from_last_xyz = ers_scene_last_known.getSceneXYZ(scene_ts);
double [] new_from_last_atr = ers_scene_last_known.getSceneATR(scene_ts);
// combine two rotations and two translations
System.out.println("Processing scene "+i+": "+scene_QuadClt.getImageName());
double [][] combo_XYZATR = ErsCorrection.combineXYZATR(
last_known_xyz, // double [] reference_xyz,
last_known_atr, // double [] reference_atr, // null?
new_from_last_xyz, // double [] scene_xyz,
new_from_last_atr); // double [] scene_atr)
// before adjusting - save original ERS, restart afterwards
double [] ers_scene_original_xyz_dt = ers_scene.getErsXYZ_dt();
double [] ers_scene_original_atr_dt = ers_scene.getErsATR_dt();
// ers should be correct for both
scenes_xyzatr[i] = adjustPairsLMA(
clt_parameters, // CLTParameters clt_parameters,
reference_QuadClt, // QuadCLT reference_QuadCLT,
scene_QuadClt, // QuadCLT scene_QuadCLT,
combo_XYZATR[0], // xyz
combo_XYZATR[1], // atr
param_select2, // final boolean[] param_select,
param_regweights2, // final double [] param_regweights,
debug_level); // int debug_level)
ers_reference.addScene(scene_QuadClt.getImageName(),
scenes_xyzatr[i][0],
scenes_xyzatr[i][1],
ers_scene.getErsXYZ_dt(),
ers_scene.getErsATR_dt()
);
// restore original ers data
ers_scene.setErsDt(
ers_scene_original_xyz_dt, // double [] ers_xyz_dt,
ers_scene_original_atr_dt); // double [] ers_atr_dt)(ers_scene_original_xyz_dt);
ers_scene.setupERS();
if (debug_level > -1) {
System.out.println("Pass multi scene "+i+" (of "+ scenes.length+") "+
reference_QuadClt.getImageName() + "/" + scene_QuadClt.getImageName()+" Done.");
}
if (delete_scene_asap) {
scenes[i+1] = null;
}
// Runtime.getRuntime().gc();
// System.out.println("Scene "+i+", --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
}
}
// process scenes after reference (if it is not the last
if (ref_index < (scenes.length - 1)) {
}
reference_QuadClt.saveInterProperties( // save properties for interscene processing (extrinsics, ers, ...)
null, // String path, // full name with extension or w/o path to use x3d directory
debug_level+1);
if (!delete_scene_asap && (debug_level > -1)) {
System.out.println("adjustSeries(): preparing image set...");
int nscenes = scenes.length;
int indx_ref = nscenes - 1;
double [][][] all_scenes_xyzatr = new double [scenes.length][][]; // includes reference (last)
double [][][] all_scenes_ers_dt = new double [scenes.length][][]; // includes reference (last)
all_scenes_xyzatr[indx_ref] = new double [][] {ZERO3,ZERO3};
all_scenes_ers_dt[indx_ref] = new double [][] {
ers_reference.getErsXYZ_dt(),
ers_reference.getErsATR_dt()};
for (int i = 0; i < nscenes; i++) if (i != indx_ref) {
String ts = scenes[i].getImageName();
all_scenes_xyzatr[i] = new double[][] {ers_reference.getSceneXYZ(ts), ers_reference.getSceneATR(ts)};
all_scenes_ers_dt[i] = new double[][] {ers_reference.getSceneErsXYZ_dt(ts), ers_reference.getSceneErsATR_dt(ts)};
}
compareRefSceneTiles(
"" , // String suffix,
false, // boolean blur_reference,
all_scenes_xyzatr, // double [][][] scene_xyzatr, // does not include reference
all_scenes_ers_dt, // double [][][] scene_ers_dt, // does not include reference
scenes, // QuadCLT [] scenes,
8); // int iscale) // 8
}
if (debug_level > -1) {
System.out.println("adjustSeries() Done.");
}
}
public void IntersceneAccumulate(
CLTParameters clt_parameters,
ColorProcParameters colorProcParameters,
......
......@@ -5532,6 +5532,12 @@ if (debugLevel < -100) {
}
}
public void resetBayer() {
if (getGPU() != null) {
getGPU().resetBayer();
}
}
public QuadCLT spawnQuadCLT(
String set_name,
CLTParameters clt_parameters,
......
......@@ -8458,6 +8458,72 @@ if (debugLevel > -100) return true; // temporarily !
System.out.println("End of interSeriesLMA()");
}
public void interSeriesLMA(
QuadCLT quadCLT_main, // tiles should be set
int ref_index,
CLTParameters clt_parameters,
EyesisCorrectionParameters.DebayerParameters debayerParameters,
ColorProcParameters colorProcParameters,
CorrectionColorProc.ColorGainsParameters channelGainParameters,
EyesisCorrectionParameters.RGBParameters rgbParameters,
EyesisCorrectionParameters.EquirectangularParameters equirectangularParameters,
Properties properties,
boolean reset_from_extrinsics,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel) throws Exception
{
if ((quadCLT_main != null) && (quadCLT_main.getGPU() != null)) {
quadCLT_main.getGPU().resetGeometryCorrection();
quadCLT_main.gpuResetCorrVector(); // .getGPU().resetGeometryCorrectionVector();
}
// final boolean batch_mode = clt_parameters.batch_run;
this.startTime=System.nanoTime();
String [] sourceFiles0=quadCLT_main.correctionsParameters.getSourcePaths();
QuadCLT.SetChannels [] set_channels_main = quadCLT_main.setChannels(debugLevel);
if ((set_channels_main == null) || (set_channels_main.length==0)) {
System.out.println("No files to process (of "+sourceFiles0.length+")");
return;
}
QuadCLT.SetChannels [] set_channels=quadCLT_main.setChannels(debugLevel);
QuadCLT [] quadCLTs = new QuadCLT [set_channels.length];
// QuadCLTCPU [] quadCLTs = new QuadCLTCPU [set_channels.length];
for (int i = 0; i < quadCLTs.length; i++) {
quadCLTs[i] = (QuadCLT) quadCLT_main.spawnQuadCLT(
set_channels[i].set_name,
clt_parameters,
colorProcParameters, //
threadsMax,
debugLevel);
// temporarily fix wrong sign:
// ErsCorrection ers = (ErsCorrection) (quadCLTs[i].getGeometryCorrection());
quadCLTs[i].setDSRBG(
clt_parameters, // CLTParameters clt_parameters,
threadsMax, // int threadsMax, // maximal number of threads to launch
updateStatus, // boolean updateStatus,
debugLevel); // int debugLevel)
}
OpticalFlow opticalFlow = new OpticalFlow(
quadCLT_main.getNumSensors(),
clt_parameters.ofp.scale_no_lma_disparity, // double scale_no_lma_disparity,
threadsMax, // int threadsMax, // maximal number of threads to launch
updateStatus); // boolean updateStatus);
opticalFlow.adjustSeries(
clt_parameters, // CLTParameters clt_parameters,
clt_parameters.ofp.k_prev, // k_prev,\
// FIXME: *********** update adjustSeries to use QUADCLTCPU ! **********
// (QuadCLT [])
quadCLTs, // QuadCLT [] scenes, // ordered by increasing timestamps
clt_parameters.ofp.debug_level_optical); // 1); // -1); // int debug_level);
System.out.println("End of interSeriesLMA()");
}
public void intersceneAccumulate(
QuadCLT quadCLT_main, // tiles should be set
......@@ -11111,10 +11177,12 @@ if (debugLevel > -100) return true; // temporarily !
if ((quadCLT_main != null) && (quadCLT_main.getGPU() != null)) {
quadCLT_main.getGPU().resetGeometryCorrection();
quadCLT_main.gpuResetCorrVector(); // .getGPU().resetGeometryCorrectionVector();
quadCLT_main.resetBayer();
}
if ((quadCLT_aux != null) && (quadCLT_aux.getGPU() != null)) {
quadCLT_aux.getGPU().resetGeometryCorrection();
quadCLT_aux.gpuResetCorrVector(); // .getGPU().resetGeometryCorrectionVector();
quadCLT_aux.resetBayer();
}
......@@ -11154,6 +11222,16 @@ if (debugLevel > -100) return true; // temporarily !
}
for (int nSet = 0; nSet < set_channels.length; nSet++){
if ((quadCLT_main != null) && (quadCLT_main.getGPU() != null)) { //TODO: is it needed here? WAs not needed before - verify
quadCLT_main.getGPU().resetGeometryCorrection();
quadCLT_main.gpuResetCorrVector(); // .getGPU().resetGeometryCorrectionVector();
quadCLT_main.resetBayer();
}
if ((quadCLT_aux != null) && (quadCLT_aux.getGPU() != null)) {
quadCLT_aux.getGPU().resetGeometryCorrection();
quadCLT_aux.gpuResetCorrVector(); // .getGPU().resetGeometryCorrectionVector();
quadCLT_aux.resetBayer();
}
// nset -> name - n1, n2 (in
String set_name = set_channels[nSet].set_name;
int nSet_main = -1, nSet_aux = -1;
......@@ -11768,7 +11846,17 @@ if (debugLevel > -100) return true; // temporarily !
// System.out.println("batchLwirRig(): processing "+(quadCLT_main.getTotalFiles(set_channels_main)+quadCLT_aux.getTotalFiles(set_channels_aux))+" files ("+set_channels_main.length+" file sets) finished at "+
int num_main = (quadCLT_main==null)? 0 : quadCLT_main.getTotalFiles(set_channels_main);
int num_aux = (quadCLT_aux ==null)? 0 : quadCLT_aux.getTotalFiles(set_channels_aux);
// Process LWIR16 tasks applicable to scene series rather than individual scenes
if ((quadCLT_main != null) && (quadCLT_main.getGPU() != null)) { //TODO: is it needed here? WAs not needed before - verify
quadCLT_main.getGPU().resetGeometryCorrection();
quadCLT_main.gpuResetCorrVector(); // .getGPU().resetGeometryCorrectionVector();
quadCLT_main.resetBayer();
}
if ((quadCLT_aux != null) && (quadCLT_aux.getGPU() != null)) {
quadCLT_aux.getGPU().resetGeometryCorrection();
quadCLT_aux.gpuResetCorrVector(); // .getGPU().resetGeometryCorrectionVector();
quadCLT_aux.resetBayer();
}
// Process LWIR16 tasks applicable to scene series rather than individual scenes
if (quadCLT_main.correctionsParameters.clt_batch_pose_pairs_main) {
TestInterLMA(quadCLT_main, // QUAD_CLT, // QuadCLT quadCLT_main,
clt_parameters, // EyesisCorrectionParameters.DCTParameters dct_parameters,
......@@ -11866,7 +11954,16 @@ if (debugLevel > -100) return true; // temporarily !
updateStatus, // final boolean updateStatus,
debugLevel);
}
if ((quadCLT_main != null) && (quadCLT_main.getGPU() != null)) { //TODO: is it needed here? WAs not needed before - verify
quadCLT_main.getGPU().resetGeometryCorrection();
quadCLT_main.gpuResetCorrVector(); // .getGPU().resetGeometryCorrectionVector();
quadCLT_main.resetBayer();
}
if ((quadCLT_aux != null) && (quadCLT_aux.getGPU() != null)) {
quadCLT_aux.getGPU().resetGeometryCorrection();
quadCLT_aux.gpuResetCorrVector(); // .getGPU().resetGeometryCorrectionVector();
quadCLT_aux.resetBayer();
}
System.out.println("batchLwirRig(): processing "+(num_main + num_aux)+" files ("+set_channels.length+" file sets) finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
......
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