From bb4ac545a08e459f47bf0ec09f52e910fe19ba85 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Tue, 16 Feb 2021 18:13:15 +0100 Subject: [PATCH] completato spostamento metodi connect/disconnect camera in class lib --- ThermalImageStreamerDemo/MainForm.Designer.cs | 60 +----- ThermalImageStreamerDemo/MainForm.cs | 170 +++++++-------- ThermoCamUtils/ImageData.cs | 194 +++++++++++++----- ThermoCamUtils/ReColorize.cs | 2 +- 4 files changed, 234 insertions(+), 192 deletions(-) diff --git a/ThermalImageStreamerDemo/MainForm.Designer.cs b/ThermalImageStreamerDemo/MainForm.Designer.cs index 0a208c0a..ac334c4f 100644 --- a/ThermalImageStreamerDemo/MainForm.Designer.cs +++ b/ThermalImageStreamerDemo/MainForm.Designer.cs @@ -46,15 +46,12 @@ this.groupBox3 = new System.Windows.Forms.GroupBox(); this.lblMaxTemp = new System.Windows.Forms.Label(); this.lblMinTemp = new System.Windows.Forms.Label(); - this.lblTempRGB = new System.Windows.Forms.Label(); this.label6 = new System.Windows.Forms.Label(); this.txtMaxScale = new System.Windows.Forms.TextBox(); this.label7 = new System.Windows.Forms.Label(); this.txtMinScale = new System.Windows.Forms.TextBox(); this.chkReadTemp = new System.Windows.Forms.CheckBox(); this.lblReadTemp = new System.Windows.Forms.Label(); - this.chkRevProc = new System.Windows.Forms.CheckBox(); - this.chkParallel = new System.Windows.Forms.CheckBox(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.label5 = new System.Windows.Forms.Label(); this.txtBC = new System.Windows.Forms.TextBox(); @@ -193,8 +190,6 @@ this.panelCmd.Controls.Add(this.chkSaveAll); this.panelCmd.Controls.Add(this.btnLoad); this.panelCmd.Controls.Add(this.groupBox3); - this.panelCmd.Controls.Add(this.chkRevProc); - this.panelCmd.Controls.Add(this.chkParallel); this.panelCmd.Controls.Add(this.groupBox2); this.panelCmd.Controls.Add(this.groupBox1); this.panelCmd.Controls.Add(this.checkLive); @@ -229,7 +224,6 @@ // this.groupBox3.Controls.Add(this.lblMaxTemp); this.groupBox3.Controls.Add(this.lblMinTemp); - this.groupBox3.Controls.Add(this.lblTempRGB); this.groupBox3.Controls.Add(this.label6); this.groupBox3.Controls.Add(this.txtMaxScale); this.groupBox3.Controls.Add(this.label7); @@ -238,7 +232,7 @@ this.groupBox3.Controls.Add(this.lblReadTemp); this.groupBox3.Location = new System.Drawing.Point(8, 333); this.groupBox3.Name = "groupBox3"; - this.groupBox3.Size = new System.Drawing.Size(175, 175); + this.groupBox3.Size = new System.Drawing.Size(175, 119); this.groupBox3.TabIndex = 5; this.groupBox3.TabStop = false; this.groupBox3.Text = "Temperature"; @@ -247,7 +241,7 @@ // this.lblMaxTemp.AutoSize = true; this.lblMaxTemp.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lblMaxTemp.Location = new System.Drawing.Point(89, 67); + this.lblMaxTemp.Location = new System.Drawing.Point(89, 42); this.lblMaxTemp.MinimumSize = new System.Drawing.Size(80, 0); this.lblMaxTemp.Name = "lblMaxTemp"; this.lblMaxTemp.Size = new System.Drawing.Size(80, 13); @@ -259,29 +253,17 @@ // this.lblMinTemp.AutoSize = true; this.lblMinTemp.ForeColor = System.Drawing.SystemColors.ControlText; - this.lblMinTemp.Location = new System.Drawing.Point(7, 67); + this.lblMinTemp.Location = new System.Drawing.Point(7, 42); this.lblMinTemp.MinimumSize = new System.Drawing.Size(80, 0); this.lblMinTemp.Name = "lblMinTemp"; this.lblMinTemp.Size = new System.Drawing.Size(80, 13); this.lblMinTemp.TabIndex = 16; this.lblMinTemp.Text = "? °C"; // - // lblTempRGB - // - this.lblTempRGB.AutoSize = true; - this.lblTempRGB.ForeColor = System.Drawing.SystemColors.ButtonHighlight; - this.lblTempRGB.Location = new System.Drawing.Point(89, 41); - this.lblTempRGB.MinimumSize = new System.Drawing.Size(80, 0); - this.lblTempRGB.Name = "lblTempRGB"; - this.lblTempRGB.Size = new System.Drawing.Size(80, 13); - this.lblTempRGB.TabIndex = 15; - this.lblTempRGB.Text = "? °C"; - this.lblTempRGB.TextAlign = System.Drawing.ContentAlignment.TopRight; - // // label6 // this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(7, 135); + this.label6.Location = new System.Drawing.Point(7, 91); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(57, 13); this.label6.TabIndex = 13; @@ -289,7 +271,7 @@ // // txtMaxScale // - this.txtMaxScale.Location = new System.Drawing.Point(92, 132); + this.txtMaxScale.Location = new System.Drawing.Point(92, 88); this.txtMaxScale.Name = "txtMaxScale"; this.txtMaxScale.Size = new System.Drawing.Size(77, 20); this.txtMaxScale.TabIndex = 12; @@ -300,7 +282,7 @@ // label7 // this.label7.AutoSize = true; - this.label7.Location = new System.Drawing.Point(7, 108); + this.label7.Location = new System.Drawing.Point(7, 64); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(54, 13); this.label7.TabIndex = 11; @@ -308,7 +290,7 @@ // // txtMinScale // - this.txtMinScale.Location = new System.Drawing.Point(92, 105); + this.txtMinScale.Location = new System.Drawing.Point(92, 61); this.txtMinScale.Name = "txtMinScale"; this.txtMinScale.Size = new System.Drawing.Size(77, 20); this.txtMinScale.TabIndex = 10; @@ -338,30 +320,6 @@ this.lblReadTemp.Text = "? °C"; this.lblReadTemp.TextAlign = System.Drawing.ContentAlignment.TopRight; // - // chkRevProc - // - this.chkRevProc.AutoSize = true; - this.chkRevProc.Checked = true; - this.chkRevProc.CheckState = System.Windows.Forms.CheckState.Checked; - this.chkRevProc.Location = new System.Drawing.Point(8, 514); - this.chkRevProc.Name = "chkRevProc"; - this.chkRevProc.Size = new System.Drawing.Size(100, 17); - this.chkRevProc.TabIndex = 11; - this.chkRevProc.Text = "Rev processing"; - this.chkRevProc.UseVisualStyleBackColor = true; - // - // chkParallel - // - this.chkParallel.AutoSize = true; - this.chkParallel.Checked = true; - this.chkParallel.CheckState = System.Windows.Forms.CheckState.Checked; - this.chkParallel.Location = new System.Drawing.Point(8, 533); - this.chkParallel.Name = "chkParallel"; - this.chkParallel.Size = new System.Drawing.Size(112, 17); - this.chkParallel.TabIndex = 10; - this.chkParallel.Text = "Bitmap Marshalled"; - this.chkParallel.UseVisualStyleBackColor = true; - // // groupBox2 // this.groupBox2.Controls.Add(this.label5); @@ -590,6 +548,7 @@ this.chkShowOrig.TabIndex = 12; this.chkShowOrig.Text = "Show Original"; this.chkShowOrig.UseVisualStyleBackColor = true; + this.chkShowOrig.CheckedChanged += new System.EventHandler(this.chkShowOrig_CheckedChanged); // // MainForm // @@ -669,15 +628,12 @@ private System.Windows.Forms.Label lblImgC; private System.Windows.Forms.ToolStripProgressBar progBar; private System.Windows.Forms.ToolStripStatusLabel lblStats; - private System.Windows.Forms.CheckBox chkParallel; - private System.Windows.Forms.CheckBox chkRevProc; private System.Windows.Forms.GroupBox groupBox3; private System.Windows.Forms.Label label6; private System.Windows.Forms.TextBox txtMaxScale; private System.Windows.Forms.Label label7; private System.Windows.Forms.TextBox txtMinScale; private System.Windows.Forms.Label lblPoint; - private System.Windows.Forms.Label lblTempRGB; private System.Windows.Forms.CheckBox chkShowOrig; private System.Windows.Forms.Button btnReset; private System.Windows.Forms.Button btnLoad; diff --git a/ThermalImageStreamerDemo/MainForm.cs b/ThermalImageStreamerDemo/MainForm.cs index 9676beb5..2fa55e1f 100644 --- a/ThermalImageStreamerDemo/MainForm.cs +++ b/ThermalImageStreamerDemo/MainForm.cs @@ -22,29 +22,24 @@ namespace ThermalImageStreamerDemo private readonly Timer _timerRefreshUi = new Timer(); -#if false - private Camera IRCam.ThermoCamera; -#endif - - private RecorderForm _recorder; - #endregion Private Fields +#if false + private RecorderForm _recorder; +#endif + #region Protected Fields protected const string colorPath = "images\\Color"; protected const string confFileName = "ThermoConf.json"; +#if false protected const string currImgFile = "ThermalData.jpg"; +#endif protected const string thermPath = "images\\Therm"; - /// - /// Ultimo range di temperature osservato - /// - protected Range _lastTempRange = new Range(-999, 5000); - protected int currPoint = -1; /// @@ -52,8 +47,6 @@ namespace ThermalImageStreamerDemo /// protected ImageData ImgData = new ImageData(); - protected double msLastCam = 0; - protected Stopwatch sw = new Stopwatch(); #endregion Protected Fields @@ -72,6 +65,11 @@ namespace ThermalImageStreamerDemo InitializeComponent(); _timerRefreshUi.Interval = 100; _timerRefreshUi.Tick += _timerRefreshUi_Tick; + _timerRefreshUi.Start(); + // collego eventi ImgData + ImgData.eh_CameraConnected += ImgData_eh_CameraConnected; + ImgData.eh_CameraDisposed += ImgData_eh_CameraDisposed; + ImgData.eh_CameraConnStatusChanged += ImgData_eh_CameraConnStatusChanged; // cerco se ho un set di parametri già impostati... tryReloadConf(); // sistemo le conf temp @@ -84,8 +82,6 @@ namespace ThermalImageStreamerDemo #region Private Properties - private bool IsDirty { get; set; } - private bool liveView { get @@ -251,7 +247,7 @@ namespace ThermalImageStreamerDemo // se è in live view --> continuo if (liveView) { - takePicture(saveEnabled); + ImgData.takePicture(saveEnabled); processImage(); refreshDisplay(); } @@ -281,23 +277,15 @@ namespace ThermalImageStreamerDemo private void btnSave_Click(object sender, EventArgs e) { - takePicture(true); + ImgData.takePicture(true); processImage(); refreshDisplay(); } - private void Camera_ConnectionStatusChanged(object sender, Flir.Atlas.Live.ConnectionStatusChangedEventArgs e) - { - BeginInvoke((Action)(() => toolStripConnectionStatus.Text = e.Status.ToString())); - BeginInvoke((Action)(() => cameraToolStripMenuItem.Enabled = e.Status == ConnectionStatus.Connected)); - // se si disconnette --> NUOVA richiesta connessione alla CHILD... - - // TODO FARE!!! - } - private void checkLive_CheckedChanged(object sender, EventArgs e) { - // non serve fare nulla + // cambio periodo timer! + _timerRefreshUi.Interval = checkLive.Checked ? 100 : 500; } private void chkPointSetup_CheckedChanged(object sender, EventArgs e) @@ -319,53 +307,17 @@ namespace ThermalImageStreamerDemo if (!readTemp) { lblReadTemp.Text = "? °C"; - lblTempRGB.Text = "? °C"; } } - private void ConnectCamera(CameraDeviceInfo cameraDeviceInfo) + private void chkShowOrig_CheckedChanged(object sender, EventArgs e) { - DisposeCamera(); - switch (cameraDeviceInfo.SelectedStreamingFormat) - { - case ImageFormat.FlirFileFormat: - IRCam.ThermoCamera = new ThermalCamera(); - break; - - case ImageFormat.Argb: - IRCam.ThermoCamera = new VideoOverlayCamera(); - break; - - default: - throw new ArgumentOutOfRangeException(); - } - IRCam.ThermoCamera.ConnectionStatusChanged += Camera_ConnectionStatusChanged; - IRCam.ThermoCamera.GetImage().Changed += Image_Changed; - IRCam.ThermoCamera.Connect(cameraDeviceInfo); - if (IRCam.ThermoCamera.Recorder == null && _recorder != null) - { - _recorder.Dispose(); - _recorder = null; - } - if (_recorder != null) - { - if (!_recorder.IsDisposed) - _recorder.Initialize(IRCam.ThermoCamera); - } - recorderToolStripMenuItem.Enabled = IRCam.ThermoCamera.Recorder != null; - _timerRefreshUi.Start(); - } - - private void DisconnectCamera() - { - if (IRCam.ThermoCamera == null) return; - - IRCam.ThermoCamera.Disconnect(); + refreshDisplay(); } private void disconnectToolStripMenuItem_Click(object sender, EventArgs e) { - DisconnectCamera(); + ImgData.DisconnectCamera(); } private void discoveryToolStripMenuItem_Click(object sender, EventArgs e) @@ -373,7 +325,7 @@ namespace ThermalImageStreamerDemo var discoveryDlg = new DiscoveryForm(); if (discoveryDlg.ShowDialog() == DialogResult.OK) { - ConnectCamera(discoveryDlg.SelectedCameraDevice); + ImgData.ConnectCamera(discoveryDlg.SelectedCameraDevice); // salvo nome camera in conf attuale! currConf.CameraName = discoveryDlg.SelectedCameraDevice.Name; saveConf(); @@ -393,6 +345,50 @@ namespace ThermalImageStreamerDemo } } + private void ImgData_eh_CameraConnected(object sender, EventArgs e) + { +#if false + _timerRefreshUi.Start(); +#endif + _timerRefreshUi.Interval = 100; + } + + private void ImgData_eh_CameraConnStatusChanged(object sender, Flir.Atlas.Live.ConnectionStatusChangedEventArgs e) + { + BeginInvoke((Action)(() => toolStripConnectionStatus.Text = e.Status.ToString())); + BeginInvoke((Action)(() => cameraToolStripMenuItem.Enabled = e.Status == ConnectionStatus.Connected)); + // se si disconnette --> NUOVA richiesta connessione alla CHILD... + + // TODO FARE!!! + } + + private void ImgData_eh_CameraDisposed(object sender, EventArgs e) + { +#if false + _timerRefreshUi.Stop(); +#endif + _timerRefreshUi.Interval = 500; + } + +#if false + private void Camera_ConnectionStatusChanged(object sender, Flir.Atlas.Live.ConnectionStatusChangedEventArgs e) + { + BeginInvoke((Action)(() => toolStripConnectionStatus.Text = e.Status.ToString())); + BeginInvoke((Action)(() => cameraToolStripMenuItem.Enabled = e.Status == ConnectionStatus.Connected)); + // se si disconnette --> NUOVA richiesta connessione alla CHILD... + + // TODO FARE!!! + } +#endif +#if false + private void DisconnectCamera() + { + if (IRCam.ThermoCamera == null) return; + + IRCam.ThermoCamera.Disconnect(); + } +#endif +#if false private void DisposeCamera() { _timerRefreshUi.Stop(); @@ -406,11 +402,14 @@ namespace ThermalImageStreamerDemo IRCam.ThermoCamera.GetImage().Changed -= Image_Changed; IRCam.ThermoCamera.Dispose(); } +#endif +#if false private void Image_Changed(object sender, Flir.Atlas.Image.ImageChangedEventArgs e) { IsDirty = true; } +#endif private void lblOrigA_Click(object sender, EventArgs e) { @@ -434,12 +433,14 @@ namespace ThermalImageStreamerDemo private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { +#if false if (_recorder != null && _recorder.IsDisposed == false) { _recorder.Dispose(); } +#endif - DisposeCamera(); + ImgData.DisposeCamera(); } private void MainForm_Load(object sender, EventArgs e) @@ -530,11 +531,12 @@ namespace ThermalImageStreamerDemo { // disegno immagine ImgData.getTemperatures(readTemp); - ImgData.calculateTarget(chkParallel.Checked, chkRevProc.Checked); + ImgData.calculateTarget(); } private void recorderToolStripMenuItem_Click(object sender, EventArgs e) { +#if false if (_recorder == null || _recorder.IsDisposed) { _recorder = new RecorderForm(); @@ -543,6 +545,7 @@ namespace ThermalImageStreamerDemo } _recorder.Show(); _recorder.Focus(); +#endif } private void refreshDisplay() @@ -581,6 +584,7 @@ namespace ThermalImageStreamerDemo currConf.TargetRange.Max = maxRangeTemp; } +#if false /// /// recupera immagine effettuando eventuale salvataggio /// @@ -622,6 +626,7 @@ namespace ThermalImageStreamerDemo sw.Stop(); msLastCam = sw.ElapsedMilliseconds; } +#endif /// /// Verifica se il punto era in edit, altrimenti segnala e lo attiva... restituendo colore x il controllo @@ -728,7 +733,7 @@ namespace ThermalImageStreamerDemo if (currConf.OrigPoints.Coords.Count > 3) { lblOrigD.Text = $"D: ({currConf.OrigPoints.Coords[3].X},{currConf.OrigPoints.Coords[3].Y})"; - ImgData.calculateTarget(chkParallel.Checked, chkRevProc.Checked); + ImgData.calculateTarget(); } } @@ -738,7 +743,7 @@ namespace ThermalImageStreamerDemo { try { - lblStats.Text = $"Camera: {msLastCam}ms | Persp {ImgData.lastStatTime("ImageTransf")}ms | Color {ImgData.lastStatTime("ImageColor")}ms | Points {ImgData.lastStatTime("AddPoints")}ms | Measures {ImgData.lastStatTime("GetAllTemperatures")}ms"; + lblStats.Text = $"Camera: {ImgData.lastStatTime("ImageAcquisition")}ms | Persp {ImgData.lastStatTime("ImageTransf")}ms | Color {ImgData.lastStatTime("ImageColor")}ms | Points {ImgData.lastStatTime("AddPoints")}ms | Measures {ImgData.lastStatTime("GetAllTemperatures")}ms"; } catch { } @@ -754,27 +759,6 @@ namespace ThermalImageStreamerDemo // mostro temp da FLIR lblReadTemp.Text = $"{ImgData.lastReadTemp:N2} °C"; - //calcolo da immagine B/N - lblTempRGB.Text = $"{ImgData.lastCalcTemp:N2} °C"; - // cambio colore se > 1 grado... - double delta = Math.Abs(ImgData.lastReadTemp - ImgData.lastCalcTemp); - if (delta < 1) - { - lblTempRGB.ForeColor = Color.Black; - } - else if (delta < 2) - { - lblTempRGB.ForeColor = Color.Blue; - } - else if (delta < 3) - { - lblTempRGB.ForeColor = Color.Orange; - } - else - { - lblTempRGB.ForeColor = Color.Red; - } - try { // mostro minimo / massimo @@ -800,7 +784,7 @@ namespace ThermalImageStreamerDemo //discoveryDialog.WindowState = FormWindowState.Minimized; if (discoveryDialog.ShowDialog() == DialogResult.OK) { - ConnectCamera(discoveryDialog.SelectedCameraDevice); + ImgData.ConnectCamera(discoveryDialog.SelectedCameraDevice); } } } diff --git a/ThermoCamUtils/ImageData.cs b/ThermoCamUtils/ImageData.cs index e28cea2d..b4cf98a7 100644 --- a/ThermoCamUtils/ImageData.cs +++ b/ThermoCamUtils/ImageData.cs @@ -1,4 +1,6 @@ using Flir.Atlas.Image; +using Flir.Atlas.Live.Device; +using Flir.Atlas.Live.Discovery; using Newtonsoft.Json; using System; using System.Collections.Generic; @@ -65,11 +67,6 @@ namespace ThermoCamUtils /// public ExecTime ExTime = new ExecTime(); - /// - /// Ultima temp calcolata da immagine B/N - /// - public double lastCalcTemp = 0; - /// /// Ultimo punto acquisito /// @@ -104,6 +101,22 @@ namespace ThermoCamUtils #endregion Public Constructors + #region Public Events + + public event EventHandler eh_CameraConnected; + + public event EventHandler eh_CameraConnStatusChanged; + + public event EventHandler eh_CameraDisposed; + + #endregion Public Events + + #region Private Properties + + private bool IsDirty { get; set; } + + #endregion Private Properties + #region Protected Properties protected Point[] _reticolo { get; set; } @@ -146,6 +159,14 @@ namespace ThermoCamUtils #region Private Methods + private void Camera_ConnectionStatusChanged(object sender, Flir.Atlas.Live.ConnectionStatusChangedEventArgs e) + { + if (eh_CameraConnStatusChanged != null) + { + eh_CameraConnStatusChanged(this, e); + } + } + private void checkLocadOutDir() { // verifico esistenza directory @@ -197,6 +218,11 @@ namespace ThermoCamUtils { } } + private void Image_Changed(object sender, Flir.Atlas.Image.ImageChangedEventArgs e) + { + IsDirty = true; + } + #endregion Private Methods #region Protected Methods @@ -267,49 +293,27 @@ namespace ThermoCamUtils /// /// Effettua calcolo immagini 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) + public void calculateTarget() { if (Thermal != null) { try { -#if false - //lastTempRange = new Range(lastThermalImage.GetValueFromSignal(lastThermalImage.MinSignalValue), lastThermalImage.GetValueFromSignal(lastThermalImage.MaxSignalValue)); - lastTempRange = new Range(Thermal.Scale.Range.Minimum, Thermal.Scale.Range.Maximum); -#endif - + // genero immagine BN sw.Restart(); var pTransf = new PerspectiveTransform(currConf.OrigPoints.Coords, currConf.DestPoints.Coords); - var rTrasf = new ReColorize(currConf.TargetRange.Min, currConf.TargetRange.Max); -#if false - var rTrasf = new ReColorize(lastTempRange.Minimum, lastTempRange.Maximum, currConf.TargetRange.Min, currConf.TargetRange.Max); -#endif 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, lastFlirData.Values); -#if false - var colImg = rTrasf.process(Origin, fastBitmap); -#endif - // e faccio la stessa trasformazione di riscalatura - var transfColImg = pTransf.convertImage(colImg, currConf.TargetSize.X, currConf.TargetSize.Y); - ColorTransf = transfColImg; - } -#if false - else - { - // old way da immagine BN full size - ColorTransf = rTrasf.process(GrayTransf, fastBitmap); - } -#endif + var rTrasf = new ReColorize(currConf.TargetRange.Min, currConf.TargetRange.Max); + // ora calcolo ricolorazione da immagine originale + var colImg = rTrasf.process(Origin, lastFlirData.Values); + // e faccio la stessa trasformazione di riscalatura + var transfColImg = pTransf.convertImage(colImg, currConf.TargetSize.X, currConf.TargetSize.Y); + ColorTransf = transfColImg; sw.Stop(); ExTime.recordData("ImageColor", sw.ElapsedMilliseconds); } @@ -319,10 +323,70 @@ namespace ThermoCamUtils } } + public void ConnectCamera(CameraDeviceInfo cameraDeviceInfo) + { + DisposeCamera(); + switch (cameraDeviceInfo.SelectedStreamingFormat) + { + case ImageFormat.FlirFileFormat: + IRCam.ThermoCamera = new ThermalCamera(); + break; + + case ImageFormat.Argb: + IRCam.ThermoCamera = new VideoOverlayCamera(); + break; + + default: + throw new ArgumentOutOfRangeException(); + } + IRCam.ThermoCamera.ConnectionStatusChanged += Camera_ConnectionStatusChanged; + IRCam.ThermoCamera.GetImage().Changed += Image_Changed; + IRCam.ThermoCamera.Connect(cameraDeviceInfo); +#if false + if (IRCam.ThermoCamera.Recorder == null && _recorder != null) + { + _recorder.Dispose(); + _recorder = null; + } + if (_recorder != null) + { + if (!_recorder.IsDisposed) + _recorder.Initialize(IRCam.ThermoCamera); + } + recorderToolStripMenuItem.Enabled = IRCam.ThermoCamera.Recorder != null; +#endif + if (eh_CameraConnected != null) + { + eh_CameraConnected(this, new EventArgs()); + } + } + + public void DisconnectCamera() + { + if (IRCam.ThermoCamera == null) return; + + IRCam.ThermoCamera.Disconnect(); + } + + public void DisposeCamera() + { + if (eh_CameraDisposed != null) + { + eh_CameraDisposed(this, new EventArgs()); + } + if (IRCam.ThermoCamera == null) return; + + IRCam.ThermoCamera.ConnectionStatusChanged -= Camera_ConnectionStatusChanged; + IRCam.ThermoCamera.GetImage().Changed -= Image_Changed; + IRCam.ThermoCamera.Dispose(); + } + public void drawCrossAtPoints() { if (Thermal != null) { + // ricopio immagine "Pulita" + initImageFromFile(); sw.Restart(); // se ho dei punti x trasformazione --> disegno if (currConf.OrigPoints.curr > 0) @@ -375,7 +439,7 @@ namespace ThermoCamUtils // carico oggetto FLIR using (var flirImg = new ThermalImageFile(fileOrigiPath)) { - //ImgData.Thermal = new ThermalImageFile(filePath); + //Thermal = new ThermalImageFile(filePath); Thermal = (ThermalImage)flirImg; Thermal.TemperatureUnit = TemperatureUnit.Celsius; Thermal.Scale.IsAutoAdjustEnabled = true; @@ -388,11 +452,6 @@ namespace ThermoCamUtils Decorated = (Bitmap)loadedImg.Clone(); } - using (Image loadedImg = Image.FromFile(fileColorPath)) - { - ColorTransf = (Bitmap)loadedImg.Clone(); - } - // carico il file delle temperature string rawData = File.ReadAllText(fileDataPath); if (!string.IsNullOrEmpty(rawData)) @@ -480,13 +539,11 @@ namespace ThermoCamUtils foreach (var item in currConf.MeasPoints) { // recupero da ARRAY in memoria delle ultime letture fatte... - lastCalcTemp = lastFlirData.Values[item.Coords.X + Thermal.Size.Width * item.Coords.Y]; - - // recupero temp da FLIR - lastReadTemp = Thermal.GetValueAt(item.Coords).Value; + lastReadTemp = lastFlirData.Values[item.Coords.X + Thermal.Size.Width * item.Coords.Y]; + //lastReadTemp = Thermal.GetValueAt(item.Coords).Value; } sw.Stop(); - ExTime.recordData("GetTemperatures", sw.ElapsedMilliseconds); + ExTime.recordData("GetPoints", sw.ElapsedMilliseconds); } catch (Exception exc) { } @@ -583,6 +640,51 @@ namespace ThermoCamUtils currConf.MeasPoints.Add(newPoint); } + /// + /// recupera immagine effettuando eventuale salvataggio + /// + /// + public string takePicture(bool doSave) + { + string answ = ""; + sw.Restart(); + if (!IsDirty) return answ; + IsDirty = false; + if (IRCam.ThermoCamera == null) return answ; + + IRCam.ThermoCamera.GetImage().EnterLock(); + try + { + Thermal = (ThermalImage)IRCam.ThermoCamera.GetImage(); + Thermal.TemperatureUnit = TemperatureUnit.Celsius; + Thermal.Scale.IsAutoAdjustEnabled = true; + lastTempRange = new Range(Thermal.Scale.Range.Minimum, Thermal.Scale.Range.Maximum); + // salvo img locale + Origin = Thermal.Image; + Decorated = Thermal.Image; + // recupero le temperature... + readAllTemperatures(); + //verifico se devo salvare... + if (doSave) + { + answ = fileSave(); + } + } + catch (Exception exception) + { + Trace.TraceError(exception.Message); + } + finally + { + IRCam.ThermoCamera.GetImage().ExitLock(); + } + + sw.Stop(); + ExTime.recordData("ImageAcquisition", sw.ElapsedMilliseconds); + + return answ; + } + #endregion Public Methods } } \ No newline at end of file diff --git a/ThermoCamUtils/ReColorize.cs b/ThermoCamUtils/ReColorize.cs index b5bd7d1c..0b28f64c 100644 --- a/ThermoCamUtils/ReColorize.cs +++ b/ThermoCamUtils/ReColorize.cs @@ -209,7 +209,7 @@ namespace ThermoCamUtils #if true currVal = pixels[currentLine + x + 2]; #endif - var newCol = Rescale(ref tempVal[x + original.Width * y]); + var newCol = Rescale(ref tempVal[x / bytesPerPixel + original.Width * y]); pixels[currentLine + x] = (byte)newCol.B; pixels[currentLine + x + 1] = (byte)newCol.G; pixels[currentLine + x + 2] = (byte)newCol.R;