所有
我刚刚在最新版本的Emgu CV中尝试过脸部检测示例,而且我的程序运行良好,但我无法从任何图像或网络摄像头实时捕获中获得任何面孔。
我的操作系统是Windows 8 Enterprise x64。我的IDE是VS2012。
顺便说一句,我也尝试过HaarCascade和CascadeClassifier。他们都不能得到结果。返回的变量的值将始终为{Emgu.CV.Structure.MCvAvgComp [0]}cap = new Capture(0);
// adjust path to find your xml
//ccf = new CascadeClassifier("D:\\haarcascade_frontalface_alt_tree.xml");
haar = new HaarCascade("D:\\haarcascade_frontalface_alt_tree.xml");
Image inputImg = Image.FromFile(@"D:\1.jpg");
Image<Bgr, byte> imageFrame = new Image<Bgr, byte>(new Bitmap(inputImg));
if (imageFrame != null) {
Image<Gray, byte> grayFrame = imageFrame.Convert<Gray, byte>();
var faces = grayFrame.DetectHaarCascade(haar, 1.1, 10, HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(20, 20))[0];
foreach (var face in faces) {
imageFrame.Draw(face.rect, new Bgr(Color.Green), 3);
}
}
pictureBox1.Image = imageFrame.ToBitmap();
有任何想法或帮助吗?非常感谢你。
解决了,谢谢。
答案 0 :(得分:0)
我使用Haar级联方法对检测到的行人做了类似的程序,看看以下代码是否可以帮助解决问题:
private void Haar(object sender, EventArgs arg)
{
Image<Bgr, Byte> frame;
Image<Gray, Byte> Gray_frame;
HaarCascade UpperBody = new HaarCascade("haarcascade_mcs_upperbody.xml");
HaarCascade LowerBody = new HaarCascade("haarcascade_lowerbody.xml");
HaarCascade FullBody = new HaarCascade("haarcascade_lowerbody.xml");
try
{
frame = _capture.QueryFrame();
Gray_frame = frame.Convert<Gray, byte>();
double fps = _capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FPS);
//Gray_frame = foreground(frame);
if (inteiro == false)
{
MCvAvgComp[] cima = UpperBody.Detect(Gray_frame, escala, vizinhos,
Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
new System.Drawing.Size(size1, size2));
MCvAvgComp[] baixo = LowerBody.Detect(Gray_frame, escala, vizinhos,
Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
new System.Drawing.Size(size1, size2));
foreach (MCvAvgComp body in cima)
{
Gray_frame.Draw(body.rect, new Emgu.CV.Structure.Gray(10), 2);
cout++;
}
foreach (MCvAvgComp body in baixo)
{
Gray_frame.Draw(body.rect, new Emgu.CV.Structure.Gray(10), 2);
cout++;
}
}
//Full Body
if (inteiro == true)
{
MCvAvgComp[] full = FullBody.Detect(Gray_frame, escala, vizinhos,
Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
new System.Drawing.Size(size1, size2));
foreach (MCvAvgComp body in full)
{
Gray_frame.Draw(body.rect, new Emgu.CV.Structure.Gray(10), 2);
cout++;
}
}
this.Text = cout.ToString();
imageBox1.Image = Gray_frame;
}
catch { }
}