• 大小: 42.07MB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2023-06-15
  • 语言: C#
  • 标签: EmguCV  人脸检测  

资源简介

c#下使用EmguCV操作摄像头和最简单的人脸检测 http://blog.csdn.net/a582127421/article/details/77745580

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Emgu.CV;
using System.Runtime.InteropServices;
using System.Windows.Media.Imaging;
using System.Drawing;
using System.Windows;
using System.Windows.Media;

namespace Camera_driver
{
    public class Camera
    {
        private static CascadeClassifier faceClassifier = new CascadeClassifier(AppDomain.CurrentDomain.baseDirectory + “haarcascade_frontalface_default.xml“);

        Capture capture;    //摄像头对象


        public void openCamera()
        {

            if(capture == null)
            {
                capture = new Capture(0);
            }
        }

        public ImageSource getImage()
        {
            try
            {
                Mat mat = capture.Queryframe();
                return ImageConverterL.ToBitmapSource(mat.Bitmap);
            }
            catch(Exception)
            {
                return null;
            }
        }

        public void closeCamera()
        {
            capture.Dispose();
            capture = null;
        }

        public CameraInfo identifyFace()
        {
            CameraInfo info = new CameraInfo();
            using(Mat mat = capture.Queryframe())
            {
                if(mat == null)
                {
                    return null;
                }
                List faces = getFaceRectangle(mat);
                if (faces.Count <= 0)
                {
                    info.isHasFace = false;
                }
                else
                {
                    // 绘制人脸
                    using (Graphics g = Graphics.FromImage(mat.Bitmap))
                    {
                        foreach (Rectangle face in faces)
                        {
                            g.DrawRectangle(new System.Drawing.Pen(System.Drawing.Color.Red 2) face);//给识别出的人脸画矩形框
                        }
                    }
                    info.isHasFace = true;             
                }
                info.mat = mat;
                info.imagesSource = ImageConverterL.ToBitmapSource(mat.Bitmap);

                return info;
            } 
        }

        /// 
        /// 获取人脸矩形
        /// 

        /// 
        /// 
        private List getFaceRectangle(Mat mat)
        {
            List faces = new List();
            try
            {
                using (UMat ugray = new UMat())
                {
                    CvInvoke.CvtColor(mat ugray Emgu.CV.CvEnum.ColorConversion.Bgr2Gray);//灰度化图片
                    CvInvoke.EqualizeHist(ugray ugray);//均衡化灰度图片

                    Rectangle[] facesDetected = faceClassifier.DetectMultiScale(ugray 1.1 10 new System.Drawing.Size(20 20));
                    faces.AddRange(facesDet

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.    102400  2017-08-31 15:04  Camera_tool\.vs\Camera_tool\v14\.suo

     文件       4427  2017-08-31 14:31  Camera_tool\Camera_driver\Camera.cs

     文件        313  2017-08-31 11:15  Camera_tool\Camera_driver\CameraInfo.cs

     文件       6512  2017-08-31 11:17  Camera_tool\Camera_driver\Camera_driver.csproj

     文件    1254733  2017-08-31 10:55  Camera_tool\Camera_driver\haarcascade_frontalface_default.xml

     文件       1813  2017-08-30 19:22  Camera_tool\Camera_driver\OpenTK.dll.config

     文件        359  2017-08-30 19:22  Camera_tool\Camera_driver\packages.config

     文件       1334  2017-08-30 19:05  Camera_tool\Camera_driver\Properties\AssemblyInfo.cs

     文件        184  2017-08-30 19:05  Camera_tool\Camera_tool\App.config

     文件        376  2017-08-30 19:05  Camera_tool\Camera_tool\App.xaml

     文件        338  2017-08-30 19:05  Camera_tool\Camera_tool\App.xaml.cs

     文件       8656  2017-08-31 10:30  Camera_tool\Camera_tool\Camera_tool.csproj

     文件    1254733  2017-08-31 10:56  Camera_tool\Camera_tool\haarcascade_frontalface_default.xml

     文件       1060  2017-08-30 19:40  Camera_tool\Camera_tool\MainWindow.xaml

     文件       3158  2017-08-31 14:30  Camera_tool\Camera_tool\MainWindow.xaml.cs

     文件       1813  2017-08-30 19:57  Camera_tool\Camera_tool\OpenTK.dll.config

     文件        358  2017-08-30 19:58  Camera_tool\Camera_tool\packages.config

     文件       2257  2017-08-30 19:05  Camera_tool\Camera_tool\Properties\AssemblyInfo.cs

     文件       2862  2017-08-30 19:05  Camera_tool\Camera_tool\Properties\Resources.Designer.cs

     文件       5612  2017-08-30 19:05  Camera_tool\Camera_tool\Properties\Resources.resx

     文件       1111  2017-08-30 19:05  Camera_tool\Camera_tool\Properties\Settings.Designer.cs

     文件        201  2017-08-30 19:05  Camera_tool\Camera_tool\Properties\Settings.settings

     文件       2147  2017-08-30 19:40  Camera_tool\Camera_tool.sln

     文件        222  2016-06-14 16:54  Camera_tool\packages\EmguCV.3.1.0.1\build\EmguCV.props

     文件        690  2016-06-14 16:54  Camera_tool\packages\EmguCV.3.1.0.1\build\EmguCV.targets

     文件   14909440  2016-06-14 16:54  Camera_tool\packages\EmguCV.3.1.0.1\build\native\x64\cvextern.dll

     文件   12954112  2016-06-14 16:54  Camera_tool\packages\EmguCV.3.1.0.1\build\native\x64\opencv_ffmpeg310_64.dll

     文件   11576832  2016-06-14 16:54  Camera_tool\packages\EmguCV.3.1.0.1\build\native\x86\cvextern.dll

     文件   12450304  2016-06-14 16:54  Camera_tool\packages\EmguCV.3.1.0.1\build\native\x86\opencv_ffmpeg310.dll

     文件   22116761  2017-08-30 19:22  Camera_tool\packages\EmguCV.3.1.0.1\EmguCV.3.1.0.1.nupkg

............此处省略72个文件信息

评论

共有 条评论