1. 從http://sourceforge.net/projects/emgucv/?source=directory下載最新的Emgu
CV2.4.2;
2. 將libemgucv-windows-x86-gpu-2.4.2.1777拷貝到D:\soft\Emgu2.4.2檔案夾下,運行此.exe檔案,將其安裝到D:\soft\Emgu2.4.2\emgucv-windows-x86-gpu2.4.2.1777檔案夾下,安裝完後會自動重啟;
3. 將D:\soft\Emgu2.4.2\emgucv-windows-x86-gpu2.4.2.1777\bin;D:\soft\Emgu2.4.2\emgucv-windows-x86-gpu2.4.2.1777\bin\x86(此x86檔案夾下包含有對應的OpenCV2.4.2的動態庫,將此目錄加入到環境變數後Emgu不需要額外的安裝相對應的OpenCV);添加到系統內容變數Path中,重啟;
4. 開啟vs2008,建立一個基於Windows表單的應用程式;
5. 匯入UI外掛程式:Tool-->Choose Toolbox Items-->.NET
Framework Components-->點擊Browse,選中D:\soft\Emgu2.4.2\emgucv-windows-x86-gpu2.4.2.1777\bin下的Emgu.CV.UI.dll開啟,會在列表中新增HistogramBox、ImageBox、MatrixBox、PanAndZoomPictureBox四項;
6. 添加引用:選中工程下的References-->Add Reference-->Browse選中D:\soft\Emgu2.4.2\emgucv-windows-x86-gpu2.4.2.1777\bin下的Emgu.CV.dll、Emgu.CV.ML.dll、
Emgu.CV.UI.dll、 Emgu.Util.dll、ZedGraph.dll 5個動態庫,點擊OK;
7. 點擊Solution Platforms-->Configuration Manager:Active solution
platform將原來的Any CPU改為x86,否則會提示“Emgu.CV.CvInvoke的類型初始值設定項引發異常”的錯誤。
網上的一個程式碼範例,編譯、運行成功:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingEmgu.CV;//Emgu
usingEmgu.CV.Structure;
usingEmgu.Util;
usingSystem.Threading;
namespaceTestEmgu
{
public partial
class Form1 :
Form
{
public
Form1()
{
InitializeComponent();
}
privateCapturecapture;
privateboolcaptureinprocess;//判斷網路攝影機的狀態
privatevoidbutton1_Click(objectsender,
EventArgse)
{
if(capture !=null)
{
if(captureinprocess)
{
Application.Idle -=new
EventHandler(processframe);
button1.Text ="stop!";
}
else
{
Application.Idle +=new
EventHandler(processframe);
button1.Text ="start!";
}
captureinprocess= !captureinprocess;
}
else//網路攝影機為空白,則通過Capture()方法調用
{
try
{
capture=
newCapture();
}
catch(NullReferenceExceptionexcpt)
{
MessageBox.Show(excpt.Message);
}
}
}
privatevoidprocessframe(objectsender,
EventArgsarg)
{
Image<Bgr,Byte>
frame =capture.QueryFrame();
imageBox1.Image =frame;
}
}
}
參考文獻:
1.
http://www.emgu.com/wiki/
2.
http://blog.163.com/woshitony111@126/blog/static/71379539201282511180304/
3.
http://blog.csdn.net/gaaranaruto/article/details/6328358