C# EmguCV 类型初始化异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11369684/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
EmguCV TypeInitializationException
提问by rkmax
i really a newbie with EgmuCV
我真的是 EgmuCV 的新手
i try to capture images from webcam with the following code:
我尝试使用以下代码从网络摄像头捕获图像:
//Program.cs (Winform)
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.UI;
using Emgu.Util;
using Emgu.CV.Structure;
namespace EgmuCVTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Capture cp = new Capture();
ImageViewer imv = new ImageViewer();
Application.Idle += new EventHandler(delegate(object s, EventArgs ea)
{
imv.Image = cp.QueryFrame();
});
imv.ShowDialog();
}
}
}
i get the follow error:
我收到以下错误:


i check and have all necesary dll in the .exe folder
我检查并在 .exe 文件夹中有所有必要的 dll
采纳答案by rkmax
After experiencing this same problem for a while, I found the instructions for solving this (TypeInitializer Exception) are incomplete.
在遇到同样的问题一段时间后,我发现解决此问题的说明(TypeInitializer Exception)不完整。
For a basic app, you need
cvextern.dll, Emgu.CV.dll, Emgu.CV.UI.dll, Emgu.Util.dllin the .EXE's directory.You need a x86(x64) dir in the .exe directory and inside "x86" dir you need
opencv_calib3dXXX.dll, opencv_contribXXX.dll, opencv_coreXXX.dll, opencv_features2dXXX.dll, opencv_highguiXXX.dll, opencv_imgprocXXX.dll, opencv_legacyXXX.dll, opencv_mlXXX.dll, opencv_objectdetectXXX.dll, opencv_videoXXX.dllandcudart32_42_9.dll, npp32_42_9.dll, opencv_flann240.dll
对于基本应用程序,您需要
cvextern.dll, Emgu.CV.dll, Emgu.CV.UI.dll, Emgu.Util.dll在 .EXE 目录中。你需要一个86(64)DIR在.exe文件目录和里面的“86” DIR你需要
opencv_calib3dXXX.dll, opencv_contribXXX.dll, opencv_coreXXX.dll, opencv_features2dXXX.dll, opencv_highguiXXX.dll, opencv_imgprocXXX.dll, opencv_legacyXXX.dll, opencv_mlXXX.dll, opencv_objectdetectXXX.dll, opencv_videoXXX.dll和cudart32_42_9.dll, npp32_42_9.dll, opencv_flann240.dll
The app will work as soon as you include all of the required DLLs.
只要您包含所有必需的 DLL,该应用程序就会运行。
回答by Denis
Another case that happened to me was that I had a NuGet package that was installed but not loaded for my project so the references looked good but at run-time, I got the TypeInitializationException.
发生在我身上的另一个案例是,我安装了一个 NuGet 包,但没有为我的项目加载,因此引用看起来不错,但在运行时,我得到了 TypeInitializationException。
-manage NuGet packages
- 管理 NuGet 包
-clock manage on the package
- 包上的时钟管理
-check the box with the current project.
- 选中当前项目的框。
回答by fian
I'm using Emgu 3.0 64 bit and the only thing i need to do to fix this problem is change the build type in my project into x64.
我正在使用 Emgu 3.0 64 位,我唯一需要做的就是将我的项目中的构建类型更改为 x64。
Right click on your project's name-> Properties-> Build-> Platform Target-> x64
右键单击您的项目名称->属性->构建->平台目标-> x64
refer to http://www.codeproject.com/Articles/257502/Creating-Your-First-EMGU-Image-Processing-Project
参考http://www.codeproject.com/Articles/257502/Creating-Your-First-EMGU-Image-Processing-Project
hope it helps someone.
希望它可以帮助某人。
回答by Hyman Miller
This problem also occurs if you are using OpenCV DLL compiled with GPU support but your PC doesn't have a GPU, e.g. if you are using a portable computer with Intel graphics chipset.
如果您使用支持 GPU 编译的 OpenCV DLL,但您的 PC 没有 GPU,也会出现此问题,例如,如果您使用的是带有 Intel 图形芯片组的便携式计算机。
In this case you can use the older version 2.4.0 which still offers DLL without GPU support:
在这种情况下,您可以使用旧版本 2.4.0,它仍然提供不支持 GPU 的 DLL:
https://sourceforge.net/projects/emgucv/files/emgucv/2.4.0/libemgucv-windows-x64-2.4.0.1717.zip
https://sourceforge.net/projects/emgucv/files/emgucv/2.4.0/libemgucv-windows-x64-2.4.0.1717.zip
回答by Minion
Just copy the cvextern.dllfile from x64 folder if you are using 64bit OS and then copy it to the debugfolder of your project.
如果您使用的是 64 位操作系统,只需从 x64 文件夹中复制cvextern.dll文件,然后将其复制到项目的调试文件夹中。
Note:Do it manually because "add existing item"doesn't copy it.
注意:手动执行,因为“添加现有项目”不会复制它。

