【问题标题】:Face Detection on a video file视频文件上的人脸检测
【发布时间】:2014-04-12 09:55:49
【问题描述】:

我想使用“haar cascade”从输入视频文件中检测人脸。我已使用此代码将视频转换为帧。请告诉我如何从这些框架中检测面部并将其标记在矩形边框中。

 private void button1_Click(object sender, EventArgs e)
    {
        OpenFileDialog openFileDialog1 = new OpenFileDialog();
        if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {

                memde = new MediaDetClass();
                System.IO.Directory.CreateDirectory("temp");
                memde.Filename = openFileDialog1.FileName;
                int len = (int)memde.StreamLength;
                counter = 0;
                Image img;
                memde.Filename = openFileDialog1.FileName;
                memde.CurrentStream = 0;
                float percent = 0.002f;
                Image<Gray, byte> gray;
                for (float i = 0.0f; i < len; i = i + (float)(percent * len))
                {
                    counter++;
                    string fbitname = storagepath + counter.ToString();
                    memde.WriteBitmapBits(i, 850, 480, fbitname + ".bmp");

                    }
                }
        }
    }

【问题讨论】:

    标签: c# asp.net emgucv face-detection


    【解决方案1】:

    我建议为您的视频文件使用捕获类,并将您的代码基于此示例:

    http://www.emgu.com/wiki/index.php?title=Video_Files

    然后将 ProcessFrame() 方法的相关部分替换为:

    if (CurrentState == VideoMethod.Viewing)
    {
        frame = _Capture.RetrieveBgrFrame();
        if (frame != null)
        {
            using (Image<Gray, Byte> gray = frame.Convert<Gray, Byte>()) //Convert it to Grayscale
            {
                //normalizes brightness and increases contrast of the image
                gray._EqualizeHist();
    
                //Detect the faces  from the gray scale image and store the locations as rectangle
                //The first dimensional is the channel
                //The second dimension is the index of the rectangle in the specific channel
                Rectangle[] facesDetected = face.DetectMultiScale(
                                   gray,
                                   1.1,
                                   10,
                                   new Size(20, 20),
                                   Size.Empty);
    
                foreach (Rectangle f in facesDetected)
                {
                    //Draw the rectangle on the frame
                    frame.Draw(f, new Bgr(Color.Red), 2);
                }
            }
    
            //Show image
            DisplayImage(frame.ToBitmap());
        }
    }
    

    干杯,

    克里斯

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-13
      • 1970-01-01
      • 2019-04-26
      • 1970-01-01
      • 1970-01-01
      • 2016-05-24
      • 2016-02-25
      • 2016-08-09
      相关资源
      最近更新 更多