无法加载 DLL 'opencv_core242': 找不到指定的模块。Emgu CV

7

我想开始使用emgu CV open CV for C#,但是我在尝试时遇到了问题。我正在按照这个指南来使用emgu CV链接制作简单的程序,但是我遇到了以下错误:(你知道我做错了什么吗?)

    System.TypeInitializationException was unhandled
      Message=The type initializer for 'Emgu.CV.CvInvoke' threw an exception.
      Source=Emgu.CV
      TypeName=Emgu.CV.CvInvoke
      StackTrace:
       at Emgu.CV.Image`2..ctor(String fileName) in c:\Emgu\emgucv-windows-x86-gpu 2.4.2.1777\Emgu.CV\Image.cs:line 144
       at TEST.Form1.button1_Click(Object sender, EventArgs e) in c:\documents and settings\laci\my documents\visual studio 2010\Projects\TEST\TEST\Form1.cs:line 28
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at TEST.Program.Main() in c:\documents and settings\laci\my documents\visual studio 2010\Projects\TEST\TEST\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.DllNotFoundException
       Message=Unable to load DLL 'opencv_core242': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
       Source=Emgu.CV
       TypeName=""
       StackTrace:
            at Emgu.CV.CvInvoke.cvRedirectError(CvErrorCallback errorHandler, IntPtr userdata, IntPtr prevUserdata)
            at Emgu.CV.CvInvoke..cctor() in c:\Emgu\emgucv-windows-x86-gpu 2.4.2.1777\Emgu.CV\PInvoke\CvInvoke.cs:line 166
       InnerException: 

1
你的代码是什么?你尝试了什么?请具体说明。 - Soner Gönül
不知道如何以可读的方式发布核心代码...但它是一个简单的代码,可以在按钮点击时从文件加载图像并将其转换为另一种格式。 - Laci
可能是[Emgu.CV.CvInvoke抛出异常]的重复问题 (http://stackoverflow.com/questions/12509582/emgu-cv-cvinvoke-threw-an-exception)。 - Peter O.
7个回答

9

我已经将链接中提到的两个dll文件放置在我的应用程序输出目录中。 - Laci
3
当一个 .DLL 文件还需要另一个 .DLL 文件时,错误消息中将不会显示另一个 .DLL 文件。例如,1.dll 需要 2.dll,而你的 C# 封装程序使用了 1.dll。错误消息将显示找不到 1.dll,因为不能加载 1.dll。因此,我建议你添加所有你认为 Emgu 使用的 OpenCV 的 .DLL 文件,并在你的应用编译成功后尝试删除未使用的文件,直到只剩下必需的文件。祝你好运。 - Didac Perez Parera
1
你也可以使用DependencyWalker来查找缺失的.DLL文件。 - Didac Perez Parera
看起来OpenCV不再提供2.4.2版本的下载了,但EMGU库仍然依赖于它?有人有获取OpenCV 2.4.2或迁移EMGU的建议吗? - bjornruffians
将nvcuda.dll复制到bin/目录下的以下注释解决了我的运行时问题。根据我的平台,我还需要从EMGU libs/文件夹中获取DLL。 - bjornruffians

3

我会为大家节省很多时间。

对于EMGU CV版本2.4.*,缺失的dll文件是“nvcuda.dll”,它不是EMGU二进制文件的一部分,但通常位于系统32文件夹中(如果没有安装英伟达驱动程序,则可能需要在线寻找该dll文件)。


1
在我的情况下,只需从http://sourceforge.net/projects/emguexample/files/下载nvcuda.dll,然后按照说明将nvcuda.dll复制到您的工作目录中(在我的情况下是Debug文件夹-我正在使用Visual Studio 2012与Emgu CV)。 - Lê Quang Duy

1

1

虽然这是个老问题,但我也遇到了同样的情况。后来发现OpenCV 2.4.0版本已经加入了GPU支持,如果你没有Nvidia显卡,那么nvcuda.dll文件会丢失,导致opencv_core242.dll无法加载。我尝试了各种方法,唯一的解决方案是回退到2.3.0版本,一切都正常了。


0

以下是解决问题的正确步骤。

访问:https://sourceforge.net/project/emgucv/emgucv/2.4.2/
根据您的操作系统下载特定版本的emgucv 2.4.2,例如对于Windows x86,您可以下载:libemgucv-windows-x86-gpu-2.4.2.1777.exe

将其安装在某个位置,例如C:\ Emgu 然后转到C:\ Emgu \ emgucv-windows-x86-gpu 2.4.2.1777 \ bin \ x86,并复制所有opencv dll文件并将其粘贴到应用程序exe输出目录中。

要删除不必要的 OpenCV DLL 文件,您可以运行应用程序并按下 Ctrl+A 尝试删除文件。那些被应用程序使用的文件将无法删除,因为应用程序正在运行并且它们正在使用中,而未使用的 DLL 文件将被删除。除此之外,您可以使用 Dependency Walker 应用程序(http://www.dependencywalker.com/),但该应用程序已过时,可能无法正常工作。

0

http://www.dependencywalker.com/下载依赖项查看器,打开声称无法加载的.dll文件。然后查找依赖项,如果一个或多个依赖项缺失于应用程序目录甚至您的系统文件夹(system32或syswow64)中,则需要将它们放入其中。


0

正如错误所述 - 它无法在应用程序的工作目录中找到本地DLL。确保将opencv_core242.dll库复制到输出目录和应用程序的工作目录中。


你确定它在工作目录中吗?你可以用“Environment.WorkingDirectory”来验证。检查路径并检查 DLL 是否沿着该路径存在。 - Vaughan Hilts

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接