zoukankan      html  css  js  c++  java
  • AI_ 视频监控-人体移动捕捉监测

    总目录地址:AI 系列 总目录 

    需要最新源码,或技术提问,请加QQ群:538327407

    我的各种github 开源项目和代码:https://github.com/linbin524

    需求

    为了实现特定场景中人员监控、人脸识别的需求,针对相关技术做研究。近场的动态人脸识别已经实现;现在需要针对人距离的移动人物进行捕捉截取,确定当前场所行走的人员做收集。

    实现效果:

    技术方案

    1、采用Emgu CV 开源框架,对人体进行动态捕捉

    2、介绍摄像头采集 识别移动人体模式

    技术实现

    动态截取人物

    代码:

        void ProcessFrame(object sender, EventArgs e)
            {
                Mat frame = _cameraCapture.QueryFrame();
                Mat smoothedFrame = new Mat();
                CvInvoke.GaussianBlur(frame, smoothedFrame, new Size(3, 3), 1); //filter out noises
                                                                                //frame._SmoothGaussian(3); 
               
                #region use the BG/FG detector to find the forground mask
    
                Mat forgroundMask = new Mat();
                _fgDetector.Apply(smoothedFrame, forgroundMask);
                #endregion
    
                CvBlobs blobs = new CvBlobs();
                _blobDetector.Detect(forgroundMask.ToImage<Gray, byte>(), blobs);
                blobs.FilterByArea(100, int.MaxValue);
    
                float scale = (frame.Width + frame.Width) / 2.0f;
                _tracker.Update(blobs, 0.01 * scale, 5, 5);
    
                long detectionTime;
    
                List<Rectangle> faces = new List<Rectangle>();
                List<Rectangle> eyes = new List<Rectangle>();
    
                IImage image = (IImage)frame;//这一步是重点
                faceImage = frame.Bitmap;
               
    
                #region 人物识别
                long processingTime;
                Rectangle[] results;
    
                if (CudaInvoke.HasCuda)
                {
                    using (GpuMat gpuMat = new GpuMat(frame))
                        results = FindPedestrian.Find(gpuMat, out processingTime);
                }
                else
                {
                    using (UMat uImage = frame.GetUMat(AccessType.ReadWrite))
                        results = FindPedestrian.Find(uImage, out processingTime);
                }
    
                foreach (Rectangle rect in results)
                {
                    CvInvoke.Rectangle(frame, rect, new Bgr(Color.Red).MCvScalar);
                }
               
                #endregion
    
                imageBox1.Image = frame;
                imageBox2.Image = forgroundMask;
            }

     人物识别动态捕捉核心代码:

    using System;
    using System.Collections.Generic;
    using Emgu.CV;
    using Emgu.CV.CvEnum;
    using Emgu.CV.Structure;
    using System.Drawing;
    using System.Diagnostics;
    using Emgu.CV.Util;
    #if !(__IOS__ || NETFX_CORE)
    using Emgu.CV.Cuda;
    #endif
    
    namespace PedestrianDetection
    {
       public static class FindPedestrian
       {
          /// <summary>
          /// Find the pedestrian in the image
          /// </summary>
          /// <param name="image">The image</param>
          /// <param name="processingTime">The processing time in milliseconds</param>
          /// <returns>The region where pedestrians are detected</returns>
          public static Rectangle[] Find(IInputArray image, out long processingTime)
          {
             Stopwatch watch;
             Rectangle[] regions;
    
             using (InputArray iaImage = image.GetInputArray())
             {
    #if !(__IOS__ || NETFX_CORE)
                //if the input array is a GpuMat
                //check if there is a compatible Cuda device to run pedestrian detection
                if (iaImage.Kind == InputArray.Type.CudaGpuMat)
                {
                   //this is the Cuda version
                   using (CudaHOG des = new CudaHOG(new Size(64, 128), new Size(16, 16), new Size(8, 8), new Size(8, 8)))
                   {
                      des.SetSVMDetector(des.GetDefaultPeopleDetector());
    
                      watch = Stopwatch.StartNew();
                      using (GpuMat cudaBgra = new GpuMat())
                      using (VectorOfRect vr = new VectorOfRect())
                      {
                         CudaInvoke.CvtColor(image, cudaBgra, ColorConversion.Bgr2Bgra);
                         des.DetectMultiScale(cudaBgra, vr);
                         regions = vr.ToArray();
                      }
                   }
                }
                else
    #endif
                {
                   //this is the CPU/OpenCL version
                   using (HOGDescriptor des = new HOGDescriptor())
                   {
                      des.SetSVMDetector(HOGDescriptor.GetDefaultPeopleDetector());
                      watch = Stopwatch.StartNew();
    
                      MCvObjectDetection[] results = des.DetectMultiScale(image);
                      regions = new Rectangle[results.Length];
                      for (int i = 0; i < results.Length; i++)
                         regions[i] = results[i].Rect;
                      watch.Stop();
                   }
                }
    
                processingTime = watch.ElapsedMilliseconds;
    
                return regions;
             }
          }
       }
    }

    读后感觉不错,有收获可以微信请作者喝杯咖啡,读后有疑问请加微信,拉群研讨,注明来意

  • 相关阅读:
    HYSBZ 3813 奇数国
    HYSBZ 4419 发微博
    HYSBZ 1079 着色方案
    HYSBZ 3506 排序机械臂
    HYSBZ 3224 Tyvj 1728 普通平衡树
    Unity 3D,地形属性
    nginx 的naginx 种包含include关键字
    Redis 出现NOAUTH Authentication required解决方案
    mysql 8.0出现 Public Key Retrieval is not allowed
    修改jar包里的源码时候需要注意的问题
  • 原文地址:https://www.cnblogs.com/linbin524/p/8037625.html
Copyright © 2011-2022 走看看