c# - 视频文件上的人脸检测

标签 c# asp.net emgucv face-detection

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

 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");

                    }
                }
        }
    }

最佳答案

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

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());
    }
}

干杯,

克里斯

关于c# - 视频文件上的人脸检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22280812/

相关文章:

c# - 无法访问 C# emgucv 中的 Image<Bgr, byte>.Data 属性

c# - 为什么在 C# 中使用动态类型?

c# - .aspx 代码错误 "Element ' xxxx' 不受支持。”

c# - 类型初始化异常

c# - 使用表单例份验证获取当前用户 ID(不是名称)?

javascript - 如何在 asp :Radiobutton? 中调用 Javascript 函数

c# - EmguCV MatchTemplate 获取所有匹配项

C# 字符串自定义格式添加尾随零

c# - 如何从 Windows Phone 8.1 获取当前国家/地区位置以及可能的国家/地区代码

c# - 搜索元组的 LINQ 查询