1

我正在展示我正在尝试开发的项目的简单版本。我在 haarCascade.cs 中不断收到 TypeIntilizationException 未处理的错误。这是我的代码

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Emgu.CV;
    using Emgu.CV.Structure;
    using Emgu.Util;
    using Emgu.CV.CvEnum;
    using System.IO;


    namespace Browseface
    {
    public partial class Form1 : Form
{
    private HaarCascade haar;
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        try
        {
            haar = new HaarCascade(@"C:\Users\Balram\Desktop\Frontal Face HaarCascades\Frontal Face HaarCascades\haarcascade_frontalface_alt_tree.xml");
        }
        catch (Exception ae)
        {
        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        try
        {
            Image inputimg = Image.FromFile(@"C:\Users\Balram\Desktop\ad.jpg");
            Image<Bgr, byte> imageframe = new Image<Bgr, byte>(new Bitmap(inputimg));
            if (imageframe != null)
            {
                Image<Gray, byte> grayform = imageframe.Convert<Gray, byte>();
                var faces =
                    grayform.DetectHaarCascade(haar, 1.4, 4, HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(25, 25))[0];
                foreach (var face in faces)
                {
                    imageframe.Draw(face.rect, new Bgr(Color.Green), 3);
                }
                pictureBox1.Image = imageframe.ToBitmap();
            }
        }
        catch (Exception at)
        {
        }
    }
}
}

在以下行的我的 HaarCascade.cs 文件中,我收到一个错误

     protected override void DisposeObject()
  {
     CvInvoke.cvReleaseHaarClassifierCascade(ref _ptr);
  }

该 TypeIntilizationException 未处理。(我已经添加了参考 Emgu.CV、Emgu.CV.UI 和 Emgu.util dll 文件

4

0 回答 0