Skip to content

Commit

Permalink
GeoRef: add min shutter drop, fix text console, show cam msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
meee1 committed Jan 3, 2023
1 parent 3645236 commit f005467
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 66 deletions.
89 changes: 65 additions & 24 deletions ExtLibs/Utilities/GeoRefImageBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
Expand All @@ -19,6 +20,7 @@
using MissionPlanner.Utilities;
using SharpKml.Base;
using SharpKml.Dom;
using Document = SharpKml.Dom.Document;

namespace MissionPlanner.GeoRef
{
Expand All @@ -41,6 +43,9 @@ public class GeoRefImageBase
public bool useAMSLAlt;
public int millisShutterLag = 0;

public Dictionary<long, VehicleLocation> camLocations { get; private set; }
public double minshutter { get; set; } = 0.5;

/// <summary>
/// Get a photos shutter time
/// </summary>
Expand Down Expand Up @@ -220,7 +225,7 @@ public Dictionary<long, VehicleLocation> readGPSMsgInLog(string fn, string gpsto

try
{
location.Time = item.time;
location.Time = item.time.ToUniversalTime();

if (statusindex != -1)
{
Expand Down Expand Up @@ -492,9 +497,10 @@ public double EstimateOffset(string logFile, string dirWithImages, string UseGps
{
if (vehicleLocations == null || vehicleLocations.Count <= 0)
{
camLocations = readCAMMsgInLog(logFile);
if (usecam)
{
vehicleLocations = readCAMMsgInLog(logFile);
{
vehicleLocations = camLocations;
}
else
{
Expand All @@ -517,11 +523,17 @@ public double EstimateOffset(string logFile, string dirWithImages, string UseGps
if (files == null || files.Length == 0)
return -1;

// load all image info
Parallel.ForEach(files, filename => { getPhotoTime(filename); });

// sort
Array.Sort(files, compareFileByPhotoTime);

double ans = 0;

for (int a = 0; a < 4; a++)
int[] itemstocheck = new int[] { 0, 1, 2, 3, files.Length - 3, files.Length - 2, files.Length - 1 };

foreach (int a in itemstocheck)
{
// First Photo time
string firstPhoto = files[a];
Expand Down Expand Up @@ -555,27 +567,27 @@ private VehicleLocation LookForLocation(DateTime t, Dictionary<long, VehicleLoca
{
long time = ToMilliseconds(t);

// Time at which the GPS position is actually search and found
long actualTime = time;
int millisSTEP = 1;

// 2 seconds (2000 ms) in the log as absolute maximum
int maxIteration = offsettime;
int maxIteration = offsettime / 2;

bool found = false;
int iteration = 0;
VehicleLocation location = null;

while (!found && iteration < maxIteration)
{
found = listLocations.ContainsKey(actualTime);
found = listLocations.ContainsKey(time + iteration);
if (found)
{
location = listLocations[actualTime];
location = listLocations[time + iteration];
}
else
{
actualTime += millisSTEP;
found = listLocations.ContainsKey(time - iteration);
if (found)
{
location = listLocations[time - iteration];
}
iteration++;
}
}
Expand All @@ -597,11 +609,12 @@ public Dictionary<string, PictureInformation> doworkGPSOFFSET(string logFile, st
// Read Vehicle Locations from log. GPS Messages. Will have to do it anyway
if (vehicleLocations == null || vehicleLocations.Count <= 0)
{
AppendText("Reading log for CAM Messages\n");
camLocations = readCAMMsgInLog(logFile);

if (usecam)
{
AppendText("Reading log for CAM Messages\n");

vehicleLocations = readCAMMsgInLog(logFile);
vehicleLocations = camLocations;
}
else
{
Expand Down Expand Up @@ -742,19 +755,35 @@ public Dictionary<string, PictureInformation> doworkCAM(string logFile, string d

AppendText("Reading log for CAM Messages\n");

var list = readCAMMsgInLog(logFile);
camLocations = readCAMMsgInLog(logFile);

if (list == null)
if (camLocations == null)
{
AppendText("Log file problem. No CAM messages. Aborting....\n");
return null;
}

AppendText("Log Read with - " + camLocations.Count + " - CAM Messages found\n");

camLocations = camLocations.Take(camLocations.Count/* - dropend*/).Skip(dropstart).ToDictionary(a => a.Key, a => a.Value);

AppendText("Log Read with - " + list.Count + " - CAM Messages found\n");
var deltalistv = camLocations
.PrevNowNext(InvalidValue: new KeyValuePair<long, VehicleLocation>(0,
new VehicleLocation() { Time = DateTime.MinValue }))
.Select(d => ((d.Item3.Value.Time - d.Item2.Value.Time), d.Item2)).ToList();

list = list.Take(list.Count - dropend).Skip(dropstart).ToDictionary(a => a.Key, a => a.Value);
if (deltalistv.Any(a => a.Item1.TotalSeconds > 0 && a.Item1.TotalSeconds < minshutter))
{
AppendText("Possible Shutter speed issue - " +
deltalistv.Min(a => a.Item1.TotalSeconds > 0 ? a.Item1.TotalSeconds : 9999) + "s\n");

var minitem = deltalistv.Where(a => a.Item1.TotalSeconds > 0 && a.Item1.TotalSeconds < 0.5).First()
.Item2;

camLocations.Remove(minitem.Key);
}

AppendText("Filtered - " + list.Count + " - CAM Messages found\n");
AppendText("Filtered - " + camLocations.Count + " - CAM Messages found\n");

AppendText("Read images\n");

Expand All @@ -764,22 +793,30 @@ public Dictionary<string, PictureInformation> doworkCAM(string logFile, string d
AppendText("Images read : " + files.Count + "\n");

// Check that we have same number of CAMs than files
if (files.Count != list.Count)
if (files.Count != camLocations.Count)
{
AppendText(string.Format("CAM Msgs and Files discrepancy. Check it! files: {0} vs CAM msg: {1}\n",files.Count,list.Count));
return null;
AppendText(string.Format("CAM Msgs and Files discrepancy. Check it! files: {0} vs CAM msg: {1}\n",files.Count,camLocations.Count));
//return null;
}

// load all image info
Parallel.ForEach(files, filename => { getPhotoTime(filename); });

// sort
files.Sort(compareFileByPhotoTime);

// Each file corresponds to one CAM message
// We assume that picture names are in ascending order in time
int i = -1;
foreach (var currentCAM in list.Values)
foreach (var currentCAM in camLocations.Values)
{
i++;
PictureInformation p = new PictureInformation();

if(files.Count <= i)
continue;


// Fill shot time in Picture
p.ShotTimeReportedByCamera = getPhotoTime(files[i]);

Expand Down Expand Up @@ -958,6 +995,10 @@ public Dictionary<string, PictureInformation> doworkTRIG(string logFile, string
return null;
}

// load all image info
Parallel.ForEach(files, filename => { getPhotoTime(filename); });

// sort
files.Sort(compareFileByPhotoTime);

// Each file corresponds to one CAM message
Expand Down
79 changes: 60 additions & 19 deletions GeoRef/Georefimage.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f005467

Please sign in to comment.