From 40ff5dae6f1464c1853325619dbcc2c5cbdcaee4 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Sat, 13 Feb 2021 11:49:04 +0100 Subject: [PATCH] spostato metodi ricalcolo img in classe libreria --- ThermalImageStreamerDemo/MainForm.cs | 25 +++++++++- ThermoCamUtils/ExecTime.cs | 45 ++++++++++++++++++ ThermoCamUtils/ImageData.cs | 71 ++++++++++++++++++++++++++++ ThermoCamUtils/Objects.cs | 8 +++- ThermoCamUtils/ThermoCamConf.cs | 64 ++++++++++++++++++++++--- ThermoCamUtils/ThermoCamUtils.csproj | 1 + 6 files changed, 203 insertions(+), 11 deletions(-) create mode 100644 ThermoCamUtils/ExecTime.cs diff --git a/ThermalImageStreamerDemo/MainForm.cs b/ThermalImageStreamerDemo/MainForm.cs index 05c0c470..f89cc73f 100644 --- a/ThermalImageStreamerDemo/MainForm.cs +++ b/ThermalImageStreamerDemo/MainForm.cs @@ -130,7 +130,17 @@ namespace ThermalImageStreamerDemo } } - protected ThermoCamConf currConf { get; set; } = new ThermoCamConf(); + protected ThermoCamConf currConf + { + get + { + return ImgData.currConf; + } + set + { + ImgData.currConf = value; + } + } protected int dimX { @@ -138,10 +148,12 @@ namespace ThermalImageStreamerDemo { int answ = 100; int.TryParse(txtAB.Text, out answ); + currConf.TargetSize.X = answ; return answ; } set { + currConf.TargetSize.X = value; txtAB.Text = $"{value}"; } } @@ -152,10 +164,12 @@ namespace ThermalImageStreamerDemo { int answ = 100; int.TryParse(txtBC.Text, out answ); + currConf.TargetSize.Y = answ; return answ; } set { + currConf.TargetSize.Y = value; txtBC.Text = $"{value}"; } } @@ -181,12 +195,14 @@ namespace ThermalImageStreamerDemo { get { - double answ = 0; + double answ = 1000; double.TryParse(txtMaxScale.Text, out answ); + currConf.TargetRange.Max = answ; return answ; } set { + currConf.TargetRange.Max = value; txtMaxScale.Text = $"{value:N0}"; } } @@ -197,10 +213,12 @@ namespace ThermalImageStreamerDemo { double answ = 0; double.TryParse(txtMinScale.Text, out answ); + currConf.TargetRange.Min = answ; return answ; } set { + currConf.TargetRange.Min = value; txtMinScale.Text = $"{value:N0}"; } } @@ -322,6 +340,8 @@ namespace ThermalImageStreamerDemo /// private void calculateTarget() { + ImgData.calculateTarget(chkParallel.Checked, chkRevProc.Checked); +#if false if (ImgData.Thermal != null) { try @@ -358,6 +378,7 @@ namespace ThermalImageStreamerDemo { } } +#endif } private void Camera_ConnectionStatusChanged(object sender, Flir.Atlas.Live.ConnectionStatusChangedEventArgs e) diff --git a/ThermoCamUtils/ExecTime.cs b/ThermoCamUtils/ExecTime.cs new file mode 100644 index 00000000..03dcfc3b --- /dev/null +++ b/ThermoCamUtils/ExecTime.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ThermoCamUtils +{ + /// + /// Gestione tempi esecuzione + /// + public class ExecTime + { + #region Public Fields + + /// + /// Dizionario statistiche tempi di esecuzione + /// + public Dictionary Stats = new Dictionary(); + + #endregion Public Fields + + #region Public Methods + + /// + /// Memorizza dato statistiche + /// + /// + /// + public void recordData(string taskName, double timeMs) + { + // facico upsert statistiche... + if (Stats.ContainsKey(taskName)) + { + Stats[taskName] = timeMs; + } + else + { + Stats.Add(taskName, timeMs); + } + } + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/ThermoCamUtils/ImageData.cs b/ThermoCamUtils/ImageData.cs index ac38ce05..cda54b5c 100644 --- a/ThermoCamUtils/ImageData.cs +++ b/ThermoCamUtils/ImageData.cs @@ -1,6 +1,7 @@ using Flir.Atlas.Image; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; using System.Linq; using System.Text; @@ -13,6 +14,29 @@ namespace ThermoCamUtils /// public class ImageData { + #region Protected Fields + + /// + /// Ultimo range di temperature osservato + /// + protected Range lastTempRange = new Range(0, 5000); + + /// + /// Stopwatch x benchmarking + /// + protected Stopwatch sw = new Stopwatch(); + + #endregion Protected Fields + + #region Public Fields + + /// + /// Statistiche esecuzione task + /// + public ExecTime ExTime = new ExecTime(); + + #endregion Public Fields + #region Public Properties /// @@ -20,6 +44,8 @@ namespace ThermoCamUtils /// public Bitmap ColorTransf { get; set; } + public ThermoCamConf currConf { get; set; } = new ThermoCamConf(); + /// /// Ultima bitmap disegnata (con punti) /// @@ -44,6 +70,51 @@ namespace ThermoCamUtils #region Public Methods + /// + /// Effettua calcolo e display immagine target + /// + /// Indica se processare bitmap in memoria (true) o con metodi standard (false) + /// Indica se prima fare falsi colori poi trasformazione proiettiva + public void calculateTarget(bool fastBitmap, bool colorizeFirst) + { + if (Thermal != null) + { + try + { + //lastTempRange = new Range(lastThermalImage.GetValueFromSignal(lastThermalImage.MinSignalValue), lastThermalImage.GetValueFromSignal(lastThermalImage.MaxSignalValue)); + lastTempRange = new Range(Thermal.Scale.Range.Minimum, Thermal.Scale.Range.Maximum); + + sw.Restart(); + var pTransf = new PerspectiveTransform(currConf.origPoints.Coords, currConf.destPoints.Coords); + var rTrasf = new ReColorize(lastTempRange.Minimum, lastTempRange.Maximum, currConf.TargetRange.Min, currConf.TargetRange.Max); + var transfImg = pTransf.convertImage(Origin, currConf.TargetSize.X, currConf.TargetSize.Y); + GrayTransf = transfImg; + sw.Stop(); + ExTime.recordData("ImageTransf", sw.ElapsedMilliseconds); + + sw.Restart(); + if (colorizeFirst) + { + // ora calcolo ricolorazione da immagine originale + var colImg = rTrasf.process(Origin, fastBitmap); + // e faccio la stessa trasformazione di riscalatura + var transfColImg = pTransf.convertImage(colImg, currConf.TargetSize.X, currConf.TargetSize.Y); + ColorTransf = transfColImg; + } + else + { + // old way da immagine BN full size + ColorTransf = rTrasf.process(GrayTransf, fastBitmap); + } + sw.Stop(); + ExTime.recordData("ImageColor", sw.ElapsedMilliseconds); + } + catch (Exception exc) + { + } + } + } + /// /// Init iniziale immagini /// diff --git a/ThermoCamUtils/Objects.cs b/ThermoCamUtils/Objects.cs index 2f7cdd99..8fb76872 100644 --- a/ThermoCamUtils/Objects.cs +++ b/ThermoCamUtils/Objects.cs @@ -9,7 +9,11 @@ namespace ThermoCamUtils { public class SetPoints { - public int curr { get; set; } = 0; + #region Public Properties + public List Coords { get; set; } = new List(); + public int curr { get; set; } = 0; + + #endregion Public Properties } -} +} \ No newline at end of file diff --git a/ThermoCamUtils/ThermoCamConf.cs b/ThermoCamUtils/ThermoCamConf.cs index 58fe4639..4b62017f 100644 --- a/ThermoCamUtils/ThermoCamConf.cs +++ b/ThermoCamUtils/ThermoCamConf.cs @@ -1,4 +1,5 @@ -using Flir.Atlas.Live.Discovery; +using Flir.Atlas.Image; +using Flir.Atlas.Live.Discovery; using System; using System.Collections.Generic; using System.Linq; @@ -7,20 +8,69 @@ using System.Threading.Tasks; namespace ThermoCamUtils { - public class ThermoCamConf + public class RangeVal { + #region Public Properties + + /// + /// VAlore MASSIMO + /// + public double Max { get; set; } = 50; + + /// + /// Valore minimo + /// + public double Min { get; set; } = 0; + + #endregion Public Properties + } + + public class Size + { + #region Public Properties + + /// + /// Dimensione X + /// + public int X { get; set; } = 100; + + /// + /// Dimensione X + /// + public int Y { get; set; } = 100; + + #endregion Public Properties + } + + public class ThermoCamConf + { + #region Public Properties /// /// Camera selezionata x autoconnect ("" = nessun autoconnect) /// public string CameraName { get; set; } = ""; - /// - /// Punti su IMG origine - /// - public SetPoints origPoints { get; set; } = new SetPoints(); + /// /// Punti su IMG destinazione /// public SetPoints destPoints { get; set; } = new SetPoints(); + + /// + /// Punti su IMG origine + /// + public SetPoints origPoints { get; set; } = new SetPoints(); + + /// + /// Range scala colori desiderata + /// + public RangeVal TargetRange { get; set; } = new RangeVal(); + + /// + /// Target (transformed & colored) image size + /// + public Size TargetSize { get; set; } = new Size(); + + #endregion Public Properties } -} +} \ No newline at end of file diff --git a/ThermoCamUtils/ThermoCamUtils.csproj b/ThermoCamUtils/ThermoCamUtils.csproj index 060714a1..13371e27 100644 --- a/ThermoCamUtils/ThermoCamUtils.csproj +++ b/ThermoCamUtils/ThermoCamUtils.csproj @@ -85,6 +85,7 @@ +