您的位置:首页 > 编程语言 > C#

【C# -- OpenCV】Emgu CV 第一个实例

2013-12-15 20:55 525 查看
原文 【C# -- OpenCV】Emgu CV 第一个实例

Emgu CV下载地址

http://sourceforge.net/projects/emgucv/files/

找最新的下就行了,傻瓜式安装,选择目录后自动完成安装,然后提示安装VS2008和VS2010的插件,我使用的是VS2010,然后完成操作。

Emgu CV是什么?

Emgu CV是.NET平台下对OpenCV图像处理库的封装,也就是.NET版。可以运行在C#、VB、VC++等。

安装完成后需要设置环境变量,比如我安装在E:/Emgu/emgucv-windows-x86 2.2.1.1150,然后再系统环境变量添加E:/Emgu/emgucv-windows-x86 2.2.1.1150/bin即可

编写第一个小程序





在VS2010中新建一个Windows应用程序



首先需要导入UI插件



在浏览中定位到Emgu的安装目录bin下,选择Emgu.CV.UI.dll



在引用中添加dll调用,分别是Emgu.CV.dll和Emgu.CV.ML.dll和Emgu.CV.UI.dll和Emgu.Util.dll以及ZedGraph.dll



添加完毕后放置一个Button控件和一个imagebox控件(第三张图中导入的自定义插件),然后编写代码即可

代码

[csharp] view plaincopyprint?

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using Emgu.CV;//PS:调用的Emgu dll

using Emgu.CV.Structure;

using Emgu.Util;

using System.Threading;

namespace Emgu1

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private Capture capture;

private bool captureinprocess;//判断摄像头的状态

private void button1_Click(object sender, EventArgs e)

{

if (capture != null)//摄像头不为空

{

if (captureinprocess)

{

Application.Idle -= new EventHandler(processfram);

button1.Text = "Stop!";

}

else

{

Application.Idle += new EventHandler(processfram);

button1.Text = "Start!";

}

captureinprocess = !captureinprocess;

}

else//摄像头为空则通过Capture()方法调用

{

try

{

capture = new Capture();

}

catch (NullReferenceException excpt)

{

MessageBox.Show(excpt.Message);

}

}

}

private void processfram(object sender, EventArgs arg)

{

Image<Bgr, Byte> frame = capture.QueryFrame();

imageBox1.Image = frame;

}

}

}

总结

我刚开始研究Emgu CV,有很多很多不懂的地方,以上步骤我基本是按照网上教程一步一步做的(http://www.dotblogs.com.tw/chou/archive/2009/06/13/8812.aspx

没有任何问题,CV中提供了众多的借口方便调用,非常适合需要图像处理而不精通算法的人,这里面非常值得研究。

全文参考:http://blog.csdn.net/gaaranaruto/article/details/6328358#
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: