C#+EmguCV实现SURF算法
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
C#+EmguCV中SURF算法的实现
EmguCV的官方网站上的例子中,有SURF算法的实现,其实现的时候利用的GPU的加速,看着比较复杂。此外,官网上例子的实现并没有做界面,看着不舒服,加载图片也不是很方便,因此,为了学习,我将官网上的例子进行了修改,去掉了GPU加速的部分,然后在做了显示界面,操作起来更友好些。
我是在Vs2012下使用2.9 Alpha版本的EmgucV做的。
首先显示界面如下图所示,显示界面是两个窗体,第一个如下:
窗体上有两个PictureBox控件,一个用来显示待匹配的源图像,一个用来显示匹配的目标图像。
然后相对应的有三个Button控件,第一个用来打开源图像,第二个用来打开目标图像,第三个用来匹配,当点击第三个Button控件实现匹配,匹配的图像显示在新的窗体上,新的窗体很简单,就一个窗体,图像我们使用窗体的Paint 事件绘制在上面,第二个窗体如下:
其中button1实现的是打开源图像,代码如下:
private void buttonSrc_Click(object sender, EventArgs e)
{
//Create open dialog;
OpenFileDialog opnDlg = new OpenFileDialog();
opnDlg.Filter = "All Image files|*.bmp;*.gif;*.jpg;*.ico;*png";
//Seting the title of dialog;
opnDlg.Title = "Open Src image files";
opnDlg.ShowHelp = true;
if (opnDlg.ShowDialog() == DialogResult.OK)
{
curFileNameSrc = opnDlg.FileName;
try
{
curBitmapSrc = new Bitmap(curFileNameSrc);
pictureBoxSrc.Image = curBitmapSrc;
}
catch
{
MessageBox.Show("programe error");
}
}
}
Button2实现的是打开目标图像的功能,代码如下:
private void buttonDst_Click(object sender, EventArgs e)
{
//Create open dialog;
OpenFileDialog opnDlg = new OpenFileDialog();
opnDlg.Filter = "All Image files|*.bmp;*.gif;*.jpg;*.ico;*png";
//Seting the title of dialog;
opnDlg.Title = "Open Dst image files";
opnDlg.ShowHelp = true;
if (opnDlg.ShowDialog() == DialogResult.OK)
{
curFileNameDst = opnDlg.FileName;
try
{
curBitmapDst = new Bitmap(curFileNameDst);
pictureBoxDst.Image = curBitmapDst;
}
catch
{
MessageBox.Show("programe error");
}
}
}
Button3用来实现匹配,代码如下:
private void buttonMatch_Click(object sender, EventArgs e)
{
if(curBitmapDst!=null&&curBitmapSrc!=null)
{
long matchTime;
Image Byte>(curBitmapSrc); Image Image Image Matching Match = new Matching(); Image Bitmap Img = result.ToBitmap(); Form2 Form = new Form2(Img); Form.ShowDialog(); } else { MessageBox.Show("programe error"); } } 用于匹配的函数,我新建了一个名叫Matching的类,用来实现具体的匹配过程,在Button3中仅是对该类实例化,传入源图像和目标图像调用Match的函数就可以了。新建的Match类的代码如下: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Emgu.CV; using Emgu.Util; using Emgu.CV.Structure; using Emgu.CV.Util; using Emgu.CV.Features2D; using System.Diagnostics; using System.Drawing; namespace test10