From f005467b8db4f6edfce29b5bdd1c98a09a58e5a4 Mon Sep 17 00:00:00 2001 From: Michael Oborne Date: Tue, 3 Jan 2023 21:17:10 +1100 Subject: [PATCH] GeoRef: add min shutter drop, fix text console, show cam msgs --- ExtLibs/Utilities/GeoRefImageBase.cs | 89 +++++++++++++++++++-------- GeoRef/Georefimage.Designer.cs | 79 ++++++++++++++++++------ GeoRef/georefimage.cs | 26 +++++++- GeoRef/georefimage.resx | 91 ++++++++++++++++++++++------ 4 files changed, 219 insertions(+), 66 deletions(-) diff --git a/ExtLibs/Utilities/GeoRefImageBase.cs b/ExtLibs/Utilities/GeoRefImageBase.cs index 22f9517d42..ac12e1f8fa 100644 --- a/ExtLibs/Utilities/GeoRefImageBase.cs +++ b/ExtLibs/Utilities/GeoRefImageBase.cs @@ -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; @@ -19,6 +20,7 @@ using MissionPlanner.Utilities; using SharpKml.Base; using SharpKml.Dom; +using Document = SharpKml.Dom.Document; namespace MissionPlanner.GeoRef { @@ -41,6 +43,9 @@ public class GeoRefImageBase public bool useAMSLAlt; public int millisShutterLag = 0; + public Dictionary camLocations { get; private set; } + public double minshutter { get; set; } = 0.5; + /// /// Get a photos shutter time /// @@ -220,7 +225,7 @@ public Dictionary readGPSMsgInLog(string fn, string gpsto try { - location.Time = item.time; + location.Time = item.time.ToUniversalTime(); if (statusindex != -1) { @@ -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 { @@ -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]; @@ -555,12 +567,8 @@ private VehicleLocation LookForLocation(DateTime t, Dictionary 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 { @@ -742,19 +755,35 @@ public Dictionary 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(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"); @@ -764,22 +793,30 @@ public Dictionary 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]); @@ -958,6 +995,10 @@ public Dictionary 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 diff --git a/GeoRef/Georefimage.Designer.cs b/GeoRef/Georefimage.Designer.cs index 60672808bf..fc3d54adb3 100644 --- a/GeoRef/Georefimage.Designer.cs +++ b/GeoRef/Georefimage.Designer.cs @@ -43,6 +43,10 @@ private void InitializeComponent() this.num_hfov = new System.Windows.Forms.NumericUpDown(); this.num_vfov = new System.Windows.Forms.NumericUpDown(); this.panel3 = new System.Windows.Forms.Panel(); + this.label3 = new System.Windows.Forms.Label(); + this.num_minshutter = new System.Windows.Forms.NumericUpDown(); + this.label2 = new System.Windows.Forms.Label(); + this.num_dropend = new System.Windows.Forms.NumericUpDown(); this.lbldrpstart = new System.Windows.Forms.Label(); this.num_dropfromstart = new System.Windows.Forms.NumericUpDown(); this.chk_usegps2 = new System.Windows.Forms.CheckBox(); @@ -58,17 +62,16 @@ private void InitializeComponent() this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.chk_camusegpsalt = new System.Windows.Forms.CheckBox(); this.chk_trigusergpsalt = new System.Windows.Forms.CheckBox(); - this.num_dropend = new System.Windows.Forms.NumericUpDown(); - this.label2 = new System.Windows.Forms.Label(); this.PANEL_TIME_OFFSET.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.num_camerarotation)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.num_hfov)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.num_vfov)).BeginInit(); this.panel3.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.num_minshutter)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.num_dropend)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.num_dropfromstart)).BeginInit(); this.PANEL_SHUTTER_LAG.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.num_dropend)).BeginInit(); this.SuspendLayout(); // // openFileDialog1 @@ -106,6 +109,7 @@ private void InitializeComponent() // resources.ApplyResources(this.BUT_Geotagimages, "BUT_Geotagimages"); this.BUT_Geotagimages.Name = "BUT_Geotagimages"; + this.BUT_Geotagimages.TextColorNotEnabled = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(87)))), ((int)(((byte)(4))))); this.BUT_Geotagimages.UseVisualStyleBackColor = true; this.BUT_Geotagimages.Click += new System.EventHandler(this.BUT_Geotagimages_Click); // @@ -113,6 +117,7 @@ private void InitializeComponent() // resources.ApplyResources(this.BUT_estoffset, "BUT_estoffset"); this.BUT_estoffset.Name = "BUT_estoffset"; + this.BUT_estoffset.TextColorNotEnabled = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(87)))), ((int)(((byte)(4))))); this.BUT_estoffset.UseVisualStyleBackColor = true; this.BUT_estoffset.Click += new System.EventHandler(this.BUT_estoffset_Click); // @@ -120,6 +125,7 @@ private void InitializeComponent() // resources.ApplyResources(this.BUT_doit, "BUT_doit"); this.BUT_doit.Name = "BUT_doit"; + this.BUT_doit.TextColorNotEnabled = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(87)))), ((int)(((byte)(4))))); this.BUT_doit.UseVisualStyleBackColor = true; this.BUT_doit.Click += new System.EventHandler(this.BUT_doit_Click); // @@ -127,6 +133,7 @@ private void InitializeComponent() // resources.ApplyResources(this.BUT_browsedir, "BUT_browsedir"); this.BUT_browsedir.Name = "BUT_browsedir"; + this.BUT_browsedir.TextColorNotEnabled = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(87)))), ((int)(((byte)(4))))); this.BUT_browsedir.UseVisualStyleBackColor = true; this.BUT_browsedir.Click += new System.EventHandler(this.BUT_browsedir_Click); // @@ -134,6 +141,7 @@ private void InitializeComponent() // resources.ApplyResources(this.BUT_browselog, "BUT_browselog"); this.BUT_browselog.Name = "BUT_browselog"; + this.BUT_browselog.TextColorNotEnabled = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(87)))), ((int)(((byte)(4))))); this.BUT_browselog.UseVisualStyleBackColor = true; this.BUT_browselog.Click += new System.EventHandler(this.BUT_browselog_Click); // @@ -141,6 +149,7 @@ private void InitializeComponent() // resources.ApplyResources(this.BUT_networklinkgeoref, "BUT_networklinkgeoref"); this.BUT_networklinkgeoref.Name = "BUT_networklinkgeoref"; + this.BUT_networklinkgeoref.TextColorNotEnabled = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(87)))), ((int)(((byte)(4))))); this.BUT_networklinkgeoref.UseVisualStyleBackColor = true; this.BUT_networklinkgeoref.Click += new System.EventHandler(this.BUT_networklinkgeoref_Click); // @@ -247,6 +256,8 @@ private void InitializeComponent() // panel3 // this.panel3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.panel3.Controls.Add(this.label3); + this.panel3.Controls.Add(this.num_minshutter); this.panel3.Controls.Add(this.label2); this.panel3.Controls.Add(this.num_dropend); this.panel3.Controls.Add(this.lbldrpstart); @@ -264,6 +275,48 @@ private void InitializeComponent() resources.ApplyResources(this.panel3, "panel3"); this.panel3.Name = "panel3"; // + // label3 + // + resources.ApplyResources(this.label3, "label3"); + this.label3.Name = "label3"; + // + // num_minshutter + // + this.num_minshutter.DecimalPlaces = 2; + this.num_minshutter.Increment = new decimal(new int[] { + 1, + 0, + 0, + 131072}); + resources.ApplyResources(this.num_minshutter, "num_minshutter"); + this.num_minshutter.Maximum = new decimal(new int[] { + 99, + 0, + 0, + 0}); + this.num_minshutter.Name = "num_minshutter"; + this.num_minshutter.Value = new decimal(new int[] { + 5, + 0, + 0, + 65536}); + this.num_minshutter.ValueChanged += new System.EventHandler(this.num_minshutter_ValueChanged); + // + // label2 + // + resources.ApplyResources(this.label2, "label2"); + this.label2.Name = "label2"; + // + // num_dropend + // + resources.ApplyResources(this.num_dropend, "num_dropend"); + this.num_dropend.Maximum = new decimal(new int[] { + 900, + 0, + 0, + 0}); + this.num_dropend.Name = "num_dropend"; + // // lbldrpstart // resources.ApplyResources(this.lbldrpstart, "lbldrpstart"); @@ -380,21 +433,6 @@ private void InitializeComponent() this.chk_trigusergpsalt.Name = "chk_trigusergpsalt"; this.chk_trigusergpsalt.UseVisualStyleBackColor = true; // - // num_dropend - // - resources.ApplyResources(this.num_dropend, "num_dropend"); - this.num_dropend.Maximum = new decimal(new int[] { - 900, - 0, - 0, - 0}); - this.num_dropend.Name = "num_dropend"; - // - // label2 - // - resources.ApplyResources(this.label2, "label2"); - this.label2.Name = "label2"; - // // Georefimage // resources.ApplyResources(this, "$this"); @@ -427,11 +465,12 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.num_vfov)).EndInit(); this.panel3.ResumeLayout(false); this.panel3.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.num_minshutter)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.num_dropend)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.num_dropfromstart)).EndInit(); this.PANEL_SHUTTER_LAG.ResumeLayout(false); this.PANEL_SHUTTER_LAG.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.num_dropend)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -476,5 +515,7 @@ private void InitializeComponent() private NumericUpDown num_dropfromstart; private Label label2; private NumericUpDown num_dropend; + private Label label3; + private NumericUpDown num_minshutter; } } \ No newline at end of file diff --git a/GeoRef/georefimage.cs b/GeoRef/georefimage.cs index d389990287..5bd95014a3 100644 --- a/GeoRef/georefimage.cs +++ b/GeoRef/georefimage.cs @@ -7,6 +7,7 @@ using System.IO; using System.Text.RegularExpressions; using System.Windows.Forms; +using MissionPlanner.Maps; namespace MissionPlanner.GeoRef { @@ -75,7 +76,7 @@ private void AppendText(string text) var inv = new MethodInvoker(delegate { - text.Replace("\n", Environment.NewLine); + text = text.Replace("\n", Environment.NewLine); TXT_outputlog.AppendText(text); TXT_outputlog.Refresh(); }); @@ -91,7 +92,7 @@ private void BUT_browselog_Click(object sender, EventArgs e) if (File.Exists(openFileDialog1.FileName)) { TXT_logfile.Text = openFileDialog1.FileName; - TXT_jpgdir.Text = Path.GetDirectoryName(TXT_logfile.Text); + TXT_jpgdir.Text = Path.GetDirectoryName(TXT_logfile.Text); } } @@ -161,6 +162,7 @@ private void BUT_doit_Click(object sender, EventArgs e) BUT_doit.Enabled = false; TXT_outputlog.Clear(); + myGMAP1.Overlays[0].Markers.Clear(); try { @@ -199,6 +201,7 @@ private void BUT_doit_Click(object sender, EventArgs e) log.Info("Draw to Map"); + GMapRoute route = new GMapRoute("vehicle"); if (georef.vehicleLocations != null) { @@ -209,7 +212,19 @@ private void BUT_doit_Click(object sender, EventArgs e) } } - myGMAP1.Overlays[0].Markers.Clear(); + if (georef.camLocations != null) + { + ushort a = 0; + foreach (var vehicleLocation in georef.camLocations) + { + myGMAP1.Overlays[0].Markers.Add(new GMapMarkerPhoto( + new MAVLink.mavlink_camera_feedback_t((ulong)vehicleLocation.Key, + (int)(vehicleLocation.Value.Lat * 1e7), + (int)(vehicleLocation.Value.Lon * 1e7), (float)vehicleLocation.Value.AltAMSL, + (float)vehicleLocation.Value.RelAlt, 0, 0, 0, 0, a++, 0, 0, 0, 0))); + } + } + if (georef.picturesInfo != null) { foreach (var pictureLocation in georef.picturesInfo) @@ -369,5 +384,10 @@ private void chk_usegps2_CheckedChanged(object sender, EventArgs e) if (georef.vehicleLocations != null) georef.vehicleLocations.Clear(); } + + private void num_minshutter_ValueChanged(object sender, EventArgs e) + { + georef.minshutter = (double)num_minshutter.Value; + } } } \ No newline at end of file diff --git a/GeoRef/georefimage.resx b/GeoRef/georefimage.resx index 35f43ec3d0..6f040aa179 100644 --- a/GeoRef/georefimage.resx +++ b/GeoRef/georefimage.resx @@ -547,7 +547,7 @@ NoControl - 258, 9 + 374, 9 47, 13 @@ -568,10 +568,10 @@ panel3 - 9 + 11 - 261, 25 + 377, 25 42, 20 @@ -589,7 +589,7 @@ panel3 - 11 + 13 True @@ -598,7 +598,7 @@ NoControl - 311, 9 + 427, 9 51, 13 @@ -619,7 +619,7 @@ panel3 - 8 + 10 True @@ -628,7 +628,7 @@ NoControl - 202, 10 + 318, 10 38, 13 @@ -649,10 +649,10 @@ panel3 - 13 + 15 - 314, 25 + 430, 25 42, 20 @@ -670,10 +670,10 @@ panel3 - 12 + 14 - 205, 26 + 321, 26 42, 20 @@ -691,7 +691,58 @@ panel3 - 10 + 12 + + + True + + + NoControl + + + 140, 10 + + + 107, 13 + + + 49 + + + Min Shutter (s) (CAM) + + + label3 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel3 + + + 0 + + + 143, 25 + + + 53, 20 + + + 48 + + + num_minshutter + + + System.Windows.Forms.NumericUpDown, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel3 + + + 1 True @@ -721,7 +772,7 @@ panel3 - 0 + 2 34, 64 @@ -742,7 +793,7 @@ panel3 - 1 + 3 True @@ -772,7 +823,7 @@ panel3 - 2 + 4 34, 25 @@ -793,7 +844,7 @@ panel3 - 3 + 5 True @@ -823,7 +874,7 @@ panel3 - 4 + 6 True @@ -850,7 +901,7 @@ panel3 - 5 + 7 False @@ -877,7 +928,7 @@ panel3 - 6 + 8 True @@ -904,7 +955,7 @@ panel3 - 7 + 9 16, 189