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控件(第三張圖中導入的自定義插件),然后編寫代碼即可
代碼
- 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中提供了眾多的借口方便調用,非常適合需要圖像處理而不精通算法的人,這里面非常值得研究,這是我發的第一篇心得,基本算是轉帖,大家見諒!歡迎一起討論