10

I have installed the latest OpenCVSharp 2 (2.4.10.201...) with the NuGet manager in my project. Everything concerning OpenCVSharp.CvMat is working OK (loading, manipulation etc) so I am sure the installation is correct.

However I cannot use OpenCVSharp.CPlusPlus at all! The problem is that it doesn't load OpenCvSharpExtern.dll.

Error shown from try-catch block:

try
{
    Mat mat = new Mat();
} catch (Exception err)
{
    Console.WriteLine( err );
}

System.TypeInitializationException: The type initializer for 'OpenCvSharp.CPlusPlus.Mat' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'OpenCvSharpExtern': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   at OpenCvSharp.CPlusPlus.NativeMethods.core_Mat_sizeof()
   at OpenCvSharp.CPlusPlus.Mat..cctor()
   --- End of inner exception stack trace ---
   at OpenCvSharp.CPlusPlus.Mat..ctor()
   at MainClass.Main() in C:\Users\kotsias\Documents\Visual Studio 2015\Projects\MyCVSharp\ConsoleApplication1\Test.cs:line 14

The OpenCvSharpExtern.dll IS deployed alongside my .exe inside the following subfolders:

..\dll\x86

&

..\dll\x64

If I manually copy the x64 .dll in the same folder as my .exe, I still get the same error above. If I copy the x86 .dll, I get a different error:

System.TypeInitializationException: The type initializer for 'OpenCvSharp.CPlusPlus.Mat' threw an exception. ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
   at OpenCvSharp.CPlusPlus.NativeMethods.core_Mat_sizeof()
   at OpenCvSharp.CPlusPlus.Mat..cctor()
   --- End of inner exception stack trace ---
   at OpenCvSharp.CPlusPlus.Mat..ctor()
   at MainClass.Main() in C:\Users\kotsias\Documents\Visual Studio 2015\Projects\MyCVSharp\ConsoleApplication1\Test.cs:line 14
Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
Bill Kotsias
  • 3,258
  • 6
  • 33
  • 60

5 Answers5

20

It is not enough installing the "OpencvSharp{version} nuget" package. You also have to install the "OpencvSharp{version}.runtime.{operating_system}" package.

For example, in my case I had to install the following Nuget pacages:

  • OpencvSharp4
  • OpencvSharp4.runtime.win
4

Another issue that some may be hitting:

OpenCvSharpExtern.dll requires mfplat.dll that is part of the Media Feature Pack. Windows 'N' editions do not include this by default.

It can be installed from Apps and Features->Optional features->Add a feature.

GazTheDestroyer
  • 20,722
  • 9
  • 70
  • 103
1

Probably you don't have correct version of Visual C++ Redistributable package installed.

OpenCvSharp 2.4.10 uses Visual C++ 2013 Redistributable Package. However, OpenCvSharp 2.4.10 is deprecated and author recommends to use OpenCvSharp 3.2:

#OpenCvSharp 2.4.10 Cross platform wrapper of OpenCV 2.4.10 for .NET Framework.

This project is deprecated. The latest release is available in OpenCvSharp.

For more information check:

Community
  • 1
  • 1
Leonid Vasilev
  • 11,910
  • 4
  • 36
  • 50
  • I need to use 3.5 framework, so I'm probably stuck with the older version. I tried the latest one but it wouldn't work with anything less than 4.0. – Bill Kotsias May 22 '17 at 11:29
  • 1
    Project README.md states that .NET Framework 2.0 and newer is supported. I created corresponding [issue](https://github.com/shimat/opencvsharp/issues/352) on GitHub. – Leonid Vasilev May 22 '17 at 14:27
1

Use this code on Package manager :

Install-Package OpenCvSharp4.Windows -Version 4.0.0.20190108
Dharman
  • 30,962
  • 25
  • 85
  • 135
hossein andarkhora
  • 740
  • 10
  • 23
1

I was having this problem in production (After Creating the Setup File and Installing it). I've solved it by doing the following steps

  1. Installed the OpenCVSharp Through NuGet Packages
  2. Setting the Platform Target to X64 in Project Properties
  3. Creating the Setup File with the same Platform
  4. Manually Copying the "packages\OpenCvSharp4.runtime.win.4.5.3.20210817\runtimes\win-x64\native\OpenCvSharpExtern.dll" file into the installation directory.