C# 视频文件中的人脸检测
我想使用“haar cascade”从输入视频文件中检测人脸。我已使用此代码将视频转换为帧。请告诉我如何从这些帧中检测人脸,并在矩形边框中进行标记C# 视频文件中的人脸检测,c#,asp.net,emgucv,face-detection,C#,Asp.net,Emgucv,Face Detection,我想使用“haar cascade”从输入视频文件中检测人脸。我已使用此代码将视频转换为帧。请告诉我如何从这些帧中检测人脸,并在矩形边框中进行标记 private void button1_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); if (openFileDialog1.ShowDialog() == System.
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");
}
}
}
}
private void按钮1\u单击(对象发送者,事件参数e)
{
OpenFileDialog openFileDialog1=新建OpenFileDialog();
if(openFileDialog1.ShowDialog()==System.Windows.Forms.DialogResult.OK)
{
memde=新的MediaDetClass();
System.IO.Directory.CreateDirectory(“temp”);
memde.Filename=openFileDialog1.Filename;
int len=(int)memde.StreamLength;
计数器=0;
图像img;
memde.Filename=openFileDialog1.Filename;
memde.CurrentStream=0;
浮动百分比=0.002f;
图像灰度;
对于(浮动i=0.0f;i
我建议对视频文件使用capture类,并根据以下示例编写代码:
然后将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());
}
}
if(CurrentState==VideoMethod.Viewing)
{
frame=_Capture.RetrieveBgrFrame();
如果(帧!=null)
{
使用(Image gray=frame.Convert())//将其转换为灰度
{
//标准化亮度并增加图像的对比度
灰色;
//从灰度图像中检测人脸,并将位置存储为矩形
//第一维度是通道
//第二个维度是特定通道中矩形的索引
矩形[]面检测=面检测多尺度(
灰色
1.1,
10,
新尺寸(20,20),
尺寸(空);
foreach(检测面中的矩形f)
{
//在框架上绘制矩形
画框(f,新Bgr(红色),2);
}
}
//显示图像
显示图像(frame.ToBitmap());
}
}
干杯
克里斯