c#_使用emgu3.0操作本地摄像头

来源:互联网 发布:js大于等于怎么写 编辑:程序博客网 时间:2024/06/11 12:40

c#_使用emgucv 3.0 操作本地摄像头

首先我们要下载emgu3.0,安装包,[下载地址]http://www.emgu.com/wiki/index.php/Download_And_Installation

安装完成以后,根据你要所开发的应用的平台,在安装目录的bin目录下选择x86或者x64 复制里面的四个dll文件 : cvextern.dll + msvcp120.dll + msvcr120.dll + opencv_ffmpeg310_64.dll / opencv_ffmpeg310.dll 到应用的开发目录的bin/debug目录下,此外将安装目录bin目录下的所有dll文件添加引用,包括 : cvextern.dll + Emgu.CV.Contrib.dll + Emgu.CV.Cuda.dll + Emgu.CV.dll + Emgu.CV.ML.dll + Emgu.CV.OCR.dll + Emgu.CV.Shape.dll + Emgu.CV.Stitching.dll + Emgu.CV.Superres.dll + Emgu.CV.UI.dll + Emgu.CV.UI.GL.dll + Emgu.CV.VideoStab.dll + Emgu.Util.dll + msvcp120.dll + msvc120.dll+ opencv_ffmpeg300_64.dll;最好是把上面的所有文件都复制到debug目录下。

在做好上面的准备工作之后,我们还要进行一个操作。添加imagebox控件,这个控件是在Emgu.CV.UI.dll文件中的,.net平台并没有提供。添加控件的步骤如下:

  1. 打开工具箱面板,右键单击工具箱空白区域,选择添加选项卡并命名为emgu.ui。

这里写图片描述

  1. 找到Emgu.CV.UI.dll 文件 将其拖入我们刚新建的选项卡中,这个时候我们的选项卡里就会多出几个控件,

这里写图片描述

  1. 进入设计视图,将imagebox 添加到窗体中

官方添加控件教程链接(英文):<链接> http://www.emgu.com/wiki/index.php/Add_ImageBox_Control

添加完控件,就可以开始写代码了!

using Emgu.CV;using System;using System.Windows.Forms;namespace RecognizeFace{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private Capture cap;        private bool isProcess = false;        void button1_Click(object sender, EventArgs e)        {            if (cap != null)            {                if (isProcess)                {                    Application.Idle -= new EventHandler(ProcessFram);                    button1.Text = "stop!";                }                else                {                    Application.Idle += new EventHandler(ProcessFram);                    button1.Text = "start!";                }                isProcess = !isProcess;            }            else            {                try                {                    cap = new Emgu.CV.Capture();                }                catch (NullReferenceException expt)                {                    MessageBox.Show(expt.Message);                }            }        }        private void ProcessFram(object sender, EventArgs arg)        {            imageBox1.Image = cap.QueryFrame();        }    }}

代码很简单,主要是配置问题!代码就不细说了。

异常 : 如果在运行的时候出现了异常:“Emgu.CV.CvInvoke”的类型初始值设定项引发异常。” 就我现在知道的,可能是因为没有将cvextern.dll + msvcp120.dll + msvcr120.dll + opencv_ffmpeg310_64.dll / opencv_ffmpeg310.dll 这四个dll文件添加到debug目录下。

0 0
原创粉丝点击