基于Emgu.Cv内置摄像头图片人脸/人手识别

建立C#的WinForm程序,添加一个pictureBox组件,一个timer组件,timer响应函数为timer1_Tick()。工程代码如下:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.IO.Ports;
using System.IO;
using System.Runtime.InteropServices;
using System.Drawing.Imaging;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Emgu.CV;
using Emgu.Util;
using Emgu.CV.ML;
using Emgu.CV.UI;
using Emgu.CV.GPU;
using Emgu.CV.OCR;
using Emgu.CV.Structure;
using Emgu.CV.ML.Structure;

namespace ProjectName
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            timer1.Enabled = true;
            timer1.Interval = 1000;//时间间隔设置为1秒
        }

        Emgu.CV.Capture capture = new Emgu.CV.Capture();

        private void timer1_Tick(object sender, EventArgs e)
        {        
            Image<Bgr, Byte> frame = capture.QueryFrame();//获取摄像头数据
            frame=frame.Flip(Emgu.CV.CvEnum.FLIP.HORIZONTAL);
            Image<Gray, Byte> gray = frame.Convert<Gray, Byte>(); //Convert it to Grayscale
            //gray._EqualizeHist();//均衡化
            CascadeClassifier face = new CascadeClassifier("数据库xml文件路径");//加载xml文件,识别人手或人脸
            Rectangle[] facesDetected = face.DetectMultiScale(gray, 1.1, 10, new Size(20, 20), Size.Empty);//寻找图片中人脸并加检测框
            foreach (Rectangle f in facesDetected)
            {
                frame.Draw(f, new Bgr(Color.Red), 3);//绘制检测框
            }
            pictureBox1.Image = frame.ToBitmap();
        }       
    }

}


这实现了一个简单的从摄像头获取图片数据并将其中关心的部分框出的功能,利用了OpenCv提供的学习机方法。对于摄像头更多的处理方法可参考:

http://blog.csdn.net/hbqhdlc/article/details/6848063

文中利用了WindowsAPI的函数功能,实现摄像。对于人手识别,不像人脸识别这么普遍,可参考:

http://www.360doc.com/content/11/1220/16/5087210_173660914.shtml

相应xml文件链接也在文中提供。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值