Fix scala cromatica assoluta da impostazione

This commit is contained in:
Samuele E. Locatelli
2021-02-12 19:33:34 +01:00
parent c9efa885d9
commit fac46ce12e
6 changed files with 237 additions and 155 deletions
+54 -41
View File
@@ -45,11 +45,10 @@
this.btnLoad = new System.Windows.Forms.Button();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.lblTempRGB = new System.Windows.Forms.Label();
this.chkAutoTemp = new System.Windows.Forms.CheckBox();
this.label6 = new System.Windows.Forms.Label();
this.txtMaxTemp = new System.Windows.Forms.TextBox();
this.txtMaxScale = new System.Windows.Forms.TextBox();
this.label7 = new System.Windows.Forms.Label();
this.txtMinTemp = new System.Windows.Forms.TextBox();
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();
@@ -76,6 +75,8 @@
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();
@@ -226,17 +227,18 @@
//
// groupBox3
//
this.groupBox3.Controls.Add(this.lblMaxTemp);
this.groupBox3.Controls.Add(this.lblMinTemp);
this.groupBox3.Controls.Add(this.lblTempRGB);
this.groupBox3.Controls.Add(this.chkAutoTemp);
this.groupBox3.Controls.Add(this.label6);
this.groupBox3.Controls.Add(this.txtMaxTemp);
this.groupBox3.Controls.Add(this.txtMaxScale);
this.groupBox3.Controls.Add(this.label7);
this.groupBox3.Controls.Add(this.txtMinTemp);
this.groupBox3.Controls.Add(this.txtMinScale);
this.groupBox3.Controls.Add(this.chkReadTemp);
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, 118);
this.groupBox3.Size = new System.Drawing.Size(175, 175);
this.groupBox3.TabIndex = 5;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Temperature";
@@ -253,54 +255,41 @@
this.lblTempRGB.Text = "? °C";
this.lblTempRGB.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// chkAutoTemp
//
this.chkAutoTemp.AutoSize = true;
this.chkAutoTemp.Checked = true;
this.chkAutoTemp.CheckState = System.Windows.Forms.CheckState.Checked;
this.chkAutoTemp.Location = new System.Drawing.Point(4, 41);
this.chkAutoTemp.Name = "chkAutoTemp";
this.chkAutoTemp.Size = new System.Drawing.Size(91, 17);
this.chkAutoTemp.TabIndex = 14;
this.chkAutoTemp.Text = "Auto Min-Max";
this.chkAutoTemp.UseVisualStyleBackColor = true;
this.chkAutoTemp.CheckedChanged += new System.EventHandler(this.chkAutoTemp_CheckedChanged);
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(7, 94);
this.label6.Location = new System.Drawing.Point(7, 135);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(57, 13);
this.label6.TabIndex = 13;
this.label6.Text = "Max Temp";
//
// txtMaxTemp
// txtMaxScale
//
this.txtMaxTemp.Location = new System.Drawing.Point(92, 91);
this.txtMaxTemp.Name = "txtMaxTemp";
this.txtMaxTemp.Size = new System.Drawing.Size(77, 20);
this.txtMaxTemp.TabIndex = 12;
this.txtMaxTemp.Text = "50";
this.txtMaxTemp.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.txtMaxScale.Location = new System.Drawing.Point(92, 132);
this.txtMaxScale.Name = "txtMaxScale";
this.txtMaxScale.Size = new System.Drawing.Size(77, 20);
this.txtMaxScale.TabIndex = 12;
this.txtMaxScale.Text = "60";
this.txtMaxScale.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(7, 67);
this.label7.Location = new System.Drawing.Point(7, 108);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(54, 13);
this.label7.TabIndex = 11;
this.label7.Text = "Min Temp";
//
// txtMinTemp
// txtMinScale
//
this.txtMinTemp.Location = new System.Drawing.Point(92, 64);
this.txtMinTemp.Name = "txtMinTemp";
this.txtMinTemp.Size = new System.Drawing.Size(77, 20);
this.txtMinTemp.TabIndex = 10;
this.txtMinTemp.Text = "0";
this.txtMinTemp.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.txtMinScale.Location = new System.Drawing.Point(92, 105);
this.txtMinScale.Name = "txtMinScale";
this.txtMinScale.Size = new System.Drawing.Size(77, 20);
this.txtMinScale.TabIndex = 10;
this.txtMinScale.Text = "0";
this.txtMinScale.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
//
// chkReadTemp
//
@@ -329,7 +318,7 @@
this.chkRevProc.AutoSize = true;
this.chkRevProc.Checked = true;
this.chkRevProc.CheckState = System.Windows.Forms.CheckState.Checked;
this.chkRevProc.Location = new System.Drawing.Point(8, 470);
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;
@@ -341,7 +330,7 @@
this.chkParallel.AutoSize = true;
this.chkParallel.Checked = true;
this.chkParallel.CheckState = System.Windows.Forms.CheckState.Checked;
this.chkParallel.Location = new System.Drawing.Point(8, 489);
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;
@@ -577,6 +566,29 @@
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);
@@ -658,17 +670,18 @@
private System.Windows.Forms.CheckBox chkParallel;
private System.Windows.Forms.CheckBox chkRevProc;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.CheckBox chkAutoTemp;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.TextBox txtMaxTemp;
private System.Windows.Forms.TextBox txtMaxScale;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.TextBox txtMinTemp;
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;
private System.Windows.Forms.CheckBox chkSaveAll;
private System.Windows.Forms.Label lblMaxTemp;
private System.Windows.Forms.Label lblMinTemp;
}
}
+66 -45
View File
@@ -22,7 +22,9 @@ namespace ThermalImageStreamerDemo
private readonly Timer _timerRefreshUi = new Timer();
private Camera _camera;
#if false
private Camera IRCam.ThermoCamera;
#endif
private RecorderForm _recorder;
@@ -170,8 +172,36 @@ namespace ThermalImageStreamerDemo
set
{
_lastTempRange = value;
txtMinTemp.Text = $"{value.Minimum:N2}";
txtMaxTemp.Text = $"{value.Maximum:N2}";
lblMinTemp.Text = $"{value.Minimum:N2}";
lblMaxTemp.Text = $"{value.Maximum:N2}";
}
}
protected double maxScale
{
get
{
double answ = 0;
double.TryParse(txtMaxScale.Text, out answ);
return answ;
}
set
{
txtMaxScale.Text = $"{value:N0}";
}
}
protected double minScale
{
get
{
double answ = 0;
double.TryParse(txtMinScale.Text, out answ);
return answ;
}
set
{
txtMinScale.Text = $"{value:N0}";
}
}
@@ -227,15 +257,6 @@ namespace ThermalImageStreamerDemo
#region Private Methods
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 _recorder_SelectedFileMouseDoubleClick(object sender, SelectedFileEventArgs e)
{
var playback = new PlaybackForm(e.FilePath);
@@ -305,15 +326,12 @@ namespace ThermalImageStreamerDemo
{
try
{
// se auto temp --> imposto min/max
if (chkAutoTemp.Checked)
{
//lastTempRange = new Range<double>(ImgData.lastThermalImage.GetValueFromSignal(ImgData.lastThermalImage.MinSignalValue), ImgData.lastThermalImage.GetValueFromSignal(ImgData.lastThermalImage.MaxSignalValue));
lastTempRange = new Range<double>(ImgData.Thermal.Scale.Range.Minimum, ImgData.Thermal.Scale.Range.Maximum);
}
//lastTempRange = new Range<double>(ImgData.lastThermalImage.GetValueFromSignal(ImgData.lastThermalImage.MinSignalValue), ImgData.lastThermalImage.GetValueFromSignal(ImgData.lastThermalImage.MaxSignalValue));
lastTempRange = new Range<double>(ImgData.Thermal.Scale.Range.Minimum, ImgData.Thermal.Scale.Range.Maximum);
sw.Restart();
var pTransf = new PerspectiveTransform(currConf.origPoints.Coords, currConf.destPoints.Coords);
var rTrasf = new ReColorize(lastTempRange.Minimum, lastTempRange.Maximum);
var rTrasf = new ReColorize(lastTempRange.Minimum, lastTempRange.Maximum, minScale, maxScale);
var transfImg = pTransf.convertImage(ImgData.Origin, dimX, dimY);
ImgData.GrayTransf = transfImg;
sw.Stop();
@@ -342,17 +360,20 @@ namespace ThermalImageStreamerDemo
}
}
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
}
private void chkAutoTemp_CheckedChanged(object sender, EventArgs e)
{
txtMinTemp.Enabled = !chkAutoTemp.Checked;
txtMaxTemp.Enabled = !chkAutoTemp.Checked;
}
private void chkPointSetup_CheckedChanged(object sender, EventArgs e)
{
// deselezione Get Temp
@@ -382,20 +403,20 @@ namespace ThermalImageStreamerDemo
switch (cameraDeviceInfo.SelectedStreamingFormat)
{
case ImageFormat.FlirFileFormat:
_camera = new ThermalCamera();
IRCam.ThermoCamera = new ThermalCamera();
break;
case ImageFormat.Argb:
_camera = new VideoOverlayCamera();
IRCam.ThermoCamera = new VideoOverlayCamera();
break;
default:
throw new ArgumentOutOfRangeException();
}
_camera.ConnectionStatusChanged += _camera_ConnectionStatusChanged;
_camera.GetImage().Changed += Image_Changed;
_camera.Connect(cameraDeviceInfo);
if (_camera.Recorder == null && _recorder != null)
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;
@@ -403,17 +424,17 @@ namespace ThermalImageStreamerDemo
if (_recorder != null)
{
if (!_recorder.IsDisposed)
_recorder.Initialize(_camera);
_recorder.Initialize(IRCam.ThermoCamera);
}
recorderToolStripMenuItem.Enabled = _camera.Recorder != null;
recorderToolStripMenuItem.Enabled = IRCam.ThermoCamera.Recorder != null;
_timerRefreshUi.Start();
}
private void DisconnectCamera()
{
if (_camera == null) return;
if (IRCam.ThermoCamera == null) return;
_camera.Disconnect();
IRCam.ThermoCamera.Disconnect();
}
private void disconnectToolStripMenuItem_Click(object sender, EventArgs e)
@@ -449,15 +470,15 @@ namespace ThermalImageStreamerDemo
private void DisposeCamera()
{
_timerRefreshUi.Stop();
if (_camera == null) return;
if (IRCam.ThermoCamera == null) return;
if (_recorder != null)
{
_recorder.UnInitialize();
_recorder.Dispose();
}
_camera.ConnectionStatusChanged -= _camera_ConnectionStatusChanged;
_camera.GetImage().Changed -= Image_Changed;
_camera.Dispose();
IRCam.ThermoCamera.ConnectionStatusChanged -= Camera_ConnectionStatusChanged;
IRCam.ThermoCamera.GetImage().Changed -= Image_Changed;
IRCam.ThermoCamera.Dispose();
}
private void drawCrossAtPoints()
@@ -656,7 +677,7 @@ namespace ThermalImageStreamerDemo
if (_recorder == null || _recorder.IsDisposed)
{
_recorder = new RecorderForm();
_recorder.Initialize(_camera);
_recorder.Initialize(IRCam.ThermoCamera);
_recorder.SelectedFileMouseDoubleClick += _recorder_SelectedFileMouseDoubleClick;
}
_recorder.Show();
@@ -718,9 +739,9 @@ namespace ThermalImageStreamerDemo
sw.Restart();
if (!IsDirty) return;
IsDirty = false;
if (_camera == null) return;
if (IRCam.ThermoCamera == null) return;
_camera.GetImage().EnterLock();
IRCam.ThermoCamera.GetImage().EnterLock();
try
{
// non funziona
@@ -729,10 +750,10 @@ namespace ThermalImageStreamerDemo
if (!chkAutoTemp.Checked)
{
Range<double> limits = new Range<double>(273.1 + minTemp, 273.1 + maxTemp);
_camera.RemoteControl.CameraSettings.SetScaleLimits(limits);
IRCam.ThermoCamera.RemoteControl.CameraSettings.SetScaleLimits(limits);
}
#endif
ImgData.Thermal = (ThermalImage)_camera.GetImage();
ImgData.Thermal = (ThermalImage)IRCam.ThermoCamera.GetImage();
ImgData.Thermal.TemperatureUnit = TemperatureUnit.Celsius;
ImgData.Thermal.Scale.IsAutoAdjustEnabled = true;
// salvo img locale
@@ -749,7 +770,7 @@ namespace ThermalImageStreamerDemo
}
finally
{
_camera.GetImage().ExitLock();
IRCam.ThermoCamera.GetImage().ExitLock();
}
sw.Stop();
+23
View File
@@ -0,0 +1,23 @@
using Flir.Atlas.Image;
using Flir.Atlas.Live.Device;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ThermoCamUtils
{
public class IRCam
{
#region Public Properties
/// <summary>
/// Oggetto gestione WebCamera
/// </summary>
public static Camera ThermoCamera { get; set; } = new ThermalCamera();
#endregion Public Properties
}
}
@@ -8,6 +8,9 @@ using System.Threading.Tasks;
namespace ThermoCamUtils
{
/// <summary>
/// Classe gestione aree di memoria immagini (thermo, trasformate, ...)
/// </summary>
public class ImageData
{
#region Public Properties
+89 -68
View File
@@ -11,14 +11,99 @@ namespace ThermoCamUtils
{
public class ReColorize
{
protected double minVal = -999;
#region Protected Fields
protected double delta = 0;
protected double maxSca = 5000;
protected double maxVal = 5000;
public ReColorize(double minValue, double maxValue)
protected double minSca = -999;
protected double minVal = -999;
#endregion Protected Fields
#region Public Constructors
public ReColorize(double minValue, double maxValue, double minScale, double maxScale)
{
minVal = minValue;
maxVal = maxValue;
minSca = minScale;
maxSca = maxScale;
delta = minVal - minSca;
}
#endregion Public Constructors
#region Protected Methods
/// <summary>
/// Calcola colore su scala dato rapporto valore B/N su min/max
/// </summary>
/// <param name="ValOrig"></param>
/// <returns></returns>
protected Color Rescale(ref int ValRGB)
{
int R = 0;
int G = 0;
int B = 0;
int ValScal = 0;
// calcolo retta interpolazione per il valore in gradi...Y = M * X + DELTA
double M = (maxVal - minVal) / 255;
double currTemp = M * ValRGB + delta;
// ora calcolo valore scalare
ValScal = (int)(255 * (currTemp - minSca) / (maxSca - minSca));
if (ValScal < 0)
{
R = 0;
G = 0;
B = 0;
}
else if (ValScal <= 51)
{
R = 0;
G = 0;
B = (int)(ValScal * 5);
}
else if (ValScal <= 102)
{
R = (int)((ValScal - 51) * 5);
G = 0;
B = 255;
}
else if (ValScal <= 153)
{
R = 255;
G = 0;
B = (int)(255 - ((ValScal - 102) * 5));
}
else if (ValScal <= 204)
{
R = 255;
G = (int)((ValScal - 153) * 5);
B = 0;
}
else if (ValScal <= 255)
{
R = 255;
G = 255;
B = (int)((ValScal - 204) * 5);
}
else
{
R = 255;
G = 255;
B = 255;
}
return Color.FromArgb(R, G, B);
}
#endregion Protected Methods
#region Public Methods
public Bitmap process(Bitmap original, bool doFast)
{
/*---------------------------------------------
@@ -46,7 +131,6 @@ namespace ThermoCamUtils
int currentLine = y * bitmapData.Stride;
for (int x = 0; x < widthInBytes; x = x + bytesPerPixel)
{
// prendo il rosso
int oldRed = pixels[currentLine + x + 0];
currVal = pixels[currentLine + x + 2];
@@ -62,7 +146,6 @@ namespace ThermoCamUtils
// copy modified bytes back
Marshal.Copy(pixels, 0, ptrFirstPixel, pixels.Length);
imgColor.UnlockBits(bitmapData);
}
else
{
@@ -80,69 +163,7 @@ namespace ThermoCamUtils
return imgColor;
}
/// <summary>
/// Calcola colore su scala dato rapporto valore B/N su min/max
/// </summary>
/// <param name="ValOrig"></param>
/// <returns></returns>
protected Color Rescale(ref int ValOrig)
{
int R = 0;
int G = 0;
int B = 0;
#if false
// calcolo retta interpolazione Y = A * X + B
double M = 255 / (maxVal - minVal);
double Q = 255 - M * maxVal;
double Value = M * currTemp + Q;
#endif
if (ValOrig < 0)
{
R = 0;
G = 0;
B = 0;
}
else if (ValOrig <= 51)
{
R = 0;
G = 0;
B = (int)(ValOrig * 5);
}
else if (ValOrig <= 102)
{
R = (int)((ValOrig - 51) * 5);
G = 0;
B = 255;
}
else if (ValOrig <= 153)
{
R = 255;
G = 0;
B = (int)(255 - ((ValOrig - 102) * 5));
}
else if (ValOrig <= 204)
{
R = 255;
G = (int)((ValOrig - 153) * 5);
B = 0;
}
else if (ValOrig <= 255)
{
R = 255;
G = 255;
B = (int)((ValOrig - 204) * 5);
}
else
{
R = 255;
G = 255;
B = 255;
}
return Color.FromArgb(R, G, B);
}
#endregion Public Methods
}
}
}
+2 -1
View File
@@ -85,7 +85,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="FlirCam.cs" />
<Compile Include="IRCam.cs" />
<Compile Include="ImageData.cs" />
<Compile Include="ThermoCamConf.cs" />
<Compile Include="Enums.cs" />
<Compile Include="Objects.cs" />