Emgu CV 第一個執行個體

來源:互聯網
上載者:User

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

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Windows.Forms;  
  9. using Emgu.CV;//PS:調用的Emgu dll  
  10. using Emgu.CV.Structure;  
  11. using Emgu.Util;  
  12. using System.Threading;  
  13.   
  14. namespace Emgu1  
  15. {  
  16.     public partial class Form1 : Form  
  17.     {  
  18.         public Form1()  
  19.         {  
  20.             InitializeComponent();  
  21.         }  
  22.         private Capture capture;  
  23.         private bool captureinprocess;//判斷網路攝影機的狀態  
  24.   
  25.         private void button1_Click(object sender, EventArgs e)  
  26.         {  
  27.             if (capture != null)//網路攝影機不為空白  
  28.             {  
  29.                 if (captureinprocess)  
  30.                 {  
  31.                     Application.Idle -= new EventHandler(processfram);  
  32.                     button1.Text = "Stop!";  
  33.                 }  
  34.                 else  
  35.                 {  
  36.                     Application.Idle += new EventHandler(processfram);  
  37.                     button1.Text = "Start!";  
  38.                 }  
  39.                 captureinprocess = !captureinprocess;  
  40.             }  
  41.             else//網路攝影機為空白則通過Capture()方法調用  
  42.             {  
  43.                 try  
  44.                 {  
  45.                     capture = new Capture();  
  46.                 }  
  47.                 catch (NullReferenceException excpt)  
  48.                 {  
  49.                     MessageBox.Show(excpt.Message);  
  50.                 }  
  51.             }  
  52.         }  
  53.   
  54.         private void processfram(object sender, EventArgs arg)  
  55.         {  
  56.             Image<Bgr, Byte> frame = capture.QueryFrame();  
  57.             imageBox1.Image = frame;  
  58.         }  
  59.     }  
  60. }  

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.