C#下的 Emgu CV


Emgu CV下载地址

http://sourceforge.net/projects/emgucv/files/

找最新的下就行了,傻瓜式安装,选择目录后自动完成安装,然后提示安装VS2008VS2010的插件,我使用的是VS2010,然后完成操作。

Emgu CV是什么?

Emgu CV.NET平台下对OpenCV图像处理库的封装,也就是.NET版。可以运行在C#VBVC++等。

安装完成后需要设置环境变量,比如我安装在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.dllEmgu.CV.ML.dllEmgu.CV.UI.dllEmgu.Util.dll以及ZedGraph.dll

添加完毕后放置一个Button控件和一个imagebox控件(第三张图中导入的自定义插件),然后编写代码即可

代码

[c-sharp] view plain copy
  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. namespace Emgu1
  14. {
  15. public partial class Form1 : Form
  16. {
  17. public Form1()
  18. {
  19. InitializeComponent();
  20. }
  21. private Capture capture;
  22. private bool captureinprocess;//判断摄像头的状态
  23. private void button1_Click(object sender, EventArgs e)
  24. {
  25. if (capture != null)//摄像头不为空
  26. {
  27. if (captureinprocess)
  28. {
  29. Application.Idle -= new EventHandler(processfram);
  30. button1.Text = "Stop!";
  31. }
  32. else
  33. {
  34. Application.Idle += new EventHandler(processfram);
  35. button1.Text = "Start!";
  36. }
  37. captureinprocess = !captureinprocess;
  38. }
  39. else//摄像头为空则通过Capture()方法调用
  40. {
  41. try
  42. {
  43. capture = new Capture();
  44. }
  45. catch (NullReferenceException excpt)
  46. {
  47. MessageBox.Show(excpt.Message);
  48. }
  49. }
  50. }
  51. private void processfram(object sender, EventArgs arg)
  52. {
  53. Image<Bgr, Byte> frame = capture.QueryFrame();
  54. imageBox1.Image = frame;
  55. }
  56. }
  57. }

总结

我刚开始研究Emgu CV,有很多很多不懂的地方,以上步骤我基本是按照网上教程一步一步做的(http://www.dotblogs.com.tw/chou/archive/2009/06/13/8812.aspx),没有任何问题,CV中提供了众多的借口方便调用,非常适合需要图像处理而不精通算法的人,这里面非常值得研究,这是我发的第一篇心得,基本算是转帖,大家见谅!欢迎一起讨论


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM