摘要

“OpenCV是一个开源的计算机视觉库。OpenCV采用C/C++语言编写,可以运行在Linux/Windows/Mac等操作系统上。OpenCV还提供了Python、Ruby、MATLAB以及其他语言的接口。OpenCV的一个目标是构建一个简单易用的计算机视觉框架,以帮助开发人员更便捷地设计更复杂得计算机视觉相关应用程序。OpenCV包含的函数有500多个,覆盖了计算机视觉的许多应用。

Emgu

Emgu CV是将OpenCV使用.net编程语言(C#)封装成的.net库,使用Emgu CV就可以在.net平台上调用OpenCV的功能,同时,Emgu CV也是开源的。

Emgu CV官网:http://www.emgu.com

从官网上你可以下载最新版本,我采用的是3.2.0.2682版本的。

安装成功之后,打开目录

打开解决方案,你可以看到很多demo,可以根据自己需求研究下

新建winform程序,添加引用,Emgu安装目录下的dll

并将所需的文件从Emgu的bin目录下拷贝到你的程序debug下

测试核心代码

  public partial class MainFrm : Form
{
/// <summary>
/// 摄像头
/// </summary>
private VideoCapture _capture = null;
private Mat _frame;
private string _exePath = AppDomain.CurrentDomain.BaseDirectory;
private string _trainedFacePath = string.Empty;
/// <summary>
/// 3.5s 保存一次图片
/// </summary>
private const double Interval = 3.5;
long detectionTime;
List<Rectangle> faces = new List<Rectangle>();
List<Rectangle> eyes = new List<Rectangle>();
/// <summary>
/// 上次保存图片时间
/// </summary>
private DateTime _lastSaveDt = DateTime.Now;
/// <summary>
/// 窗口坐标
/// </summary>
private Point _frmPoint;
/// <summary>
/// 是否抓取到人脸
/// </summary>
private bool _isHavePersonFace = false;
public MainFrm()
{
InitializeComponent();
this.TopMost = true;
CheckForIllegalCrossThreadCalls = false;
_frmPoint = new Point();
} private void MainFrm_Load(object sender, EventArgs e)
{
//无边框
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
//不出现在任务栏
this.ShowInTaskbar = false;
//去掉滑轮放大或者缩小
this.VideoImageBox.Enabled = false;
this.MouseDown += MainFrm_MouseDown;
this.MouseMove += MainFrm_MouseMove; _trainedFacePath = _exePath + "trainedfaces";
this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width - ,
Screen.PrimaryScreen.WorkingArea.Height - this.Height);
if (!Directory.Exists(_trainedFacePath))
{
Directory.CreateDirectory(_trainedFacePath);
}
CvInvoke.UseOpenCL = false;
try
{
_capture = new VideoCapture();
_frame = new Mat();
_capture.ImageGrabbed += ProcessFrame;
_capture.Start(); }
catch (NullReferenceException excpt)
{
MessageBox.Show(excpt.Message);
}
} void MainFrm_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Point myPosittion = MousePosition;
myPosittion.Offset(-_frmPoint.X, -_frmPoint.Y);
Location = myPosittion;
}
} void MainFrm_MouseDown(object sender, MouseEventArgs e)
{
_frmPoint.X = e.X;
_frmPoint.Y = e.Y;
} private void ReleaseData()
{
if (_capture != null)
_capture.Dispose(); }
private void ProcessFrame(object sender, EventArgs e)
{ if (_capture != null && _capture.Ptr != IntPtr.Zero)
{
bool isOk = _capture.Retrieve(_frame, );
VideoImageBox.Image = _frame;
if (isOk && !_isHavePersonFace)
{ Run(_frame);
}
}
}
private void UploadFile(string filePath)
{ try
{
FileInfo file = new FileInfo(filePath);
FileLogHelper.WriteFileLog(file.Name); }
catch (Exception ex)
{
FileLogHelper.WriteFileLog(ex);
} } private void Run(Mat mat)
{
IImage image = mat;
DetectFace.Detect(
image, "haarcascade_frontalface_default.xml", "haarcascade_eye.xml",
faces, eyes,
out detectionTime);
string fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg";
string path = Path.Combine(_trainedFacePath, fileName); foreach (Rectangle face in faces)
{
try
{
_isHavePersonFace = true;
CvInvoke.Rectangle(image, face, new Bgr(Color.Red).MCvScalar, );
using (Bitmap bm = new Bitmap(face.Width, face.Height))
using (Graphics g = Graphics.FromImage(bm))
{
g.DrawImage(image.Bitmap, new Rectangle(, , face.Width, face.Height),
new Rectangle(face.X + , face.Y + , face.Width - , face.Height - ), GraphicsUnit.Pixel);
bm.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg);
}
break; }
catch (Exception ex)
{
FileLogHelper.WriteFileLog(ex);
}
} _isHavePersonFace = false;
} }

[Winform]基于Emgu.CV人脸识别的更多相关文章

  1. Emgu cv人脸检测识别

    Emgu cv人脸检测识别 1.开发平台:WIN10 X64    VS2012    Emgucv版本:3.1 2.先给大家分享一个官网给的示例源代码: https://ncu.dl.sourcef ...

  2. 基于 OpenCV 的人脸识别

    基于 OpenCV 的人脸识别 一点背景知识 OpenCV 是一个开源的计算机视觉和机器学习库.它包含成千上万优化过的算法,为各种计算机视觉应用提供了一个通用工具包.根据这个项目的关于页面,OpenC ...

  3. 【计算机视觉】基于OpenCV的人脸识别

    一点背景知识 OpenCV 是一个开源的计算机视觉和机器学习库.它包含成千上万优化过的算法,为各种计算机视觉应用提供了一个通用工具包.根据这个项目的关于页面,OpenCV 已被广泛运用在各种项目上,从 ...

  4. 基于MATLAB的人脸识别算法的研究

    基于MATLAB的人脸识别算法的研究 作者:lee神 现如今机器视觉越来越盛行,从智能交通系统的车辆识别,车牌识别到交通标牌的识别:从智能手机的人脸识别的性别识别:如今无人驾驶汽车更是应用了大量的机器 ...

  5. 基于 HTML5 的人脸识别技术

    基于 HTML5 的人脸识别技术 https://github.com/auduno/headtrackr/

  6. 基于node.js人脸识别之人脸对比

    基于node.js人脸识别之人脸对比 Node.js简介 Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境. Node.js 使用了一个事件驱动.非阻塞式 I/O ...

  7. java基于OpenCV的人脸识别

    基于Java简单的人脸和人眼识别程序 使用这个程序之前必须先安装配置OpenCV详细教程见:https://www.cnblogs.com/prodigal-son/p/12768948.html 注 ...

  8. 基于Emgu CV+百度人脸识别,实现视频动态 人脸抓取与识别

    背景 目前AI 处于风口浪尖,作为 公司的CTO,也作为自己的技术专研,开始了AI之旅,在朋友圈中也咨询 一些大牛对于AI 机器学习框架的看法,目前自己的研究方向主要开源的 AI 库,如:Emgu C ...

  9. 可学习的多人人脸识别程序(基于Emgu CV)

    源代码下载(需要安装Emgu CV,安装方法请百度) 很多朋友使用Emgu CV遇到CvInvoke()的报错,我找到一种解决方法. 把EmguCV目录下bin里面的所有dll复制到C:\WINDOW ...

随机推荐

  1. python中open函数的用法

    用法如下: name = open('errname.txt','w')name.readline()name.close() 1.看下第一行的代码 用来访问磁盘中存放的文件,可以进行读写等操作,例如 ...

  2. Mac安装MAT报错问题

    安装mat报错,提示在/.eclipse/1528649425_macosx_cocoa_x86_64/configuration/1539332382530.log路径下查看错误日志, 原因是/pr ...

  3. 洛谷P3375KMP字符串匹配

    传送门 #include <iostream> #include <cstdio> #include <cstring> #include <algorith ...

  4. java 多态缺陷

    一,会覆盖私有方法 package object; class Derive extends Polymorphism{ public void f1() { System.out.println(& ...

  5. Java @Override 注解

    @Override注解,不是关键字,但可以当关键字使用,可以选择添加这个注解,在你不留心重载而并非复写了该方法时,编译器就会产生一条错误:The method doh(Milhouse) of typ ...

  6. InnoDB逻辑存储结构

    从InnoDB存储引擎的逻辑存储结构看,所有数据都被逻辑地存放在一个空间中,称之为表空间(tablespace).表空间又由段(segment).区(extent).页(page)组成.页在一些文档中 ...

  7. KnockoutJs学习笔记(十)

    event binding主要用于为指定的事件添加相应的处理函数,可以作用于任意事件,包括keypress.mouseover.mouseout等(也包括之前提到的click,根据后面的描述,clic ...

  8. [转] impress.js学习

    引子 断断续续用了好几天,终于把 impress.js 源码看完,作为刚入门的前端菜鸟,这是我第一次看 js 源码,最初还是比较痛苦的.不过还好,impress.js源码的注释相当清楚,每个函数和事件 ...

  9. 【BZOJ】2120: 数颜色

    题解 练习一下带修改莫队 先按照左端点的块排序,再按照右端点的块排序,然后按照时间排序 每个修改操作存一下修改前这个位置的值就可以逆序操作了 代码 #include <bits/stdc++.h ...

  10. 系统管理员常用的Linux命令

    整理Linux的一些基本系统管理命令作为备忘 ========================================================================= 查看文 ...