test reverse trasformata punti
This commit is contained in:
Generated
-7
@@ -119,13 +119,6 @@
|
||||
this.disconnectToolStripMenuItem.Text = "Disconnect";
|
||||
this.disconnectToolStripMenuItem.Click += new System.EventHandler(this.disconnectToolStripMenuItem_Click);
|
||||
//
|
||||
// openToolStripMenuItem
|
||||
//
|
||||
this.openToolStripMenuItem.Name = "openToolStripMenuItem";
|
||||
this.openToolStripMenuItem.Size = new System.Drawing.Size(133, 22);
|
||||
this.openToolStripMenuItem.Text = "Open...";
|
||||
this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click);
|
||||
//
|
||||
// cameraToolStripMenuItem
|
||||
//
|
||||
this.cameraToolStripMenuItem.Enabled = false;
|
||||
|
||||
@@ -352,18 +352,6 @@ namespace Thermo.Cam.Setup
|
||||
{
|
||||
}
|
||||
|
||||
private void openToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
using (var dialog = new OpenFileDialog())
|
||||
{
|
||||
dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + @"\FLIR";
|
||||
dialog.Filter = FileFilter;
|
||||
if (dialog.ShowDialog() != DialogResult.OK) return;
|
||||
var playback = new PlaybackForm(dialog.FileName);
|
||||
playback.Show();
|
||||
}
|
||||
}
|
||||
|
||||
private void pictureBox1_Click(object sender, EventArgs e)
|
||||
{
|
||||
// calcolo la ratio img originale --> pictureBox
|
||||
@@ -379,7 +367,23 @@ namespace Thermo.Cam.Setup
|
||||
{ }
|
||||
// trasformo punto in equivalente originale
|
||||
var mea = (MouseEventArgs)e;
|
||||
ThermoCamCont.lastPoint = new Point() { X = (int)(mea.X / ratio), Y = (int)(mea.Y / ratio) };
|
||||
var clickPoint = new Point() { X = (int)(mea.X / ratio), Y = (int)(mea.Y / ratio) };
|
||||
// se sono nell'immagine originale
|
||||
if (showOrigBig)
|
||||
{
|
||||
ThermoCamCont.lastPoint = clickPoint;
|
||||
}
|
||||
else
|
||||
{
|
||||
// altrimenti antitrasformata...
|
||||
List<Point> point2fix = new List<Point>();
|
||||
point2fix.Add(clickPoint);
|
||||
var revPoint = ThermoCamCont.reversePoint(point2fix);
|
||||
if (revPoint.Count > 0)
|
||||
{
|
||||
ThermoCamCont.lastPoint = revPoint[0];
|
||||
}
|
||||
}
|
||||
lblPoint.Text = $"({mea.X},{mea.Y}) --> ({ThermoCamCont.lastPoint.X},{ThermoCamCont.lastPoint.Y})";
|
||||
if (pointSetup)
|
||||
{
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Thermo.Cam.Utils
|
||||
|
||||
protected List<CameraDeviceInfo> discoveredDevices = new List<CameraDeviceInfo>();
|
||||
|
||||
protected Timer timerAutoconnect = new Timer();
|
||||
protected System.Timers.Timer timerAutoconnect = new System.Timers.Timer();
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
@@ -91,54 +91,11 @@ namespace Thermo.Cam.Utils
|
||||
}
|
||||
}
|
||||
|
||||
private void DiscoveryForm_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
Stop();
|
||||
}
|
||||
|
||||
private void DiscoveryForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
Start();
|
||||
timerAutoconnect.Start();
|
||||
}
|
||||
|
||||
private void RemoveDevice(CameraDeviceInfo cameraDeviceInfo)
|
||||
{
|
||||
discoveredDevices.Remove(cameraDeviceInfo);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Stop();
|
||||
_discovery = new Discovery();
|
||||
_discovery.DeviceFound += _discovery_DeviceFound;
|
||||
_discovery.DeviceLost += _discovery_DeviceLost;
|
||||
_discovery.DeviceError += _discovery_DeviceError;
|
||||
|
||||
// Scan for camera devices on all interfaces. If you are only interested in devices from i.e. USB
|
||||
// then you can start Discovery with the bit-flag Interface.Usb.
|
||||
|
||||
// _discovery.Start(Interface.Usb);
|
||||
|
||||
// or with a combination
|
||||
// _discovery.Start(Interface.Network | Interface.Usb);
|
||||
|
||||
// Start discovery, scan on all interfaces.
|
||||
// This requires that Bonjour and the Pleora drivers are installed, see the Atlas web page for more information.
|
||||
_discovery.Start();
|
||||
}
|
||||
|
||||
private void Stop()
|
||||
{
|
||||
if (_discovery == null) return;
|
||||
_discovery.DeviceFound -= _discovery_DeviceFound;
|
||||
_discovery.DeviceLost -= _discovery_DeviceLost;
|
||||
_discovery.DeviceError -= _discovery_DeviceError;
|
||||
// Stop discovery might take some time. Put dispose of discovery on a background thread.
|
||||
ThreadPool.QueueUserWorkItem(DisposeDiscovery, _discovery);
|
||||
_discovery = null;
|
||||
}
|
||||
|
||||
private void timerAutoconnect_Tick(object sender, EventArgs e)
|
||||
{
|
||||
timerAutoconnect.Stop();
|
||||
@@ -159,5 +116,47 @@ namespace Thermo.Cam.Utils
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public void Start()
|
||||
{
|
||||
Stop();
|
||||
_discovery = new Discovery();
|
||||
_discovery.DeviceFound += _discovery_DeviceFound;
|
||||
_discovery.DeviceLost += _discovery_DeviceLost;
|
||||
_discovery.DeviceError += _discovery_DeviceError;
|
||||
|
||||
// Scan for camera devices on all interfaces. If you are only interested in devices from i.e. USB
|
||||
// then you can start Discovery with the bit-flag Interface.Usb.
|
||||
|
||||
// _discovery.Start(Interface.Usb);
|
||||
|
||||
// or with a combination
|
||||
// _discovery.Start(Interface.Network | Interface.Usb);
|
||||
|
||||
// Start discovery, scan on all interfaces.
|
||||
// This requires that Bonjour and the Pleora drivers are installed, see the Atlas web page for more information.
|
||||
_discovery.Start();
|
||||
|
||||
// avvio timer...
|
||||
timerAutoconnect.Start();
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
// chiudo timer...
|
||||
timerAutoconnect.Stop();
|
||||
|
||||
if (_discovery == null) return;
|
||||
_discovery.DeviceFound -= _discovery_DeviceFound;
|
||||
_discovery.DeviceLost -= _discovery_DeviceLost;
|
||||
_discovery.DeviceError -= _discovery_DeviceError;
|
||||
// Stop discovery might take some time. Put dispose of discovery on a background thread.
|
||||
ThreadPool.QueueUserWorkItem(DisposeDiscovery, _discovery);
|
||||
_discovery = null;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
using OpenCvSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Thermo.Cam.Utils
|
||||
{
|
||||
public class PerspTrans
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private Point2f[] dstPoints = new Point2f[] {
|
||||
new Point2f(600, 0),
|
||||
new Point2f(0, 0),
|
||||
new Point2f(0, 400),
|
||||
new Point2f(600, 400),
|
||||
};
|
||||
|
||||
private Point2f[] srcPoints = new Point2f[] {
|
||||
new Point2f(300, 0),
|
||||
new Point2f(0, 0),
|
||||
new Point2f(0, 200),
|
||||
new Point2f(300, 200),
|
||||
};
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Protected Fields
|
||||
|
||||
protected Mat OriginalImage;
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
public PerspTrans(List<System.Drawing.Point> _srcPoints, List<System.Drawing.Point> _dstPoints)
|
||||
{
|
||||
srcPoints = convDraw2CV(_srcPoints);
|
||||
dstPoints = convDraw2CV(_dstPoints);
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
/// <summary>
|
||||
/// Conversione array di punti Point2f --> System.Drawings
|
||||
/// </summary>
|
||||
/// <param name="origList"></param>
|
||||
/// <returns></returns>
|
||||
protected List<System.Drawing.Point> convCV2Draw(Point2f[] origList)
|
||||
{
|
||||
List<System.Drawing.Point> answ = origList.Select(item => new System.Drawing.Point() { X = (int)item.X, Y = (int)item.Y }).ToList();
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Conversione array di punti System.Drawings --> Point2f
|
||||
/// </summary>
|
||||
/// <param name="origList"></param>
|
||||
/// <returns></returns>
|
||||
protected Point2f[] convDraw2CV(List<System.Drawing.Point> origList)
|
||||
{
|
||||
Point2f[] answ = origList.Select(item => new Point2f(item.X, item.Y)).ToArray();
|
||||
return answ;
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Public Methods
|
||||
|
||||
// This is the function that converts IplImage image
|
||||
// into Bitmap
|
||||
public static Bitmap MatToBitmap(Mat image)
|
||||
{
|
||||
return OpenCvSharp.Extensions.BitmapConverter.ToBitmap(image);
|
||||
}
|
||||
|
||||
public Bitmap convertImage(Bitmap OrigImage, int dimX, int dimY)
|
||||
{
|
||||
Bitmap answ = OrigImage;
|
||||
OriginalImage = OpenCvSharp.Extensions.BitmapConverter.ToMat(OrigImage);
|
||||
// verifica siano 4 sorgente e 4 dest...
|
||||
if (srcPoints.Length == 4 && dstPoints.Length == 4)
|
||||
{
|
||||
using var matrix = Cv2.GetPerspectiveTransform(srcPoints, dstPoints);
|
||||
using var dst = new Mat(new OpenCvSharp.Size(dimX, dimY), MatType.CV_8UC3);
|
||||
Cv2.WarpPerspective(OriginalImage, dst, matrix, dst.Size());
|
||||
|
||||
answ = MatToBitmap(dst);
|
||||
}
|
||||
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calcola antitrasformata x il punto dallo spazio di destinazione a quello di origine (secondo matrice di trasformazione)
|
||||
/// </summary>
|
||||
/// <param name="reqPointDest">Punto nelle corrd dello spazio DEST</param>
|
||||
/// <returns></returns>
|
||||
public List<System.Drawing.Point> getReversedPoint(List<System.Drawing.Point> reqPointDest)
|
||||
{
|
||||
List<System.Drawing.Point> answ = new List<System.Drawing.Point>();
|
||||
// trasformo
|
||||
var puntiDest = convDraw2CV(reqPointDest);
|
||||
if (srcPoints.Length == 4 && dstPoints.Length == 4)
|
||||
{
|
||||
using var matrix = Cv2.GetPerspectiveTransform(srcPoints, dstPoints);
|
||||
var puntiOrig = Cv2.PerspectiveTransform(puntiDest, matrix);
|
||||
if (puntiOrig.Count() > 0)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
return answ;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
using OpenCvSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Thermo.Cam.Utils
|
||||
{
|
||||
public class PerspectiveTransform
|
||||
{
|
||||
Point2f[] srcPoints = new Point2f[] {
|
||||
new Point2f(0, 0),
|
||||
new Point2f(0, 0),
|
||||
new Point2f(0, 0),
|
||||
new Point2f(0, 0),
|
||||
};
|
||||
|
||||
Point2f[] dstPoints = new Point2f[] {
|
||||
new Point2f(600, 0),
|
||||
new Point2f(0, 0),
|
||||
new Point2f(0, 400),
|
||||
new Point2f(600, 400),
|
||||
};
|
||||
|
||||
protected Mat OriginalImage;
|
||||
|
||||
|
||||
|
||||
public PerspectiveTransform(List<System.Drawing.Point> _srcPoints, List<System.Drawing.Point> _dstPoints)
|
||||
{
|
||||
srcPoints = convertPoints(_srcPoints);
|
||||
dstPoints = convertPoints(_dstPoints);
|
||||
}
|
||||
|
||||
protected Point2f[] convertPoints(List<System.Drawing.Point> origList)
|
||||
{
|
||||
Point2f[] answ = new Point2f[origList.Count];
|
||||
for (int i = 0; i < origList.Count; i++)
|
||||
{
|
||||
answ[i] = new Point2f(origList[i].X, origList[i].Y);
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
public Bitmap convertImage(Bitmap OrigImage, int dimX, int dimY)
|
||||
{
|
||||
Bitmap answ = OrigImage;
|
||||
OriginalImage = OpenCvSharp.Extensions.BitmapConverter.ToMat(OrigImage);
|
||||
// verifica siano 4 sorgente e 4 dest...
|
||||
if (srcPoints.Length == 4 && dstPoints.Length == 4)
|
||||
{
|
||||
using var matrix = Cv2.GetPerspectiveTransform(srcPoints, dstPoints);
|
||||
using var dst = new Mat(new OpenCvSharp.Size(dimX, dimY), MatType.CV_8UC3);
|
||||
Cv2.WarpPerspective(OriginalImage, dst, matrix, dst.Size());
|
||||
|
||||
answ = MatToBitmap(dst);
|
||||
}
|
||||
|
||||
return answ;
|
||||
}
|
||||
|
||||
// This is the function that converts IplImage image
|
||||
// into Bitmap
|
||||
public static Bitmap MatToBitmap(Mat image)
|
||||
{
|
||||
return OpenCvSharp.Extensions.BitmapConverter.ToBitmap(image);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -315,7 +315,7 @@ namespace Thermo.Cam.Utils
|
||||
{
|
||||
// genero immagine BN
|
||||
sw.Restart();
|
||||
var pTransf = new PerspectiveTransform(currConf.OrigPoints.Coords, currConf.DestPoints.Coords);
|
||||
var pTransf = new PerspTrans(currConf.OrigPoints.Coords, currConf.DestPoints.Coords);
|
||||
var transfImg = pTransf.convertImage(Origin, currConf.TargetSize.X, currConf.TargetSize.Y);
|
||||
GrayTransf = transfImg;
|
||||
sw.Stop();
|
||||
@@ -622,6 +622,19 @@ namespace Thermo.Cam.Utils
|
||||
ExTime.recordData("GetAllTemperatures", sw.ElapsedMilliseconds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calcola punti con antitrasformata prospettica
|
||||
/// </summary>
|
||||
/// <param name="trasfPoints">Elenco punti trasformati da invertire</param>
|
||||
/// <returns></returns>
|
||||
public List<Point> reversePoint(List<Point> trasfPoints)
|
||||
{
|
||||
List<Point> answ = trasfPoints;
|
||||
var pTransf = new PerspTrans(currConf.OrigPoints.Coords, currConf.DestPoints.Coords);
|
||||
answ = pTransf.getReversedPoint(trasfPoints);
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Salva su file il file di conf corrente
|
||||
/// </summary>
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
<Compile Include="ThermoCamConf.cs" />
|
||||
<Compile Include="Enums.cs" />
|
||||
<Compile Include="Objects.cs" />
|
||||
<Compile Include="PerspectiveTransform.cs" />
|
||||
<Compile Include="PerspTrans.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ReColorize.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user