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

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目录下。

转载于:https://www.cnblogs.com/pjCoder/p/5252612.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值