-歡迎轉載,請務必注明出處。
一、目的:
測試Emgu安裝是否正確,攝像頭采集測試。
二、背景知識:
1.什么是EmguCV?
其實就是OpenCV的C#版,對於我這種熟悉.net人來說比較容易上手。
2.如何安裝EmguCV?
詳見http://www.emgu.com/wiki/index.php/Main_Page,或百度一下,很容易安裝。
三、安裝環境:
VisualStudio2008 + Emgu V2.0.5
四、測試步驟:
1.程序界面設計
2.程序代碼
/* * Wrote by james at 2012-10-11 * jamesking.chao@gmail.com */ 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; using Emgu.CV.Structure; using Emgu.Util; using System.Threading; namespace Emgu學習_攝像頭采集顯示 { public partial class Form1 : Form { private Capture capt; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { this.btnBegin.Enabled = true; this.btnEnd.Enabled = false; } private void GetFrame(object sender, EventArgs e) { Image<Bgr, Byte> frame = capt.QueryFrame(); imageBox1.Image = frame; } private void button1_Click(object sender, EventArgs e) { try { if (capt == null) capt = new Capture(); } catch (NullReferenceException excpt) { MessageBox.Show(excpt.Message); } if (capt != null) { btnBegin.Enabled = false; btnEnd.Enabled = true; Application.Idle += new EventHandler(GetFrame); } } private void btnEnd_Click(object sender, EventArgs e) { if (capt != null) { btnBegin.Enabled = true; btnEnd.Enabled = false; Application.Idle -= new EventHandler(GetFrame); } } } }
3.運行效果