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控制項(第三張圖中匯入的自訂外掛程式),然後編寫代碼即可
代碼
[c-sharp:nogutter] view plaincopy
- 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;
- }
- }
- }