spostato save in libreria
This commit is contained in:
+27
-25
@@ -44,6 +44,8 @@
|
||||
this.chkSaveAll = new System.Windows.Forms.CheckBox();
|
||||
this.btnLoad = new System.Windows.Forms.Button();
|
||||
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();
|
||||
@@ -75,8 +77,6 @@
|
||||
this.lblImgB = new System.Windows.Forms.Label();
|
||||
this.lblImgC = new System.Windows.Forms.Label();
|
||||
this.chkShowOrig = new System.Windows.Forms.CheckBox();
|
||||
this.lblMinTemp = new System.Windows.Forms.Label();
|
||||
this.lblMaxTemp = new System.Windows.Forms.Label();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pBoxA)).BeginInit();
|
||||
@@ -243,6 +243,29 @@
|
||||
this.groupBox3.TabStop = false;
|
||||
this.groupBox3.Text = "Temperature";
|
||||
//
|
||||
// lblMaxTemp
|
||||
//
|
||||
this.lblMaxTemp.AutoSize = true;
|
||||
this.lblMaxTemp.ForeColor = System.Drawing.SystemColors.ControlLightLight;
|
||||
this.lblMaxTemp.Location = new System.Drawing.Point(89, 67);
|
||||
this.lblMaxTemp.MinimumSize = new System.Drawing.Size(80, 0);
|
||||
this.lblMaxTemp.Name = "lblMaxTemp";
|
||||
this.lblMaxTemp.Size = new System.Drawing.Size(80, 13);
|
||||
this.lblMaxTemp.TabIndex = 17;
|
||||
this.lblMaxTemp.Text = "? °C";
|
||||
this.lblMaxTemp.TextAlign = System.Drawing.ContentAlignment.TopRight;
|
||||
//
|
||||
// lblMinTemp
|
||||
//
|
||||
this.lblMinTemp.AutoSize = true;
|
||||
this.lblMinTemp.ForeColor = System.Drawing.SystemColors.ControlText;
|
||||
this.lblMinTemp.Location = new System.Drawing.Point(7, 67);
|
||||
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;
|
||||
@@ -272,6 +295,7 @@
|
||||
this.txtMaxScale.TabIndex = 12;
|
||||
this.txtMaxScale.Text = "60";
|
||||
this.txtMaxScale.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
|
||||
this.txtMaxScale.TextChanged += new System.EventHandler(this.txtMaxScale_TextChanged);
|
||||
//
|
||||
// label7
|
||||
//
|
||||
@@ -290,6 +314,7 @@
|
||||
this.txtMinScale.TabIndex = 10;
|
||||
this.txtMinScale.Text = "0";
|
||||
this.txtMinScale.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
|
||||
this.txtMinScale.TextChanged += new System.EventHandler(this.txtMinScale_TextChanged);
|
||||
//
|
||||
// chkReadTemp
|
||||
//
|
||||
@@ -566,29 +591,6 @@
|
||||
this.chkShowOrig.Text = "Show Original";
|
||||
this.chkShowOrig.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// lblMinTemp
|
||||
//
|
||||
this.lblMinTemp.AutoSize = true;
|
||||
this.lblMinTemp.ForeColor = System.Drawing.SystemColors.ControlText;
|
||||
this.lblMinTemp.Location = new System.Drawing.Point(7, 67);
|
||||
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";
|
||||
//
|
||||
// lblMaxTemp
|
||||
//
|
||||
this.lblMaxTemp.AutoSize = true;
|
||||
this.lblMaxTemp.ForeColor = System.Drawing.SystemColors.ControlLightLight;
|
||||
this.lblMaxTemp.Location = new System.Drawing.Point(89, 67);
|
||||
this.lblMaxTemp.MinimumSize = new System.Drawing.Size(80, 0);
|
||||
this.lblMaxTemp.Name = "lblMaxTemp";
|
||||
this.lblMaxTemp.Size = new System.Drawing.Size(80, 13);
|
||||
this.lblMaxTemp.TabIndex = 17;
|
||||
this.lblMaxTemp.Text = "? °C";
|
||||
this.lblMaxTemp.TextAlign = System.Drawing.ContentAlignment.TopRight;
|
||||
//
|
||||
// MainForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
|
||||
@@ -52,25 +52,18 @@ namespace ThermalImageStreamerDemo
|
||||
/// </summary>
|
||||
protected ImageData ImgData = new ImageData();
|
||||
|
||||
#if false
|
||||
protected double lastCalcTemp = 0;
|
||||
|
||||
protected Point ImgData.lastPoint = new Point();
|
||||
|
||||
protected double lastReadTemp = 0;
|
||||
#endif
|
||||
|
||||
protected double msLastCam = 0;
|
||||
|
||||
protected double msLastCol = 0;
|
||||
|
||||
#if false
|
||||
protected double msLastMsr = 0;
|
||||
|
||||
protected double msLastPts = 0;
|
||||
|
||||
protected double msLastCol = 0;
|
||||
protected double msLastTra = 0;
|
||||
|
||||
protected Point refTempPoint = new Point();
|
||||
#endif
|
||||
|
||||
protected Stopwatch sw = new Stopwatch();
|
||||
|
||||
@@ -92,6 +85,8 @@ namespace ThermalImageStreamerDemo
|
||||
_timerRefreshUi.Tick += _timerRefreshUi_Tick;
|
||||
// cerco se ho un set di parametri già impostati...
|
||||
tryReloadConf();
|
||||
// sistemo le conf temp
|
||||
setRangeTemp();
|
||||
// calcolo i currConf.destPoints
|
||||
updateDestPt();
|
||||
}
|
||||
@@ -176,51 +171,30 @@ namespace ThermalImageStreamerDemo
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ultimo range di temperature osservato
|
||||
/// </summary>
|
||||
protected Range<double> lastTempRange
|
||||
{
|
||||
get
|
||||
{
|
||||
return _lastTempRange;
|
||||
}
|
||||
set
|
||||
{
|
||||
_lastTempRange = value;
|
||||
lblMinTemp.Text = $"{value.Minimum:N2}";
|
||||
lblMaxTemp.Text = $"{value.Maximum:N2}";
|
||||
}
|
||||
}
|
||||
|
||||
protected double maxScale
|
||||
protected double maxRangeTemp
|
||||
{
|
||||
get
|
||||
{
|
||||
double answ = 1000;
|
||||
double.TryParse(txtMaxScale.Text, out answ);
|
||||
currConf.TargetRange.Max = answ;
|
||||
return answ;
|
||||
}
|
||||
set
|
||||
{
|
||||
currConf.TargetRange.Max = value;
|
||||
txtMaxScale.Text = $"{value:N0}";
|
||||
}
|
||||
}
|
||||
|
||||
protected double minScale
|
||||
protected double minRangeTemp
|
||||
{
|
||||
get
|
||||
{
|
||||
double answ = 0;
|
||||
double.TryParse(txtMinScale.Text, out answ);
|
||||
currConf.TargetRange.Min = answ;
|
||||
return answ;
|
||||
}
|
||||
set
|
||||
{
|
||||
currConf.TargetRange.Min = value;
|
||||
txtMinScale.Text = $"{value:N0}";
|
||||
}
|
||||
}
|
||||
@@ -308,18 +282,26 @@ namespace ThermalImageStreamerDemo
|
||||
{
|
||||
try
|
||||
{
|
||||
ImgData.Thermal = new ThermalImageFile(filePath);
|
||||
ImgData.Thermal.TemperatureUnit = TemperatureUnit.Celsius;
|
||||
ImgData.Thermal.Scale.IsAutoAdjustEnabled = true;
|
||||
using (var flirImg = new ThermalImageFile(filePath))
|
||||
{
|
||||
//ImgData.Thermal = new ThermalImageFile(filePath);
|
||||
ImgData.Thermal = (ThermalImage)flirImg;
|
||||
ImgData.Thermal.TemperatureUnit = TemperatureUnit.Celsius;
|
||||
ImgData.Thermal.Scale.IsAutoAdjustEnabled = true;
|
||||
}
|
||||
|
||||
// carico DIRETTAMENTE da file...
|
||||
ImgData.Origin = (Bitmap)Image.FromFile(filePath);
|
||||
ImgData.Decorated = (Bitmap)Image.FromFile(filePath);
|
||||
using (Image loadedImg = Image.FromFile(filePath))
|
||||
{
|
||||
ImgData.Origin = (Bitmap)loadedImg;
|
||||
ImgData.Decorated = (Bitmap)loadedImg;
|
||||
}
|
||||
|
||||
// aggiorno visualizzazione
|
||||
processImage();
|
||||
refreshDisplay();
|
||||
}
|
||||
catch
|
||||
catch (Exception exc)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -327,7 +309,7 @@ namespace ThermalImageStreamerDemo
|
||||
private void btnReset_Click(object sender, EventArgs e)
|
||||
{
|
||||
pointSetup = true;
|
||||
currConf.origPoints = new SetPoints();
|
||||
currConf.OrigPoints = new SetPoints();
|
||||
}
|
||||
|
||||
private void btnSave_Click(object sender, EventArgs e)
|
||||
@@ -458,6 +440,7 @@ namespace ThermalImageStreamerDemo
|
||||
IRCam.ThermoCamera.Dispose();
|
||||
}
|
||||
|
||||
#if false
|
||||
private void drawCrossAtPoints()
|
||||
{
|
||||
if (ImgData.Thermal != null)
|
||||
@@ -505,25 +488,6 @@ namespace ThermalImageStreamerDemo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if false
|
||||
private void getTemperatures()
|
||||
{
|
||||
if (ImgData.Thermal != null)
|
||||
{
|
||||
lastReadTemp = 0;
|
||||
if (readTemp)
|
||||
{
|
||||
// recupero temp da FLIR
|
||||
lastReadTemp = ImgData.Thermal.GetValueAt(ImgData.lastPoint).Value;
|
||||
|
||||
// calcolo temp da RGB considerato limiti minMAX...
|
||||
//int rgbVal = ImgData.lastImageOrig.Image.GetPixel(ImgData.lastPoint.X, ImgData.lastPoint.Y).R;
|
||||
int rgbVal = getRSmooth(ImgData.lastPoint);
|
||||
lastCalcTemp = lastTempRange.Minimum + ((lastTempRange.Maximum - lastTempRange.Minimum) * rgbVal / 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private void Image_Changed(object sender, Flir.Atlas.Image.ImageChangedEventArgs e)
|
||||
@@ -606,15 +570,15 @@ namespace ThermalImageStreamerDemo
|
||||
if (pointSetup)
|
||||
{
|
||||
// max 4 punti... se sono già FULL --> imposto singolo valore nuovo
|
||||
if (currConf.origPoints.curr >= 4)
|
||||
if (currConf.OrigPoints.curr >= 4)
|
||||
{
|
||||
if (currPoint >= 0)
|
||||
{
|
||||
currConf.origPoints.Coords[currPoint] = ImgData.lastPoint;
|
||||
currConf.OrigPoints.Coords[currPoint] = ImgData.lastPoint;
|
||||
}
|
||||
else
|
||||
{
|
||||
currConf.origPoints = new SetPoints();
|
||||
currConf.OrigPoints = new SetPoints();
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -622,8 +586,8 @@ namespace ThermalImageStreamerDemo
|
||||
// salvo coordinate in base al num corrente...
|
||||
try
|
||||
{
|
||||
currConf.origPoints.Coords.Add(ImgData.lastPoint);
|
||||
currConf.origPoints.curr++;
|
||||
currConf.OrigPoints.Coords.Add(ImgData.lastPoint);
|
||||
currConf.OrigPoints.curr++;
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
@@ -637,7 +601,8 @@ namespace ThermalImageStreamerDemo
|
||||
}
|
||||
else if (readTemp)
|
||||
{
|
||||
refTempPoint = ImgData.lastPoint;
|
||||
// x ora fisso 1 solo valore...
|
||||
ImgData.saveMeasurePoint(false);
|
||||
// aggiorno visualizzazione
|
||||
processImage();
|
||||
refreshDisplay();
|
||||
@@ -665,7 +630,7 @@ namespace ThermalImageStreamerDemo
|
||||
|
||||
private void refreshDisplay()
|
||||
{
|
||||
drawCrossAtPoints();
|
||||
ImgData.drawCrossAtPoints();
|
||||
displayImages();
|
||||
updateDisplay();
|
||||
updateTempDisplay();
|
||||
@@ -690,6 +655,7 @@ namespace ThermalImageStreamerDemo
|
||||
return answ;
|
||||
}
|
||||
|
||||
#if false
|
||||
private void saveImgFile()
|
||||
{
|
||||
try
|
||||
@@ -704,10 +670,59 @@ namespace ThermalImageStreamerDemo
|
||||
// salvo!
|
||||
ImgData.Thermal.Scale.IsAutoAdjustEnabled = true;
|
||||
ImgData.Thermal.SaveSnapshot(filePath);
|
||||
var rawData = JsonConvert.SerializeObject(ImgData.Thermal, Formatting.Indented);
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Sistema le temp range min/Max
|
||||
/// </summary>
|
||||
private void setRangeTemp()
|
||||
{
|
||||
currConf.TargetRange.Min = minRangeTemp;
|
||||
currConf.TargetRange.Max = maxRangeTemp;
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Ultimo range di temperature osservato
|
||||
/// </summary>
|
||||
protected Range<double> lastTempRange
|
||||
{
|
||||
get
|
||||
{
|
||||
return _lastTempRange;
|
||||
}
|
||||
set
|
||||
{
|
||||
_lastTempRange = value;
|
||||
lblMinTemp.Text = $"{value.Minimum:N2}";
|
||||
lblMaxTemp.Text = $"{value.Maximum:N2}";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if false
|
||||
private void getTemperatures()
|
||||
{
|
||||
if (ImgData.Thermal != null)
|
||||
{
|
||||
lastReadTemp = 0;
|
||||
if (readTemp)
|
||||
{
|
||||
// recupero temp da FLIR
|
||||
lastReadTemp = ImgData.Thermal.GetValueAt(ImgData.lastPoint).Value;
|
||||
|
||||
// calcolo temp da RGB considerato limiti minMAX...
|
||||
//int rgbVal = ImgData.lastImageOrig.Image.GetPixel(ImgData.lastPoint.X, ImgData.lastPoint.Y).R;
|
||||
int rgbVal = getRSmooth(ImgData.lastPoint);
|
||||
lastCalcTemp = lastTempRange.Minimum + ((lastTempRange.Maximum - lastTempRange.Minimum) * rgbVal / 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// recupera immagine effettuando eventuale salvataggio
|
||||
@@ -740,7 +755,10 @@ namespace ThermalImageStreamerDemo
|
||||
ImgData.Decorated = ImgData.Thermal.Image;
|
||||
if (doSave)
|
||||
{
|
||||
#if false
|
||||
saveImgFile();
|
||||
#endif
|
||||
ImgData.saveImgFiles();
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
@@ -824,14 +842,24 @@ namespace ThermalImageStreamerDemo
|
||||
updateDestPt();
|
||||
}
|
||||
|
||||
private void txtMaxScale_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
setRangeTemp();
|
||||
}
|
||||
|
||||
private void txtMinScale_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
setRangeTemp();
|
||||
}
|
||||
|
||||
private void updateDestPt()
|
||||
{
|
||||
currConf.destPoints.Coords = new List<Point>();
|
||||
currConf.DestPoints.Coords = new List<Point>();
|
||||
// ciclo i punti A-B-C-D...
|
||||
currConf.destPoints.Coords.Add(new Point() { X = 0, Y = 0 });
|
||||
currConf.destPoints.Coords.Add(new Point() { X = dimX, Y = 0 });
|
||||
currConf.destPoints.Coords.Add(new Point() { X = dimX, Y = dimY });
|
||||
currConf.destPoints.Coords.Add(new Point() { X = 0, Y = dimY });
|
||||
currConf.DestPoints.Coords.Add(new Point() { X = 0, Y = 0 });
|
||||
currConf.DestPoints.Coords.Add(new Point() { X = dimX, Y = 0 });
|
||||
currConf.DestPoints.Coords.Add(new Point() { X = dimX, Y = dimY });
|
||||
currConf.DestPoints.Coords.Add(new Point() { X = 0, Y = dimY });
|
||||
// salvo conf
|
||||
saveConf();
|
||||
}
|
||||
@@ -843,28 +871,36 @@ namespace ThermalImageStreamerDemo
|
||||
lblOrigC.Text = "C";
|
||||
lblOrigD.Text = "D";
|
||||
// popolo
|
||||
if (currConf.origPoints.Coords.Count > 0)
|
||||
if (currConf.OrigPoints.Coords.Count > 0)
|
||||
{
|
||||
lblOrigA.Text = $"A: ({currConf.origPoints.Coords[0].X},{currConf.origPoints.Coords[0].Y})";
|
||||
lblOrigA.Text = $"A: ({currConf.OrigPoints.Coords[0].X},{currConf.OrigPoints.Coords[0].Y})";
|
||||
}
|
||||
if (currConf.origPoints.Coords.Count > 1)
|
||||
if (currConf.OrigPoints.Coords.Count > 1)
|
||||
{
|
||||
lblOrigB.Text = $"B: ({currConf.origPoints.Coords[1].X},{currConf.origPoints.Coords[1].Y})";
|
||||
lblOrigB.Text = $"B: ({currConf.OrigPoints.Coords[1].X},{currConf.OrigPoints.Coords[1].Y})";
|
||||
}
|
||||
if (currConf.origPoints.Coords.Count > 2)
|
||||
if (currConf.OrigPoints.Coords.Count > 2)
|
||||
{
|
||||
lblOrigC.Text = $"C: ({currConf.origPoints.Coords[2].X},{currConf.origPoints.Coords[2].Y})";
|
||||
lblOrigC.Text = $"C: ({currConf.OrigPoints.Coords[2].X},{currConf.OrigPoints.Coords[2].Y})";
|
||||
}
|
||||
if (currConf.origPoints.Coords.Count > 3)
|
||||
if (currConf.OrigPoints.Coords.Count > 3)
|
||||
{
|
||||
lblOrigD.Text = $"D: ({currConf.origPoints.Coords[3].X},{currConf.origPoints.Coords[3].Y})";
|
||||
lblOrigD.Text = $"D: ({currConf.OrigPoints.Coords[3].X},{currConf.OrigPoints.Coords[3].Y})";
|
||||
ImgData.calculateTarget(chkParallel.Checked, chkRevProc.Checked);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateStatDisplay()
|
||||
{
|
||||
lblStats.Text = $"Camera: {msLastCam}ms | Persp {msLastTra}ms | Color {msLastCol}ms | Points {msLastPts}ms | Measures {msLastMsr}ms";
|
||||
if (ImgData.ExTime.Stats.Count > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
lblStats.Text = $"Camera: {msLastCam}ms | Persp {ImgData.ExTime.Stats["ImageTransf"]}ms | Color {ImgData.ExTime.Stats["ImageColor"]}ms | Points {ImgData.ExTime.Stats["AddPoints"]}ms | Measures {ImgData.ExTime.Stats["GetTemperatures"]}ms";
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTempDisplay()
|
||||
@@ -896,47 +932,16 @@ namespace ThermalImageStreamerDemo
|
||||
{
|
||||
lblTempRGB.ForeColor = Color.Red;
|
||||
}
|
||||
|
||||
// mostro minimo / massimo
|
||||
lblMinTemp.Text = $"{ImgData.Thermal.Scale.Range.Minimum:N2}";
|
||||
lblMaxTemp.Text = $"{ImgData.Thermal.Scale.Range.Maximum:N2}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Calcola valore R ponderato dato un punto + intorno
|
||||
/// </summary>
|
||||
/// <param name="reqPoint"></param>
|
||||
/// <returns></returns>
|
||||
protected int getRSmooth(Point reqPoint)
|
||||
{
|
||||
int answ = 0;
|
||||
if (ImgData.Origin != null)
|
||||
{
|
||||
// solo se il punto è entro limiti immagine --> 1 pixel entro bordo
|
||||
if (reqPoint.X > 0 && reqPoint.X < ImgData.Origin.Width)
|
||||
{
|
||||
if (reqPoint.Y > 0 && reqPoint.Y < ImgData.Origin.Height)
|
||||
{
|
||||
int rgbValMain = ImgData.Origin.GetPixel(ImgData.lastPoint.X, ImgData.lastPoint.Y).R;
|
||||
|
||||
int rgbValN = ImgData.Origin.GetPixel(ImgData.lastPoint.X, ImgData.lastPoint.Y - 1).R;
|
||||
int rgbValNO = ImgData.Origin.GetPixel(ImgData.lastPoint.X - 1, ImgData.lastPoint.Y - 1).R;
|
||||
int rgbValO = ImgData.Origin.GetPixel(ImgData.lastPoint.X - 1, ImgData.lastPoint.Y).R;
|
||||
int rgbValSO = ImgData.Origin.GetPixel(ImgData.lastPoint.X - 1, ImgData.lastPoint.Y + 1).R;
|
||||
int rgbValS = ImgData.Origin.GetPixel(ImgData.lastPoint.X, ImgData.lastPoint.Y + 1).R;
|
||||
int rgbValSE = ImgData.Origin.GetPixel(ImgData.lastPoint.X + 1, ImgData.lastPoint.Y + 1).R;
|
||||
int rgbValE = ImgData.Origin.GetPixel(ImgData.lastPoint.X + 1, ImgData.lastPoint.Y).R;
|
||||
int rgbValNE = ImgData.Origin.GetPixel(ImgData.lastPoint.X + 1, ImgData.lastPoint.Y - 1).R;
|
||||
// calcolo valore ponderato
|
||||
answ = (int)Math.Round((double)(1 * rgbValMain + 1 * (rgbValN + rgbValO + rgbValS + rgbValE) + rgbValNO + rgbValSO + rgbValSE + rgbValNE) / 10, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
#endif
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public void discoveryCamera()
|
||||
|
||||
+140
-7
@@ -1,9 +1,13 @@
|
||||
using Flir.Atlas.Image;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -16,6 +20,16 @@ namespace ThermoCamUtils
|
||||
{
|
||||
#region Protected Fields
|
||||
|
||||
protected const string colorPath = "images\\Color";
|
||||
|
||||
protected const string confFormat = "json";
|
||||
|
||||
protected const string currImgFile = "_last";
|
||||
|
||||
protected const string imgFormat = "jpg";
|
||||
|
||||
protected const string thermPath = "images\\Therm";
|
||||
|
||||
/// <summary>
|
||||
/// Ultimo range di temperature osservato
|
||||
/// </summary>
|
||||
@@ -30,6 +44,8 @@ namespace ThermoCamUtils
|
||||
|
||||
#region Public Fields
|
||||
|
||||
public static readonly string BASE_PATH = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||
|
||||
/// <summary>
|
||||
/// Statistiche esecuzione task
|
||||
/// </summary>
|
||||
@@ -83,6 +99,35 @@ namespace ThermoCamUtils
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private void drawPoint(Color currColor, Point currPoint)
|
||||
{
|
||||
// disegno!
|
||||
using (Graphics gr = Graphics.FromImage(Decorated))
|
||||
{
|
||||
gr.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
|
||||
Point[] crsPoints = new Point[4];
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
crsPoints[i] = currPoint;
|
||||
}
|
||||
crsPoints[0].X = crsPoints[0].X - 4;
|
||||
crsPoints[1].X = crsPoints[1].X + 4;
|
||||
crsPoints[2].Y = crsPoints[2].Y - 4;
|
||||
crsPoints[3].Y = crsPoints[3].Y + 4;
|
||||
|
||||
using (Pen thick_pen = new Pen(currColor, 1))
|
||||
{
|
||||
gr.DrawLine(thick_pen, crsPoints[0], crsPoints[1]);
|
||||
gr.DrawLine(thick_pen, crsPoints[2], crsPoints[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
/// <summary>
|
||||
@@ -137,7 +182,7 @@ namespace ThermoCamUtils
|
||||
lastTempRange = new Range<double>(Thermal.Scale.Range.Minimum, Thermal.Scale.Range.Maximum);
|
||||
|
||||
sw.Restart();
|
||||
var pTransf = new PerspectiveTransform(currConf.origPoints.Coords, currConf.destPoints.Coords);
|
||||
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;
|
||||
@@ -167,6 +212,33 @@ namespace ThermoCamUtils
|
||||
}
|
||||
}
|
||||
|
||||
public void drawCrossAtPoints()
|
||||
{
|
||||
if (Thermal != null)
|
||||
{
|
||||
sw.Restart();
|
||||
// se ho dei punti x trasformazione --> disegno
|
||||
if (currConf.OrigPoints.curr > 0)
|
||||
{
|
||||
foreach (var item in currConf.OrigPoints.Coords)
|
||||
{
|
||||
drawPoint(Color.Green, item);
|
||||
}
|
||||
}
|
||||
// se ho punto acquisizione temp --> disegno!
|
||||
if (currConf.MeasPoints.Count > 0)
|
||||
{
|
||||
foreach (var item in currConf.MeasPoints)
|
||||
{
|
||||
// disegno!
|
||||
drawPoint(Color.Blue, item.Coords);
|
||||
}
|
||||
}
|
||||
sw.Stop();
|
||||
ExTime.recordData("AddPoints", sw.ElapsedMilliseconds);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupera temperature coi 2 metodi da FLIR e da B/N
|
||||
/// </summary>
|
||||
@@ -178,13 +250,19 @@ namespace ThermoCamUtils
|
||||
lastReadTemp = 0;
|
||||
if (readTemp)
|
||||
{
|
||||
// recupero temp da FLIR
|
||||
lastReadTemp = Thermal.GetValueAt(lastPoint).Value;
|
||||
sw.Restart();
|
||||
foreach (var item in currConf.MeasPoints)
|
||||
{
|
||||
// recupero temp da FLIR
|
||||
lastReadTemp = Thermal.GetValueAt(item.Coords).Value;
|
||||
|
||||
// calcolo temp da RGB considerato limiti minMAX...
|
||||
//int rgbVal = lastImageOrig.Image.GetPixel(lastPoint.X, lastPoint.Y).R;
|
||||
int rgbVal = getRSmooth(lastPoint);
|
||||
lastCalcTemp = lastTempRange.Minimum + ((lastTempRange.Maximum - lastTempRange.Minimum) * rgbVal / 255);
|
||||
// calcolo temp da RGB considerato limiti minMAX...
|
||||
//int rgbVal = lastImageOrig.Image.GetPixel(lastPoint.X, lastPoint.Y).R;
|
||||
int rgbVal = getRSmooth(item.Coords);
|
||||
lastCalcTemp = lastTempRange.Minimum + ((lastTempRange.Maximum - lastTempRange.Minimum) * rgbVal / 255);
|
||||
}
|
||||
sw.Stop();
|
||||
ExTime.recordData("GetTemperatures", sw.ElapsedMilliseconds);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -212,6 +290,61 @@ namespace ThermoCamUtils
|
||||
}
|
||||
}
|
||||
|
||||
public void saveImgFiles()
|
||||
{
|
||||
try
|
||||
{
|
||||
// fix percorsi
|
||||
string thermoDirPath = $"{BASE_PATH}\\{thermPath}";
|
||||
string thermoColPath = $"{BASE_PATH}\\{colorPath}";
|
||||
if (!Directory.Exists(thermoDirPath))
|
||||
{
|
||||
Directory.CreateDirectory(thermoDirPath);
|
||||
}
|
||||
if (!Directory.Exists(thermoColPath))
|
||||
{
|
||||
Directory.CreateDirectory(thermoColPath);
|
||||
}
|
||||
|
||||
// nomi file
|
||||
string themoFilePath = $"{thermoDirPath}\\{currImgFile}.{imgFormat}";
|
||||
string themoDataPath = $"{thermoDirPath}\\{currImgFile}.{confFormat}";
|
||||
string colorFilePath = $"{thermoColPath}\\{currImgFile}.{imgFormat}";
|
||||
|
||||
// salvo thermo!
|
||||
Thermal.Scale.IsAutoAdjustEnabled = true;
|
||||
Thermal.SaveSnapshot(themoFilePath);
|
||||
// salvo conf thermo
|
||||
string rawData = JsonConvert.SerializeObject(Thermal, Formatting.Indented);
|
||||
File.WriteAllText(themoDataPath, rawData);
|
||||
|
||||
// salvo colorata
|
||||
ColorTransf.Save(colorFilePath);
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Salvo il punto di misura selezionato
|
||||
/// </summary>
|
||||
/// <param name="addOnEnd"></param>
|
||||
public void saveMeasurePoint(bool addOnEnd)
|
||||
{
|
||||
// se NO devo accodare resetto...
|
||||
if (!addOnEnd)
|
||||
{
|
||||
currConf.MeasPoints = new List<MeasurePoint>();
|
||||
}
|
||||
MeasurePoint newPoint = new MeasurePoint()
|
||||
{
|
||||
Id = currConf.MeasPoints.Count,
|
||||
Coords = lastPoint,
|
||||
Temperature = 0
|
||||
};
|
||||
currConf.MeasPoints.Add(newPoint);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,28 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ThermoCamUtils
|
||||
{
|
||||
public class MeasurePoint
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// Punto di riferimento
|
||||
/// </summary>
|
||||
public Point Coords { get; set; } = new Point();
|
||||
|
||||
/// <summary>
|
||||
/// Id del punto
|
||||
/// </summary>
|
||||
public int Id { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Temperatura rilevata al punto
|
||||
/// </summary>
|
||||
public double Temperature { get; set; } = 0;
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
|
||||
public class SetPoints
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Flir.Atlas.Live.Discovery;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -44,6 +45,15 @@ namespace ThermoCamUtils
|
||||
|
||||
public class ThermoCamConf
|
||||
{
|
||||
#region Public Fields
|
||||
|
||||
/// <summary>
|
||||
/// Elenco di punti x misurazione temperatura
|
||||
/// </summary>
|
||||
public List<MeasurePoint> MeasPoints = new List<MeasurePoint>();
|
||||
|
||||
#endregion Public Fields
|
||||
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
@@ -54,12 +64,12 @@ namespace ThermoCamUtils
|
||||
/// <summary>
|
||||
/// Punti su IMG destinazione
|
||||
/// </summary>
|
||||
public SetPoints destPoints { get; set; } = new SetPoints();
|
||||
public SetPoints DestPoints { get; set; } = new SetPoints();
|
||||
|
||||
/// <summary>
|
||||
/// Punti su IMG origine
|
||||
/// </summary>
|
||||
public SetPoints origPoints { get; set; } = new SetPoints();
|
||||
public SetPoints OrigPoints { get; set; } = new SetPoints();
|
||||
|
||||
/// <summary>
|
||||
/// Range scala colori desiderata
|
||||
|
||||
@@ -46,6 +46,9 @@
|
||||
<Reference Include="Flir.Atlas.Live">
|
||||
<HintPath>..\..\..\..\..\..\Program Files (x86)\FLIR Systems\FLIR Atlas SDK 4\bin\x64\Flir.Atlas.Live.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="OpenCvSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\OpenCvSharp4.4.5.1.20210208\lib\net461\OpenCvSharp.dll</HintPath>
|
||||
</Reference>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net462" />
|
||||
<package id="OpenCvSharp4" version="4.5.1.20210208" targetFramework="net462" />
|
||||
<package id="OpenCvSharp4.runtime.win" version="4.5.1.20210208" targetFramework="net462" />
|
||||
<package id="OpenCvSharp4.Windows" version="4.5.1.20210208" targetFramework="net462" />
|
||||
|
||||
Reference in New Issue
Block a user