You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openCV/OpenCV/Form1.cs

86 lines
2.6 KiB

using System;
using System.Windows.Forms;
using OpenCvSharp;
namespace OpenCV
{
public partial class Form1 : Form
{
IplImage src;
string fileName;
public Form1()
{
InitializeComponent();
}
private string FindFileName()
{
string path = "";
OpenFileDialog dialog = new OpenFileDialog();
DialogResult dialogResult = dialog.ShowDialog();
if (dialogResult == DialogResult.OK)
path = dialog.FileName;
return path;
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
fileName = FindFileName();
if (String.IsNullOrEmpty(fileName))
return;
src = new IplImage(fileName);
OpenCVClass Converter = new OpenCVClass();
pictureBoxIpl1.ImageIpl = src;
//CvPoint2D32f[] srcPoints = new CvPoint2D32f[]
//{
// new CvPoint2D32f(100.0, 100.0),
// new CvPoint2D32f(src.Width - 100.0, 100.0),
// new CvPoint2D32f(100.0, src.Height - 100.0)
//};
//CvPoint2D32f[] dstPoints = new CvPoint2D32f[]
//{
// new CvPoint2D32f(300.0, 100.0),
// new CvPoint2D32f(src.Width - 100.0, 100.0),
// new CvPoint2D32f(100.0, src.Height - 100.0)
//};
//pictureBoxIpl2.ImageIpl = Converter.AffineImage(src, srcPoints, dstPoints);
CvPoint2D32f[] srcPoints = new CvPoint2D32f[]
{
new CvPoint2D32f(600.0, 600.0),
new CvPoint2D32f(300.0, 900.0),
new CvPoint2D32f(1300.0, 600.0),
new CvPoint2D32f(1600.0, 900.0)
};
CvPoint2D32f[] dstPoints = new CvPoint2D32f[]
{
new CvPoint2D32f(0.0, 0.0),
new CvPoint2D32f(0.0, src.Height),
new CvPoint2D32f(src.Width, 0.0),
new CvPoint2D32f(src.Width, src.Height)
};
pictureBoxIpl2.ImageIpl = Converter.PerspectiveImage(src, srcPoints, dstPoints);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Cv.ReleaseImage(src);
if (src != null)
src.Dispose();
}
}
}