Commit 47f52836 authored by Andrey Filippov's avatar Andrey Filippov

Debugging/fixing with Codex

parent 0c711ac1
......@@ -269,6 +269,19 @@ public class CuasMotion {
CLTParameters clt_parameters) {
return clt_parameters.imp.cuas_half_step ? (clt_parameters.imp.cuas_corr_offset/2) : clt_parameters.imp.cuas_corr_offset;
}
/**
* Geometric separation between adjacent keyframes in scene units.
*
* When {@code cuas_half_step} is enabled and {@code cuas_corr_offset} is odd, the
* actual scan index advance returned by {@link #getCorrInc(CLTParameters)} is truncated
* to an integer scene step. For chaining targets between neighboring keyframes we need
* the intended half-offset geometry rather than the truncated array index increment.
*/
public static double getCorrIncExact(
CLTParameters clt_parameters) {
return clt_parameters.imp.cuas_half_step ? (0.5 * clt_parameters.imp.cuas_corr_offset) : clt_parameters.imp.cuas_corr_offset;
}
public int getCorrInc() { // == frame_step;
return getCorrInc(clt_parameters);
......@@ -285,17 +298,12 @@ public class CuasMotion {
}
public double getInterseqScale() { // multiply target velocity to get offset in the middle between the key frames
// double inter_scale = 0.5* getCorrInc()/corr_offset;
double inter_scale = 0.5*1.25 * getCorrInc()/corr_offset;
System.out.println("getInterseqScale(): getCorrInc()="+getCorrInc()+" corr_offset="+corr_offset+
" clt_parameters.imp.cuas_half_step="+clt_parameters.imp.cuas_half_step+
" clt_parameters.imp.cuas_corr_offset="+clt_parameters.imp.cuas_corr_offset+
" inter_scale="+inter_scale);
return inter_scale; // 0.5* getCorrInc()/corr_offset;
return 0.5 * getCorrIncExact(clt_parameters) / corr_offset;
}
/**
* Multiply RESULT_VX,RESULT_VX to get pixel offset per scene (at ~60Hz)
* Multiply raw {@code RSLT_VX}/{@code RSLT_VY} pair displacement by this factor
* to get pixel offset per scene (at ~60Hz).
* @param clt_parameters
* @return coefficient for VX, VY
*/
......@@ -304,12 +312,13 @@ public class CuasMotion {
}
/**
* Multiply RESULT_VX,RESULT_VX to get pixel offset per key frame (now ~6Hz)
* Multiply raw {@code RSLT_VX}/{@code RSLT_VY} pair displacement by this factor
* to get pixel offset between neighboring keyframe centers.
* @param clt_parameters
* @return coefficient for VX, VY
*/
public static double getKeyFrameVelocityScale(CLTParameters clt_parameters) {
return getCorrInc(clt_parameters)/clt_parameters.imp.cuas_corr_offset;
return getCorrIncExact(clt_parameters)/clt_parameters.imp.cuas_corr_offset;
}
......@@ -1451,6 +1460,9 @@ public class CuasMotion {
true); // final boolean calc_fraction ){ // calculate fraction inside center circle
for (int ntile = 0; ntile < num_tiles; ntile++) if (vector_field[ntile] != null){
double [] target = CuasMotionLMA.getEmpty();
// Store the raw displacement over one correlation-pair separation
// (cuas_corr_offset scenes). Convert later with getFrameVelocityScale()
// or getKeyFrameVelocityScale() depending on the consumer.
target[CuasMotionLMA.RSLT_VX] = vector_field[ntile][INDX_VX];
target[CuasMotionLMA.RSLT_VY] = vector_field[ntile][INDX_VY];
target[CuasMotionLMA.RSLT_VSTR] = vector_field[ntile][INDX_STRENGTH];
......@@ -2820,7 +2832,15 @@ public class CuasMotion {
}
ImageDtt.startAndJoin(threads);
final int [][] ltargets_first_last = new int [amax.get()][]; // correct
final int max_ltarg_all = amax.get();
if (max_ltarg_all < 0) {
System.out.println(
"convertToRgbAnnotateTargets(): no detected targets or UAS-log targets available for annotation in \"" +
title + "\"; returning RGB stack without target overlays.");
return imp;
}
final int [][] ltargets_first_last = new int [max_ltarg_all][]; // correct
for (int nseq = 0; nseq < num_seq; nseq++) if ((local_tiles[nseq] != null) && (local_tiles[nseq].length > 0)){ // no if is not needed - bug fixed
uas_tiles[nseq] = local_tiles[nseq][0];
......@@ -2925,7 +2945,10 @@ public class CuasMotion {
final int [] targets_order = Arrays.stream(targets_order_integer).mapToInt(Integer::intValue).toArray();
// plot targets
// now target_coord is ordered from highest priority to the lowest
// now target_coord is ordered from highest priority to the lowest java.lang.NegativeArraySizeException: -1
if (local_tiles[nSeq].length == 0) {
continue;
}
double [][][] target_coord = new double [local_tiles[nSeq].length-1][][]; // save centers of targets and text coordinates
Rectangle [][] annot_boxes = new Rectangle[local_tiles[nSeq].length-1][]; // order will match target_coord order
String [][] annots = new String [local_tiles[nSeq].length-1][];
......@@ -3706,6 +3729,7 @@ public class CuasMotion {
boolean show_inf_gt = clt_parameters.imp.cuas_show_inf_gt; // false; // Use ">max" instead of infinity symbol
double max_annot_range = clt_parameters.imp.cuas_rng_limit; // 5000, maybe make a separate parameter
double max_axial_range = clt_parameters.imp.cuas_radar_range; // may be a separate - maximal range for axial velocity/heading
double velocity_scale = getFrameVelocityScale(clt_parameters);
double ifov = ersCorrection.getIFOV();
int sensor_width = ersCorrection.getSensorWH()[0];
int sensor_height = ersCorrection.getSensorWH()[1];
......@@ -3767,9 +3791,10 @@ public class CuasMotion {
while (el < -Math.PI) el += 2* Math.PI;
double az_deg = az * 180/Math.PI;
double el_deg = el * 180/Math.PI;
double omega_az = interpolate (target0[CuasMotionLMA.RSLT_VX],target1[CuasMotionLMA.RSLT_VX],k) * ifov * fps;
double omega_el = -interpolate (target0[CuasMotionLMA.RSLT_VY],target1[CuasMotionLMA.RSLT_VY],k) * ifov * fps;
double vx = interpolate (target0[CuasMotionLMA.RSLT_VX],target1[CuasMotionLMA.RSLT_VX],k) * velocity_scale;
double vy = interpolate (target0[CuasMotionLMA.RSLT_VY],target1[CuasMotionLMA.RSLT_VY],k) * velocity_scale;
double omega_az = vx * ifov * fps;
double omega_el = -vy * ifov * fps;
double omega_az_degs = omega_az * 180/Math.PI;
double omega_el_degs = omega_el * 180/Math.PI;
......@@ -3924,8 +3949,8 @@ public class CuasMotion {
* @param fps
* @param px
* @param py
* @param vx
* @param vy
* @param vx target velocity in pixels per frame
* @param vy target velocity in pixels per frame
* @return
*/
public static double [][] getPixToAzElev(
......@@ -4898,7 +4923,7 @@ public class CuasMotion {
// final int min_keep = 2; // Keep at least this number of (preliminary) best candidates
final int tile1 = GPUTileProcessor.DTT_SIZE;
final int tile2 = 2 * tile1;
final int dbg_tile=12 + 23*80;
final int dbg_tile=-(12 + 23*80);
final double [] mask_centered = (centered && (centered_radius > 0)) ? new double [tile2* tile2]: null;
final boolean [] disabled_centered = (mask_centered != null) ? (new boolean [mask_centered.length]) : null;
if (mask_centered != null) {
......@@ -4955,7 +4980,7 @@ public class CuasMotion {
param_select[CuasMotionLMA.INDX_RR0] = lma_fit_r;
param_select[CuasMotionLMA.INDX_K] = lma_fit_k;
// final int dbg_tile = -(38 + 45 * 80); //(38 + 45 * 80);
final int dbg_seq = 48;
final int dbg_seq = -48;
boolean show_dbg = (dbg_tile >= 0) && (parentCLT != null);
final String [] dbg_titles = {"mask","tile","masked","limited","blured","um","um-blured","um-blured-scaled",
"centroid","lma-Y","fX","ymfx","weights"};
......@@ -7380,7 +7405,7 @@ public class CuasMotion {
final int debugLevel){
final boolean use_motion = (motion_sequence != null) ? use_motion_in : false;
final boolean select_new = (motion_sequence != null) ? select_new_in : false;
boolean debug_now = (debugLevel>-5);
boolean debug_now = (debugLevel>5);
final int num_seq = target_sequence_multi.length;
final int num_tiles = target_sequence_multi[0].length;
final int tilesY = num_tiles/ tilesX;
......
......@@ -2788,6 +2788,7 @@ public class CuasRanging {
sb.append("\n"); // there will be 1 extra blank column
String [] slice_titles = cuasMotion.getSliceTitles(); // timestamps
ErsCorrection ersCorrection = center_CLT.getErsCorrection();
double velocity_scale = CuasMotion.getFrameVelocityScale(clt_parameters);
for (int nseq = 0; nseq < num_seq; nseq++) {
String timestamp = slice_titles[nseq];
sb.append(nseq+"\t"+timestamp+"\t");
......@@ -2820,8 +2821,8 @@ public class CuasRanging {
int tileY = ntile / tilesX;
double xc = tileSize * tileX + tileSize/2 + target[CuasMotionLMA.RSLT_X];
double yc = tileSize * tileY + tileSize/2 + target[CuasMotionLMA.RSLT_Y];
double vx = target[CuasMotionLMA.RSLT_VX];
double vy = target[CuasMotionLMA.RSLT_VY];
double vx = target[CuasMotionLMA.RSLT_VX] * velocity_scale;
double vy = target[CuasMotionLMA.RSLT_VY] * velocity_scale;
// calculate and output target azimuth, elevation, disparity (full) and range
az_el_oaz_oel= CuasMotion.getPixToAzElev(
ersCorrection, // ErsCorrection ersCorrection,
......
......@@ -5782,6 +5782,11 @@ public class OpticalFlow {
OK = earliest_scene >=0;
}
if (!OK) {
if (use_cuas) {
System.out.println(
"buildSeries(): aborting CUAS sequence after failed initial orientations. " +
"Input IMS/orientation data appear inconsistent, so no automatic recovery will be attempted.");
}
return null;
}
// export csv
......@@ -7233,7 +7238,7 @@ java.lang.NullPointerException
// Moved to the very end, after 3D
// boolean test_vegetation = true;
if (master_CLT.hasCenterClt()) { // cuas mode
if (master_CLT.hasCenterClt() && clt_parameters.imp.cuas_targets_en) { // cuas mode
if (debugLevel >-3) {
System.out.println("===== Running CUAS ranging. =====");
}
......
......@@ -549,6 +549,7 @@ public class QuadCLTCPU {
dts = center_CLT.getTimeStamp();
}
}
CuasData localCuasData = cuasData;
// Read parent (cumulative if possible) data if full_path is provided
CuasData parentCuasData = null;
if (center_CLT == null) {
......@@ -650,6 +651,38 @@ public class QuadCLTCPU {
if (full_path != null) { // set/update parent directory where to look for cumulative data
center_CLT.setCenterParentDir(full_path); // is not in cuasData, only in center_CLT instance
}
String centerBasePath = center_CLT.getImagePath()+Prefs.getFileSeparator()+center_CLT.getImageName();
String centerSinglePath = centerBasePath + CuasData.getCuasSuffix();
String centerCumulPath = centerBasePath + CuasData.getCuasCumulativeSuffix();
File centerSingleFile = new File(centerSinglePath);
File centerCumulFile = new File(centerCumulPath);
if (!centerSingleFile.exists() || !centerCumulFile.exists()) {
System.out.println(
"restoreCenterClt(): WARNING reused center data in "+center_CLT.getImagePath()+
", but serialized CuasData files are incomplete: single="+centerSingleFile.exists()+
", cumulative="+centerCumulFile.exists()+
". Backfilling from restored data.");
try {
if (!centerSingleFile.exists()) {
CuasData singleCuasData = (localCuasData != null) ? localCuasData : cuasData;
singleCuasData.writeCuasData(centerSinglePath);
if (debugLevel > -3) {
String source = (localCuasData != null) ? "local single-sequence data" : "effective restored data";
System.out.println("restoreCenterClt(): wrote missing single-scene CuasData to "+centerSinglePath+
" using "+source);
}
}
if (!centerCumulFile.exists()) {
cuasData.writeCuasData(centerCumulPath);
if (debugLevel > -3) {
System.out.println("restoreCenterClt(): wrote missing cumulative CuasData to "+centerCumulPath);
}
}
} catch (IOException e) {
System.out.println("restoreCenterClt(): ERROR backfilling serialized CuasData files for "+center_CLT.getImagePath());
e.printStackTrace();
}
}
return center_CLT;
}
......@@ -2400,20 +2433,44 @@ public class QuadCLTCPU {
int xr = (int) Math.round((offset[0] + (s+1)*width)/tile_size);
int yt = (int) Math.round((offset[1] - s* height)/tile_size);
int yb = (int) Math.round((offset[1] + (s+1)*height)/tile_size);
if (yt > 0) {
Arrays.fill(relable_scene_tiles, 0, tilesX * yt, false);
int x0 = Math.max(0, Math.min(tilesX, xl));
int x1 = Math.max(0, Math.min(tilesX, xr));
int y0 = Math.max(0, Math.min(tilesY, yt));
int y1 = Math.max(0, Math.min(tilesY, yb));
boolean clipped = (x0 != xl) || (x1 != xr) || (y0 != yt) || (y1 != yb);
if ((x0 >= x1) || (y0 >= y1)) {
System.out.println(
"maskByOverlap(): no overlap after clipping, offset=(" + offset[0] + ", " + offset[1] +
"), raw x=[" + xl + ", " + xr + "), y=[" + yt + ", " + yb +
"), clipped x=[" + x0 + ", " + x1 + "), y=[" + y0 + ", " + y1 +
"), tiles=" + tilesX + "x" + tilesY + ", image=" + width + "x" + height);
Arrays.fill(relable_scene_tiles, false);
return relable_scene_tiles;
}
if (yb < tilesY) {
Arrays.fill(relable_scene_tiles, tilesX * yb, relable_scene_tiles.length, false);
if (clipped) {
System.out.println(
"maskByOverlap(): clipped overlap bounds, offset=(" + offset[0] + ", " + offset[1] +
"), raw x=[" + xl + ", " + xr + "), y=[" + yt + ", " + yb +
"), clipped x=[" + x0 + ", " + x1 + "), y=[" + y0 + ", " + y1 +
"), tiles=" + tilesX + "x" + tilesY + ", image=" + width + "x" + height);
}
if (xl > 0) {
for (int i = 0; i < tilesY; i++) {
Arrays.fill(relable_scene_tiles, tilesX * i, tilesX * i + xl, false);
}
if (y0 > 0) {
Arrays.fill(relable_scene_tiles, 0, Math.min(relable_scene_tiles.length, tilesX * y0), false);
}
if (y1 < tilesY) {
Arrays.fill(relable_scene_tiles, Math.min(relable_scene_tiles.length, tilesX * y1), relable_scene_tiles.length, false);
}
if (xr < tilesX) {
for (int i = 0; i < tilesY; i++) {
Arrays.fill(relable_scene_tiles, tilesX * i + xr, tilesX * (i + 1), false); //java.lang.IllegalArgumentException: fromIndex(9) > toIndex(0)
for (int i = 0; i < tilesY; i++) {
int rowStart = tilesX * i;
if (rowStart >= relable_scene_tiles.length) {
break;
}
int rowEnd = Math.min(relable_scene_tiles.length, tilesX * (i + 1));
if (x0 > 0) {
Arrays.fill(relable_scene_tiles, rowStart, Math.min(rowEnd, rowStart + x0), false);
}
if (x1 < tilesX) {
Arrays.fill(relable_scene_tiles, Math.min(rowEnd, rowStart + x1), rowEnd, false);
}
}
return relable_scene_tiles;
......
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