0

我是 OpenCV 的新手。

我在 C# 和 Visual Studio 2015 中使用 Emgu CV 3.1 库。

我在从网络摄像头读取实时视频时遇到问题。我不知道为什么 Capture() 构造函数会发生异常。我浪费了我2天的时间。

Plzzz 帮助我并在 Visual Studio 2015 上的 Emgu CV 3.1 中为我提供解决方案。我得到了 TypeInitializationException。我还上传了异常的图片。 TypeInitializationException 在这里

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using Emgu.CV;
using Emgu.CV.Structure;

namespace FaceRecognition_3._0
{
    public partial class Form1 : Form
    {
        private Capture _capture;
        private CascadeClassifier _cascadeClassifier;


        public Form1()
        {
            InitializeComponent();

            _capture = new Capture();
            imgCamUser.Image = _capture.QueryFrame();
            startProcess();
        }

        public void startProcess()
        {
            _cascadeClassifier = new CascadeClassifier(Application.StartupPath + "/haarcascade_frontalface_alt_tree.xml");

            using (var imageFrame = _capture.QueryFrame().ToImage<Bgr, Byte>())
            {
                if (imageFrame != null)
                {
                    var grayframe = imageFrame.Convert<Gray, byte>();
                    var faces = _cascadeClassifier.DetectMultiScale(grayframe, 1.1, 10, Size.Empty); //the actual face detection happens here
                    foreach (var face in faces)
                    {
                        imageFrame.Draw(face, new Bgr(Color.BurlyWood), 3); //the detected face(s) is highlighted here using a box that is drawn around it/them

                    }
                }

                imgCamUser.Image = imageFrame;
            }
        }
    }
}

`

4

2 回答 2

0

Emgu.CV.CvInvoke当在可执行文件的文件夹中找不到非托管 dll时,将引发此异常。

根据EmguCV Wiki,您必须将 OpenCV dll 从复制<EmguFolder>/bin到执行目录(可能bin/Debug)。

于 2016-06-19T19:13:27.817 回答
0

将 Emgu dll 文件和所有 Opencv dll 文件复制到您的 Debug 文件夹。这个对我有用。

于 2016-10-12T13:51:14.563 回答