【问题标题】:emgu CV C# with Capture class带有捕获类的 emgu CV C#
【发布时间】:2017-01-29 00:28:09
【问题描述】:

我一直在从事一个有趣的编码项目,该项目使用 emguCV 以及 C# 和 .NET。我遇到的问题是尝试在我的代码中初始化 Capture() 类。每次我尝试初始化 Capture 时都会引发异常:

    The Type initializer for 'Emgu.CV.CvInvoke' threw an Exception
    Exception type: System.InitializationException from Emgu.CV.dll

这是我的 C# 代码:

class Vision
{
    private Capture cap;
    private HaarCascade haar;
    private Form1 form;

    public Vision()
    {
            form = new Form1();
            cap = new Capture();
            haar = new HaarCascade("C:\\haarcascade_frontalface_alt2.xml");
    }
    public void faceDetect()
    {
        using(Image<Bgr, Byte> nextFrame = cap.QueryFrame())
        {
            if(nextFrame != null)
            {
                Image<Gray, Byte> grayframe = nextFrame.Convert<Gray, Byte>();
                var faces = grayframe.DetectHaarCascade(haar, 1.4, 4, HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(nextFrame.Width / 8, nextFrame.Height / 8))[0];
                foreach(var face in faces)
                {
                    nextFrame.Draw(face.rect, new Bgr(0, double.MaxValue, 0), 1);
                }
                form.setImage(nextFrame.ToBitmap());
            }
        }
    }
}

代码参考如下:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Emgu.CV;
    using Emgu.Util;
    using Emgu.CV.Structure;
    using Emgu.CV.CvEnum;
    using System.Drawing;

每次发生异常时,它都会显示在 cap = new Capture();

我还尝试将 Capture 类的相机索引设置为 0,1,2...,但也没有运气。我还想也许是因为我在 Mac 上运行 Windows,所以它没有检测到网络摄像头,但后来我确实下载了最新的 Windows 驱动程序来访问摄像头。我感谢所有提前提供帮助的人! :-)

【问题讨论】:

  • EmguCV 应该对 OpenCV 有一些非托管依赖,你确定一切都安装了吗?
  • 是的,我下载了正确的软件并按照附带的教程添加了依赖项。
  • 我知道,我是 necroposter,但在 Emgu CV 310 Capture 中被 VideoCapture 取代。我花了 2 天时间才找到它。

标签: c# .net opencv emgucv


【解决方案1】:

对于 EmguCV 的第一个用户来说,这是一个非常“经典”的错误,所以不用担心,很容易解决!

您需要为您的 Visual Studio 版本安装 MSVCRT。此外,也可能是您没有将 DLL 文件放入项目中并带有“如果较新则复制”。

查看the official emguCV site的所有详细信息

【讨论】:

    【解决方案2】:

    当非托管 DLL 依赖项无法加载时,可能会发生这种情况。尝试以下方法:

    1. 确保您使用的是正确版本的 EmguCV,即,如果您在 x86 模式下构建解决方案,您应该使用 x86 版本的 EmguCV,同样适用于 x64 版本。

      李>
    2. 确保 OpenCV DLL 在您的 PATH 中(或直接在 bin 目录中,如果这是 Console/WinForms/WPF 应用程序。)

    您可以找到操作方法here

    也可以参考官方文档here

    【讨论】:

      【解决方案3】:

      如果您使用的是 x64 机器,则需要更改项目设置。转到项目设置 -> 构建 -> 目标平台 -> x64。更多细节在这里:http://www.emgu.com/wiki/index.php/Setting_up_EMGU_C_Sharp

      【讨论】:

        猜你喜欢
        • 2019-03-10
        • 2017-12-24
        • 1970-01-01
        • 2011-06-13
        • 2015-05-30
        • 1970-01-01
        • 1970-01-01
        • 2017-12-05
        • 2023-03-04
        相关资源
        最近更新 更多