EmguCV HaarCascade 问题

EmguCV HaarCascade issue

我已经使用 EmguCV 开发了一个有效的 C# 人脸识别程序。

但是,如果我加载 "haarcascade_fullbody.xml" 而不是 "haarcascade_frontalface_alt_tree.xml",我会遇到万能的访问冲突。

这是代码;

public Bitmap detection(Bitmap Source)
    {
        List<Image<Gray, byte>> TrainedImages = this.TrainedImages;
        List<String> Names = this.Names;
        Image<Bgr, byte> ImageFrame = new Image<Bgr, byte>(Source);
        Image<Gray, byte> grayFrame = ImageFrame.Convert<Gray, byte>();
        Image<Bgr, byte> overlay = new Image<Bgr, byte>(Source.Width, Source.Height);
        Graphics FaceCanvas;

        List<String> finimg = new List<String>();

        //HaarCascade haar = new HaarCascade("haarcascade_frontalface_alt_tree.xml");
        HaarCascade haar = new HaarCascade("haarcascade_fullbody.xml");

        var faces = grayFrame.DetectHaarCascade(haar, 1.1, 3, HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new System.Drawing.Size(25, 25))[0];

        foreach (var face in faces)
        {                
            overlay.Draw(face.rect, new Bgr(System.Drawing.Color.Green), 3);
            tempbmp = new Bitmap(100, 100);

            FaceCanvas = Graphics.FromImage(tempbmp);
            FaceCanvas.DrawImage(grayFrame.ToBitmap(), 0, 0, face.rect, GraphicsUnit.Pixel);
            detected.Add(tempbmp);
            if (doit)
            {
                saveBitmap(tempbmp, trainpath, trainnamer.Text);
                doit = false;
            }

            if (doit10)
            {
                for (int k = 1; k <= 10; k++)
                    saveBitmap(tempbmp, trainpath, trainnamer.Text);
                doit10 = false;
            }


            try
            {
                MCvTermCriteria termCrit = new MCvTermCriteria(TrainedImages.ToArray().Length, 0.001);//????????????
                EigenObjectRecognizer recognizer = new EigenObjectRecognizer(TrainedImages.ToArray(), Names.ToArray(), 2500, ref termCrit);
                MCvFont font = new MCvFont(FONT.CV_FONT_HERSHEY_TRIPLEX, 0.5d, 0.5d);

                String name = recognizer.Recognize(new Image<Gray, byte>(tempbmp));
                if (Names.Contains(name) == false)
                    name = "Stranger";
                else
                    name = removeformat(name);

                overlay.Draw(name, ref font, new System.Drawing.Point(face.rect.Left, face.rect.Top - 5), new Bgr(System.Drawing.Color.Green));
                finimg.Add(name);
            }
            catch (IndexOutOfRangeException)
            {
                MCvFont font = new MCvFont(FONT.CV_FONT_HERSHEY_TRIPLEX, 0.5d, 0.5d);
                ImageFrame.Draw("Stranger", ref font, new System.Drawing.Point(face.rect.Left, face.rect.Top - 5), new Bgr(color));
                continue;

            }

        }


        detected.Clear();

        Bitmap supra = overlay.ToBitmap();

        supra.MakeTransparent(System.Drawing.Color.Black);

        return supra;
    }

显然 xml 存在问题,与任何其他 haarcascade 一样,我尝试成功加载负载。我建议使用 HOGDescriptor"haarcascade_mcs_upperbody.xml" 进行行人检测。