【问题标题】:Emgu.CV.Util.CvException: 'OpenCV: cv::XMLParser::parse' Error C#Emgu.CV.Util.CvException: 'OpenCV: cv::XMLParser::parse' 错误 C#
【发布时间】:2020-04-24 09:51:55
【问题描述】:

你好
在我使用 c# 编写的人脸识别程序中,打开程序时出错。
论坛1代码:

using AForge.Video;
using AForge.Video.DirectShow;
using Emgu.CV;
using Emgu.CV.Structure;
using System;
using System.Drawing;
using System.Windows.Forms;

namespace FaceApp
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    FilterInfoCollection filter;
    VideoCaptureDevice device;

    CascadeClassifier cascadeClassifier = new CascadeClassifier("haarcascade_frontalface_alt_tree.xml");

    private void Form1_Load(object sender, EventArgs e)
    {
        filter = new FilterInfoCollection(FilterCategory.VideoInputDevice);
        foreach (FilterInfo device in filter)
            comboBox1.Items.Add(device.Name);
        comboBox1.SelectedIndex = 0;
        device = new VideoCaptureDevice();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        device = new VideoCaptureDevice(filter[comboBox1.SelectedIndex].MonikerString);
        device.NewFrame += Device_NewFrame;
        device.Start();
    }

    private void Device_NewFrame(object sender, NewFrameEventArgs eventArgs)
    {
        Bitmap bitmap = (Bitmap)eventArgs.Frame.Clone();
        Image<Bgr, byte> grayImage = new Image<Bgr, byte>(bitmap);
        Rectangle[] rectangles = cascadeClassifier.DetectMultiScale(grayImage, 1.2, 1);
        foreach (Rectangle rectangle in rectangles)
        {
            using (Graphics graphics = Graphics.FromImage(bitmap))
            {
                using (Pen pen = new Pen(Color.Red, 1))
                {
                    graphics.DrawRectangle(pen, rectangle);
                }
            }
        }
        pictureBox1.Image = bitmap;
    }

    private void button2_Click(object sender, EventArgs e)
    {
        if (device.IsRunning)
            device.Stop();
    }
}
}

程序失败的代码行:

CascadeClassifier cascadeClassifier = new CascadeClassifier("haarcascade_frontalface_alt_tree.xml");

错误:异常未处理

Emgu.CV.Util.CvException: 'OpenCV: cv::XMLParser::parse'

我在互联网上搜索了一下错误,但找不到解决方案。
我在下面写的代码也不起作用。

private static readonly CascadeClassifier Classifier = new CascadeClassifier("haarcascade_frontalface_alt_tree.xml");
// or
private readonly CascadeClassifier Classifier = new CascadeClassifier("haarcascade_frontalface_alt_tree.xml");

我该如何解决这个问题?

【问题讨论】:

    标签: c# opencv exception emgucv


    【解决方案1】:

    我知道我的回答迟了,但这对那些面临同样问题的人会有所帮助。我遇到了同样的问题,这是由于 xml 文件。我从 EmguCV github 页面下载了 haarcascades。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-04
      • 2021-05-17
      • 2021-09-26
      • 2021-03-08
      • 2012-01-21
      • 1970-01-01
      • 1970-01-01
      • 2018-05-15
      相关资源
      最近更新 更多