我是 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;
}
}
}
}
`