Emgu CV 是英特尔 OpenCV 图像处理库的跨平台. Net 包装器. 小编 c++ 学习群 825414254 获取 c++ 一整套系统性的学习资料还有数十套 PDF
允许从. NET 兼容语言 (如 C#,VB,VC ++,IronPython 等) 调用 OpenCV 函数. 包装器可以在 Mono 中编译并在 Linux / Mac OS X 上运行. 与 OpenCVDotNet 等其他包装器不同, SharperCV 使用不安全的代码, Emgu CV 完全用 C#编写. 好处是它可以在 Mono 中编译, 因此能够在 Mono 支持的任何平台上运行, 包括 Linux,Solaris 和 Mac OS X. 由于标题必须是大量的, 因此需要花费很多精力来实现纯 C#实现. 移植, 与托管 C ++ 实现相比, 可以简单地包含头文件. 但是如果你看到 Emora CV 在 Fedora 10 上运行, 这是值得的! 此外, 它始终让您感到舒适, 因为您的代码是跨平台的.
人脸识别
1 - 创建 Windows 窗体应用程序
2 - 添加 PictureBox 和计时器(并启用它)
3 - 在 x86 系统上运行
4 - 确保在文件夹中有 OpenCV 相关 dll(包含在 Emgu CV 下载中)你执行代码.
5 - 调整路径以找到 Haarcascade xml(代码的最后一行)
- using System;
- using System.Windows.Forms;
- using System.Drawing;
- using Emgu.CV;
- using Emgu.Util;
- using Emgu.CV.Structure;
- using Emgu.CV.CvEnum;
- namespace opencvtut
- {
- public partial class Form1 : Form
- {
- private Capture cap;
- private HaarCascade haar;
- public Form1()
- {
- InitializeComponent();
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- using (Image<Bgr, byte> nextFrame = cap.QueryFrame())
- {
- if (nextFrame != null)
- {
- // there's only one channel (greyscale), hence the zero index
- //var faces = nextFrame.DetectHaarCascade(haar)[0];
- Image<Gray, byte> grayframe = nextFrame.Convert<Gray, byte>();
- var faces =
- grayframe.DetectHaarCascade(
- haar, 1.4, 4,
- HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
- new Size(nextFrame.Width/8, nextFrame.Height/8)
- )[0];
- foreach (var face in faces)
- {
- nextFrame.Draw(face.rect, new Bgr(0,double.MaxValue,0), 3);
- }
- pictureBox1.Image = nextFrame.ToBitmap();
- }
- }
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- // passing 0 gets zeroth webcam
- cap = new Capture(0);
- // adjust path to find your xml
- haar = new HaarCascade(
- "..\\..\\..\\..\\lib\\haarcascade_frontalface_alt2.xml");
- }
- }
- }
来源: http://www.jianshu.com/p/05f415aa2861