Commit 956905bd authored by Andrey Filippov's avatar Andrey Filippov

Extracting parameters

parent 5d8a3045
......@@ -4389,6 +4389,14 @@ public class CuasMotion {
int height = image.length/width;
int xl = xc - icon_width/2;
int yt = yc - icon_height/2;
int xr = xc + icon_width/2;
int yb = yc + icon_height/2;
if ((xl < 0) || (yt < 0) || (xr >= width) || (yb >= height)) {
System.out.println("imprintPixelIcon(): outside of the window: xc="+xc+", yc="+yc+", width="+width+", height="+height);
return;
}
for (int y = 0; y < icon_height; y++) {
int py = yt + y;
if ((py >= 0) && (py < height)) {
......@@ -4469,8 +4477,7 @@ public class CuasMotion {
final double ifov = scene.getGeometryCorrection().getIFOV();
final double radar_range = clt_parameters.imp.cuas_radar_range;
final String font_name = clt_parameters.imp.cuas_font_name;
// final int font_size_radar = clt_parameters.imp.cuas_font_size;
final int font_size_radar = 7; // clt_parameters.imp.cuas_font_size;
final int font_size_radar = clt_parameters.imp.cuas_font_size; // 7; //
final double font_ratio_radar = 1.2; // if 0 - will use default spacing ( ~=1.5)
final int font_type = clt_parameters.imp.cuas_font_type;
final Color text_color = clt_parameters.imp.cuas_text_color;
......@@ -4480,7 +4487,6 @@ public class CuasMotion {
final int target_type = clt_parameters.imp.cuas_target_type; // 0; // 0 - unknown, 1 - known, 2 - friend, 3 - foe
final int uas_type = clt_parameters.imp.cuas_known_type; // 2; // Target location matching UAS flight log: 0; // 0 - unknown, 1 - known, 2 - friend, 3 - foe
final boolean reserve_missing_fields = false; // make a parameter.Reserve a line for requested but missing parameters
final boolean scale2x = true;
final int image_scale = 2; // here always 2
......@@ -4559,6 +4565,7 @@ public class CuasMotion {
final AtomicInteger ai = new AtomicInteger(0);
final AtomicInteger amax = new AtomicInteger(-1);
final int [] uas_tiles = new int[num_seq];
Arrays.fill(uas_tiles, -1);
final int [][] local_tiles = new int [num_seq][];
for (int ithread = 0; ithread < threads.length; ithread++) {
......@@ -4576,6 +4583,7 @@ public class CuasMotion {
if (target != null) {
if (!Double.isNaN(target[CuasMotionLMA.RSLT_FL_PX])) {
local_tiles_map.put(0, ntile); // flight log data
max_ltarg = Math.max(max_ltarg, 0);
}
if (!Double.isNaN(target[CuasMotionLMA.RSLT_GLOBAL])) {
int ltarg = (int) target[CuasMotionLMA.RSLT_GLOBAL];
......@@ -4596,10 +4604,9 @@ public class CuasMotion {
}
ImageDtt.startAndJoin(threads);
final int [][] ltargets_first_last = new int [amax.get()][]; // correct
for (int nseq = 0; nseq < num_seq; nseq++) {
for (int nseq = 0; nseq < num_seq; nseq++) if (local_tiles[nseq].length > 0){ // no if is not needed - bug fixed
uas_tiles[nseq] = local_tiles[nseq][0];
}
......@@ -5177,6 +5184,8 @@ public class CuasMotion {
double xc,
double yc,
double radius) {
int width = colorProcessor.getWidth();
int height = colorProcessor.getHeight();
double radius2 = radius*radius;
int icolor = color.getRGB() | 0xff000000; // needed?
if (color != null) colorProcessor.setColor(color);
......@@ -5184,7 +5193,11 @@ public class CuasMotion {
int y0 = (int) Math.floor(yc - radius);
int x1 = (int) Math.ceil (xc + radius);
int y1 = (int) Math.ceil (yc + radius);
int width = colorProcessor.getWidth();
if ((x0 < 0) || (y0 < 0) || (x1 >= width) || (y1 >= height)) {
System.out.println("drawCircle(): outside of the window: xc="+xc+", yc="+yc+", width="+width+", height="+height+
", color="+ color.toString());
return;
}
int [] pixels = (int[]) colorProcessor.getPixels();
for (int y = y0; y <= y1; y++) {
double dy = y-yc;
......@@ -5193,7 +5206,8 @@ public class CuasMotion {
double dx = x-xc;
double r2 = dx*dx + dy2;
if (r2 <= radius2) {
pixels[x+y*width] = icolor;
pixels[x+y*width] = icolor; // java.lang.ArrayIndexOutOfBoundsException: Index -144985 out of bounds for length 552960 at com.elphel.imagej.cuas.CuasMotion.drawCircle(CuasMotion.java:5197) at com.elphel.imagej.cuas.CuasMotion$33.run(CuasMotion.java:4662)
}
}
}
......@@ -6903,7 +6917,7 @@ public class CuasMotion {
*/
public static int [][][] calcMatchingTargetsLengths( // calculate number of consecutive keyframes connected to each target
final double [][][][] targets_multi,
final boolean calc_linked,
final boolean calc_linked, // needed to calculate indices in the order of lengths. But only when there are few targets
final double max_mismatch, // if <=0, do not calculate mismatch_ba and filter
final double slow_fast_mismatch,
final double match_len_pwr, // 0.5; // raise matching length to this power for calculating score
......@@ -9783,6 +9797,7 @@ public class CuasMotion {
}
final void recalcOmegas(
boolean recalc,
double [][][] target_single,
boolean batch_mode,
int debugLevel){
......@@ -9806,9 +9821,11 @@ public class CuasMotion {
targets_multi, // final double [][][][] targets_multi,
true, // final boolean good_only,
tilesX); // int tilesX) {
if (recalc) {
recalcOmegas(
targets_multi, // double [][][][] targets_multi,
debugLevel); // int debugLevel){
}
getHalfBeforeAfterPixXY(
targets_multi, // final double [][][][] targets_multi,
true, // final boolean good_only,
......
......@@ -78,12 +78,17 @@ public class CuasMultiSeries {
model_dirs = new File[num_series];
model_names = new String[num_series];
this.uasLogReader = uasLogReader;
int dbg_nser = 45;
for (int nser = 0; nser < num_series; nser++) {
model_names[nser] = scene_dirs[nser].getName(); // 1747803230_276111-CENTER
model_dirs[nser] = new File(scene_dirs[nser], version);
String target_file_name = model_names[nser]+ CuasMotion.getParametersSuffixRanging(clt_parameters,CuasRanging.TARGET_DISPARITIES_SUFFIX)+".tiff";
File target_file=new File(model_dirs[nser], target_file_name);
String [][] scen_titles_w = new String[1][];
if (nser==dbg_nser) {
System.out.println("-nser="+nser);
}
targets_multi_series[nser] = CuasMotion.getTargetsFromHyperAugment(
null, // String [][] pvf_top_titles,
scen_titles_w, // String [][] pvf_titles,
......@@ -106,14 +111,23 @@ public class CuasMultiSeries {
break;
}
}
if (i >= linked_targets_multi[nser][ntarg].length) {
targets_start_end[nser][ntarg] = new int[0];
} else {
for ( i++; i < linked_targets_multi[nser][ntarg].length; i++) {
if (linked_targets_multi[nser][ntarg][i] == null) {
break;
}
}
targets_start_end[nser][ntarg][1] = i-1;
// targets_start_end[nser][ntarg][1] = i-1;
// p.y = i-1;
// tlist.add(p);
}
}
}
recalculateAllRanges(
targets_multi_series, // final double [][][][] targets_multi_series, // [nser][nseq][ntile][nfield]
infinity, // final double new_infinity,
......@@ -209,14 +223,17 @@ public class CuasMultiSeries {
double pts_scale = clt_parameters.imp.video_fps/clt_parameters.imp.sensor_fps;
pts_scale = 1.0;
String shellCommand;
//ffmpeg -i input_file.mkv -c copy -metadata:s:v:0 stereo_mode=1 output_file.mkv
//https://ffmpeg.org/ffmpeg-formats.html
//ffmpeg -i sample_left_right_clip.mpg -an -c:v libvpx -metadata stereo_mode=left_right -y stereo_clip.webm
//anaglyph_cyan_red
shellCommand = String.format("ffmpeg -y -f concat -safe 0 -i %s -r 60 -vf setpts=%f*PTS -b:v %fM -crf %d -c %s %s",
list_to_concat.toString(), pts_scale, video_bitrate_m, video_crf_combo, video_codec_combo, video_out.toString());
/*
when called from java, ffmpeg terminated in ~5min and 848MB, but java continued to wait
For now - just run command manually by copying the shellCommand
*/
shellCommand = String.format("ffmpeg -y -f concat -safe 0 -i %s -r 60 -vf setpts=%f*PTS -b:v %fM -crf %d -c %s %s",
list_to_concat.toString(), pts_scale, video_bitrate_m, video_crf_combo, video_codec_combo, video_out.toString());
Process p = null;
int exit_code = -1;
System.out.println("Will run shell command: \""+shellCommand+"\"");
......@@ -280,7 +297,7 @@ public class CuasMultiSeries {
//
ImagePlus imp_radar = testGenerateRadarImage(
clt_parameters, // CLTParameters clt_parameters,
3, // 15, // int nser,
45, // 3, // 15, // int nser,
uasLogReader, // UasLogReader uasLogReader, // contains camera orientation (getCameraATR())
debugLevel); // int debugLevel) {
return;
......@@ -403,10 +420,15 @@ public class CuasMultiSeries {
final Thread[] threads = ImageDtt.newThreadArray();
final AtomicInteger ai = new AtomicInteger(0);
final AtomicInteger amiss = new AtomicInteger(0);
final int dbg_nser = 45;
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nSer = ai.getAndIncrement(); nSer < targets_multi_series.length; nSer = ai.getAndIncrement()) {
if (nSer==dbg_nser) {
System.out.println("-nser="+nSer);
}
for (int nseq = 0; nseq < targets_multi_series[nSer].length; nseq++) {
for (int ntile = 0; ntile < targets_multi_series[nSer][nseq].length; ntile++) {
double [] target = targets_multi_series[nSer][nseq][ntile];
......@@ -441,10 +463,14 @@ public class CuasMultiSeries {
final Thread[] threads = ImageDtt.newThreadArray();
final AtomicInteger ai = new AtomicInteger(0);
final AtomicInteger aglob = new AtomicInteger(0);
final int dbg_nser = 45;
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nSer = ai.getAndIncrement(); nSer < targets_multi_series.length; nSer = ai.getAndIncrement()) {
if (nSer==dbg_nser) {
System.out.println("-nser="+nSer);
}
int [][][] ltargets = linked_targets_multi[nSer];
double [][][] mtargets = targets_multi_series[nSer];
int [] utiles = uas_tiles[nSer];
......@@ -557,7 +583,9 @@ public class CuasMultiSeries {
}
// skip pairs that have global target_id >0 (at least skip UAS
for (int ntarg = 0; ntarg < num_targ; ntarg++) if (!skip_assigned ||(target_map[nSer][ntarg] <= 0)) { // no globally assigned
if (targets_start_end[nSer][ntarg].length > 0) { // now, start,end pair may be [] if all were NaN
for (int ntarg1 = ntarg+1; ntarg1 < num_targ; ntarg1++) if (!skip_assigned || (target_map[nSer][ntarg1] <= 0)) { // no globally assigned
if (targets_start_end[nSer][ntarg1].length > 0) {
if (targets_start_end[nSer][ntarg][1] < targets_start_end[nSer][ntarg1][0]) {
if ((targets_start_end[nSer][ntarg1][0] - targets_start_end[nSer][ntarg][1]) <= tmtch_gaps) {
after[ntarg][ntarg1] = true; // ntarg1 is after ntarg
......@@ -572,6 +600,8 @@ public class CuasMultiSeries {
}
}
}
}
}
local_map[nSer] = new int [num_targ]; // [nser][ntarg]
local_imap[nSer]= new int [num_targ][1]; // [nser][ntarg]
for (int i = 0; i < num_targ; i++) {
......@@ -735,6 +765,7 @@ public class CuasMultiSeries {
if (targs0.length > 0){
int ntarg0 = targs0[targs0.length -1]; // last if several are connected
if (!skip_assigned || (target_map[prev_ser][ntarg0] <= 0)) { // not globally assigned
if (targets_start_end[prev_ser][ntarg0].length > 0) { // now, start,end pair may be [] if all were NaN
int nseq0 = targets_start_end[prev_ser][ntarg0][1]; // end of the last segment in previous series
int end_gap = linked_targets_multi[prev_ser][ntarg0].length -1 - nseq0;
if (end_gap <= tmtch_ends) {
......@@ -746,6 +777,7 @@ public class CuasMultiSeries {
if (targs1.length > 0){
int ntarg1 = targs1[0]; // first if several are connected
if (!skip_assigned || (target_map[nSer][ntarg1] <= 0)) { // no globally assigned
if (targets_start_end[nSer][ntarg1].length > 0) { // now, start,end pair may be [] if all were NaN
int nseq1 = targets_start_end[nSer][ntarg1][0]; // start of the first segment in this series
if (nseq1 <= tmtch_ends) {
int ntile1 = linked_targets_multi[nSer][ntarg1][nseq1][0];
......@@ -839,6 +871,8 @@ public class CuasMultiSeries {
}
}
}
}
}
} // for (int ntgrp0 = 0; ntgrp0 < local_imap[prev_ser].length; ntgrp0++) {
// find and resolve conflicts between pairs
// pair.x is in previous segment (prev_seg), and in case of a chain - the last one
......
......@@ -69,6 +69,8 @@ public class CuasRanging {
boolean rng_img = clt_parameters.imp.cuas_rng_img;
boolean rng_glob = clt_parameters.imp.cuas_rng_glob;
boolean rng_disp = clt_parameters.imp.cuas_rng_disp;
boolean recalc_target_id = true; // temporalily bug fixing, may be removed later
boolean rng_vfy = clt_parameters.imp.cuas_rng_vfy; // Generate/save ranging verification images (per-sensor and combined rendering from the same data)
boolean reset_disparity = clt_parameters.imp.cuas_reset_disparity;
......@@ -282,13 +284,19 @@ public class CuasRanging {
System.out.println ("Recalculating omegas to better fit target positions in consecutive key frames.");
}
cuasMotion.recalcOmegas(
true, // boolean recalc,
targets, // final double [][][] target_single_in,
batch_mode, // boolean batch_mode,
debugLevel); // final int debugLevel){
} else {
cuasMotion.recalcOmegas(
false, // boolean recalc,
targets, // final double [][][] target_single_in,
batch_mode, // boolean batch_mode,
debugLevel); // final int debugLevel){
if (debugLevel > -4) {
System.out.println ("Skipping omegas recalculation omegas.");
System.out.println ("Skipping omegas recalculation omegas, still calculating local target index (called GLOBAL_INDEX).");
}
}
// String model_prefix = center_CLT.getImageName()+CuasMotion.getParametersSuffix(clt_parameters,null);
......@@ -318,6 +326,15 @@ public class CuasRanging {
cuasMotion.getTilesX()); // int tilesX) {
center_CLT.saveImagePlusInModelDirectory(imp_with_range); // ImagePlus imp)
}
} else if (recalc_target_id){// if (disparity_targets == null) {
cuasMotion.recalcOmegas(
false, // boolean recalc,
targets, // final double [][][] target_single_in,
batch_mode, // boolean batch_mode,
debugLevel); // final int debugLevel){
if (debugLevel > -4) {
System.out.println ("(Re)calculating local target index (called GLOBAL_INDEX). May be remolved later");
}
}
}
// calculate range from disparity
......
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