Difference between revisions of "Download And Installation"

From Emgu CV: OpenCV in .NET (C#, VB, C++ and more)
Jump to navigation Jump to search
(13 intermediate revisions by the same user not shown)
Line 5: Line 5:
 
*From your project, right click on "References" and select "Manager Nuget Packages..." option. It will open up nuget package manager. In package source, make sure that "nuget.org" is selected. (If you are using the commercial release, please check the instruction in the commercial download area for instructions to setup the commercial release nuget repository.)
 
*From your project, right click on "References" and select "Manager Nuget Packages..." option. It will open up nuget package manager. In package source, make sure that "nuget.org" is selected. (If you are using the commercial release, please check the instruction in the commercial download area for instructions to setup the commercial release nuget repository.)
  
 +
 +
===== CPU only nuget package =====
 
*Under "Browse", enter the search text "emgu.cv.runtime" and you should be able to find the Emgu.CV.runtime.windows nuget package.  
 
*Under "Browse", enter the search text "emgu.cv.runtime" and you should be able to find the Emgu.CV.runtime.windows nuget package.  
 
[[File:install_EmguCV_Nuget.png| 600px]]
 
[[File:install_EmguCV_Nuget.png| 600px]]
Line 11: Line 13:
  
 
*Click the "Install" button. Nuget will download Emgu.CV.runtime.windows and configure the project for you.
 
*Click the "Install" button. Nuget will download Emgu.CV.runtime.windows and configure the project for you.
 +
 +
===== CUDA nuget package 4.4.0.4099 =====
 +
The version available directly from nuget.org is version 4.4.0.4099. If you want simple installation, you can use this version.
 +
 +
*Under "Browse", enter the search text "Emgu.CV.runtime.windows.cuda" and you should be able to find the Emgu.CV.runtime.windows.cuda nuget package.
 +
 +
Please make sure the package is created by "Emgu Corporation" for the official release.
 +
 +
*Click the "Install" button. Nuget will download Emgu.CV.runtime.windows.cuda and configure the project for you.
 +
 +
===== CUDA nuget pacakge 4.5.1+ =====
 +
For more recent versions of Emgu.CV.runtime.windows.cuda package, they are not available from nuget.org. If you need to use the nuget package with cuda support, you can download two large nuget packages:
 +
 +
<code>Emgu.CV.runtime.windows.cuda.{version}.nupkg</code>
 +
 +
<code>Emgu.runtime.windows.cuda.dnn.cnn.{cuda_dnn_version}.nupkg</code>
 +
 +
and hosted it on your local nuget repository.
 +
 +
For v4.5.3+, you can find the nuget packages from the GitHub release page. e.g. For 4.5.3 release you can download them from [https://github.com/emgucv/emgucv/releases/tag/4.5.3 here]
 +
 +
The newer CUDA DNN package has a file, e.g."cudnn_cnn_infer64_8.dll" in v8.0.4, that is 688MB in size, after the nuget package compression the nupkg file is still 287MB. Nuget.org has a hard limit in package size of 250MB, this prevent the package being uploaded to nuget.org. Unless NVidia break up "cudnn_cnn_infer64_8.dll" into multiple smaller files, or nuget.org increase the file limit, we will not be able to upload the latest cuda nuget packages into nuget.org. The existing 4.4 release use older version of CUDNN and has nuget package reaching 248MB, we have moved onto newer version of CUDA and CUDNN to support the RTX 30xx series of graphic card and is no longer using the previous version of CUDNN. Commercial license holder will not be affected, we have the Emgu.CV.runtime.windows.cuda package uploaded to our commercial nuget repository which have larger nupkg size limit (500MB).
  
 
====Commercial Release====
 
====Commercial Release====
Line 27: Line 51:
  
 
*Click the "Install" button. Nuget will download Emgu CV commercial release and configure the project for you.
 
*Click the "Install" button. Nuget will download Emgu CV commercial release and configure the project for you.
 +
 +
====Targeting .Net Framework====
 +
If you are targeting .Net Core or .Net 5+, you can skip this session.
 +
 +
 +
If you are targeting .Net Framework, when using Emgu.CV.runtime.windows(.dldt / .cuda / .cuda.dldt) nuget packages for windows, please set the build architecture to either "x86" or "x64". Do not set the architecture to "Any CPU". .Net Framework do not have the capability to deploy nuget package that target multiple architectures. If you set the architecture to "x86", the files under "runtime\win-x86\native" in the runtime nuget package will be copied to the folder of the executable. If you set the architecture to "x64", the files under "runtime\win-x64\native" in the runtime nuget package will be copied to the folder of the executable. If you set the architecture to "Any CPU", none of the native files will be copied over, and you will have a PInvoke exception.
 +
 +
 +
If you are targeting .Net Core or .Net 5+, you can use "Any CPU". .Net Core and .Net 5+ are build to handle multiple architecture native binary deployments. All files under the "runtime" folder will be copied recursively to the folder of the executable, the runtime will load the correct files based on the running architecture.
  
 
===Using the Downloadable packages===
 
===Using the Downloadable packages===
Line 91: Line 124:
 
*Hello World ([[Hello_World_in_CSharp |C#]] or [[Hello_World_in_VB.NET |VB .NET]]) is a good starting point.
 
*Hello World ([[Hello_World_in_CSharp |C#]] or [[Hello_World_in_VB.NET |VB .NET]]) is a good starting point.
  
====The type initializer for 'Emgu.CV.CvInvoke' threw an exception.====
+
====The type initializer for 'Emgu.CV.CvInvoke' threw an exception====
 
If you see this exception, please check the following
 
If you see this exception, please check the following
  
Line 119: Line 152:
 
===== Are you missing any dependency? =====
 
===== Are you missing any dependency? =====
 
Download [http://www.dependencywalker.com/ Dependency Walker] and use it to open the "cvextern.dll" file. Check if any dependency is missing. The native 64-bit binaries can be found under the "runtimes\win-x64\native" subfolder, from your fodler of executable. The 32-bit binaries can be found under the "runtimes\win-x86\native" subfolder, from your folder of executable.
 
Download [http://www.dependencywalker.com/ Dependency Walker] and use it to open the "cvextern.dll" file. Check if any dependency is missing. The native 64-bit binaries can be found under the "runtimes\win-x64\native" subfolder, from your fodler of executable. The 32-bit binaries can be found under the "runtimes\win-x86\native" subfolder, from your folder of executable.
 +
 +
You can run <code>depends.exe</code> to bring up the UI, and use it to open the "cvextern.dll" file.
 +
 +
Once the file is open, you can use "File" => "Save" to save the result as a ".dwi" file. If you are planning to file a bug report you should include the ".dwi" file in the bug description.
 +
 +
If you are in a window-less environment (e.g. docker image), download dependency walker to the same folder as the native binary and run the following command from command line:
 +
 +
<code> .\depends.exe -c -f:0 -u:1 -pa:1 -pf:0 -pe:0 -pb -sm:12 -sf:4  -oc:cvextern.csv -od:cvextern.dwi depends.exe </code>
 +
 +
The command may return right away, but the dependency walker will be running in the background to check dependency. You may find that there is no output files generated. Don't panic, take a break. It can take up to 30 minutes for the dependency report to be generated and written to disk. After a while, check the folder for the "cvextern.dwi" file. If it shows up, you can copy it out of docker to exam it.
  
 
===== I have checked all of above but I still got the Exception =====
 
===== I have checked all of above but I still got the Exception =====
Line 259: Line 302:
 
* Emgu.CV.Platform\Netstandard\Emgu.CV.Platform.Netstandard.csproj
 
* Emgu.CV.Platform\Netstandard\Emgu.CV.Platform.Netstandard.csproj
 
* Emgu.CV.Runtime\Mac\Emgu.CV.Runtime.Mac.shproj
 
* Emgu.CV.Runtime\Mac\Emgu.CV.Runtime.Mac.shproj
 +
 +
=== System.DllNotFoundException ===
 +
If you encounter this exception, there might be missing dependencies. In this case, go to the folder where the <code>libcvextern.dylib</code> file is:
 +
* If you build emgu cv from source, go to <code>libs/macos</code> folder.
 +
* If you use emgu cv runtime nuget package, go to <code>bin/{build_config}/{dotnet_version}/runtimes/osx/native</code> (e.g. <code>bin/Debug/net5.0/runtimes/osx/native</code>) folder.
 +
 +
Run this command
 +
<code>otool -L libcvextern.dylib</code>
 +
 +
and check if there is any dependency missing.
 +
 +
If no native dependency is missing, you can trace from .Net runtime. Move back to <code>Emgu.CV.Example/BuildInfo.NetCore.Console</code> folder (or the folder of your project) and run this two commands:
 +
 +
<code>DYLD_PRINT_APIS=1 dotnet run</code>
 +
 +
<code>DYLD_PRINT_LIBRARIES=1 dotnet run</code>
 +
 +
to find missing dependencies.
 +
  
 
=== Demos ===
 
=== Demos ===
The demo solution is available under the "Solution\Mac" folder.
+
If you use the zip file, the demo solution can be found under the "Solution\Mac" folder. To avoid getting security error from Mac OS such as
 +
 
 +
<code>"{App ID}" is blocked from use because it is not from an identified developer</code>
 +
 
 +
please change the demo project output folder to somewhere '''outside''' the unzipped folder.
  
 
== iOS ==
 
== iOS ==
Line 271: Line 337:
 
<pre>libs\Emgu.CV.Platform.IOS.dll</pre>
 
<pre>libs\Emgu.CV.Platform.IOS.dll</pre>
 
Adding this two dll files as a reference to your Xamarin iOS App should allow you to use Emgu CV in your App.  
 
Adding this two dll files as a reference to your Xamarin iOS App should allow you to use Emgu CV in your App.  
For 4.5.1 and later release, after adding the references. You should call <pre>CvInvokeIOS.Init()</pre> in the main ios app, to make sure the native binary is included in the compilation. Otherwise you may see a long list of missing native reference errors during compilation.
+
For 4.5.1 and later release, after adding the references. You should call <pre>CvInvokeIOS.Init()</pre> in the main ios app, to make sure the native binary is included in the compilation. Otherwise you may see a long list of missing native reference errors during compilation. You can add the function call in the AppDelegate.cs file, under the FinishedLaunching function:
 +
<source lang="csharp">
 +
        [Export("application:didFinishLaunchingWithOptions:")]
 +
        public bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
 +
        {
 +
            // Override point for customization after application launch.
 +
            // If not required for your application you can safely delete this method
 +
 
 +
            Emgu.CV.CvInvokeIOS.Init();
 +
 
 +
            return true;
 +
        }
 +
</source>
  
 
=== Adding Emgu CV to your Xamarin iOS App using nuget package ===
 
=== Adding Emgu CV to your Xamarin iOS App using nuget package ===

Revision as of 15:09, 4 October 2021

Windows

Nuget

Using nuget package manager is probably the easiest way to include Emgu CV library in your project.

Open Source Release

  • From your project, right click on "References" and select "Manager Nuget Packages..." option. It will open up nuget package manager. In package source, make sure that "nuget.org" is selected. (If you are using the commercial release, please check the instruction in the commercial download area for instructions to setup the commercial release nuget repository.)


CPU only nuget package
  • Under "Browse", enter the search text "emgu.cv.runtime" and you should be able to find the Emgu.CV.runtime.windows nuget package.

Install EmguCV Nuget.png

Please make sure the package is created by "Emgu Corporation" for the official release.

  • Click the "Install" button. Nuget will download Emgu.CV.runtime.windows and configure the project for you.
CUDA nuget package 4.4.0.4099

The version available directly from nuget.org is version 4.4.0.4099. If you want simple installation, you can use this version.

  • Under "Browse", enter the search text "Emgu.CV.runtime.windows.cuda" and you should be able to find the Emgu.CV.runtime.windows.cuda nuget package.

Please make sure the package is created by "Emgu Corporation" for the official release.

  • Click the "Install" button. Nuget will download Emgu.CV.runtime.windows.cuda and configure the project for you.
CUDA nuget pacakge 4.5.1+

For more recent versions of Emgu.CV.runtime.windows.cuda package, they are not available from nuget.org. If you need to use the nuget package with cuda support, you can download two large nuget packages:

Emgu.CV.runtime.windows.cuda.{version}.nupkg

Emgu.runtime.windows.cuda.dnn.cnn.{cuda_dnn_version}.nupkg

and hosted it on your local nuget repository.

For v4.5.3+, you can find the nuget packages from the GitHub release page. e.g. For 4.5.3 release you can download them from here

The newer CUDA DNN package has a file, e.g."cudnn_cnn_infer64_8.dll" in v8.0.4, that is 688MB in size, after the nuget package compression the nupkg file is still 287MB. Nuget.org has a hard limit in package size of 250MB, this prevent the package being uploaded to nuget.org. Unless NVidia break up "cudnn_cnn_infer64_8.dll" into multiple smaller files, or nuget.org increase the file limit, we will not be able to upload the latest cuda nuget packages into nuget.org. The existing 4.4 release use older version of CUDNN and has nuget package reaching 248MB, we have moved onto newer version of CUDA and CUDNN to support the RTX 30xx series of graphic card and is no longer using the previous version of CUDNN. Commercial license holder will not be affected, we have the Emgu.CV.runtime.windows.cuda package uploaded to our commercial nuget repository which have larger nupkg size limit (500MB).

Commercial Release

  • If you are using the commercial release, please check the instruction in the commercial download area for instructions to setup the commercial release nuget repository. Commercial release download link can be found in the "Download Instructions" at the bottom of your purchase complete page. It is also available on the product delivery email, under the "CUSTOMER SERVICE" session. Please click on the link below "Your Order Data" to access the Commercial release download area.

Order data.png

  • If you have the Professional / Ultimate license. The instruction can be found at the bottom of the page once you clicked into the "windows" folder.
  • If you have the Windows only license. The instructions can be found at the bottom of the page as soon as you logged in.
  • Once the commercial nuget repository is setup, you should be able to find the following three packages, please choose one depends on your requirement:
    • Emgu.CV.runtime.windows.dldt is the commercial release runtime without CUDA;
    • Emgu.CV.runtime.windows.cuda.dldt is the commercial release runtime with CUDA support.
    • Emgu.CV.runtime.uwp is the commercial release runtime for UWP.
  • Click the "Install" button. Nuget will download Emgu CV commercial release and configure the project for you.

Targeting .Net Framework

If you are targeting .Net Core or .Net 5+, you can skip this session.


If you are targeting .Net Framework, when using Emgu.CV.runtime.windows(.dldt / .cuda / .cuda.dldt) nuget packages for windows, please set the build architecture to either "x86" or "x64". Do not set the architecture to "Any CPU". .Net Framework do not have the capability to deploy nuget package that target multiple architectures. If you set the architecture to "x86", the files under "runtime\win-x86\native" in the runtime nuget package will be copied to the folder of the executable. If you set the architecture to "x64", the files under "runtime\win-x64\native" in the runtime nuget package will be copied to the folder of the executable. If you set the architecture to "Any CPU", none of the native files will be copied over, and you will have a PInvoke exception.


If you are targeting .Net Core or .Net 5+, you can use "Any CPU". .Net Core and .Net 5+ are build to handle multiple architecture native binary deployments. All files under the "runtime" folder will be copied recursively to the folder of the executable, the runtime will load the correct files based on the running architecture.

Using the Downloadable packages

If you are using the downloadable packages (.zip or .exe), you can follow the instructions below.

Getting the Dependency

  • For Version 3.0+, the required vcrt dlls are included in the "x86" and "x64" folder. You will be ready as long as you copy all the unmanaged dlls in the "x86" and "x64" folder to the folder of executable.
  • For version 2.4.x the bundled OpenCV binary is build with Visual Studio 2010, you will needs to installed MSVCRT 9.0 SP1 x86 or MSVCRT 9.0 SP1 x64 to resolve the dependency issue.
  • For Version 2.0 - 2.3, the bundled OpenCV binary is build with Visual Studio 2008, you will needs to installed MSVCRT 9.0 SP1 to resolve the dependency issue.
  • For Version 1.5, the bundled OpenCV pre1.1 binary is build with Visual Studio 2005, you will needs to installed MSVCRT 8.0 SP1 to resolve the dependency issue.

Building the Examples

  • Follow this link for the latest release files on GitHub
  • Download and extract the windows installer.
  • Install the software
  • Go to the "Solution\Windows.Desktop" folder.
  • Open Emgu.CV.Example.sln and build the solution. At this point, you should be able to run the example programs.

Creating a New Project in Visual Studio

To use the framework in Visual Studio, you need to

  • Download and extract the opensource package "libemgucv-windesktop-{version}.zip" or commercial package "libemgucv-windows-ipp-dldt-{version}.zip".

For a Full guide to using the dependencies under Visual Studio and C# see the C# Tutorial.

Core Functionality
Managed Code
  • Create a new Visual Studio project or use an existing one
  • Add reference
    • For 4.4 release. Add the Emgu.CV.Platform.NetStandard.dll to Reference. Add Emgu.CV.Runtime\Windows\Emgu.CV.Runtime.Windows shared project to include the native dlls into your project.
    • For 4.2 release. Add the Emgu.CV.World.NetStandard.dll to Reference. Add Emgu.CV.Runtime\Windows\Emgu.CV.Runtime.Windows shared project to include the native dlls into your project.
    • For 3.1 release. Add the Emgu.CV.World.dll to Reference of the project.
    • For 3.0 release. Add the two files Emgu.Utils.dll and Emgu.CV.dll to References of the project.
  • Optionally put the following lines in the top of your code to include the Emgu.CV namespace.

using Emgu.CV;

using Emgu.CV.Structure;

Open CV unmanaged dll
  • For Emgu CV 4.2 and above, adding Emgu.CV.Runtime\Windows\Emgu.CV.Runtime.Windows shared project to your project will take care of deploying all the native files.
  • For older releases, copy the "x86" and "x64" folder, along with the DLLs inside those folder to the folder of the executable. Emgu CV is able to load the unmanaged binary from the "x86" folder when running in 32bit mode, and load the unmanaged binary from the "x64" folder when running in 64bit-mode. If you are only targeting the "x64" platform, you only need to copy the "x64" folder.
CUDA (GPU) package
  • For Emgu CV 4.2 and above, adding Emgu.CV.Runtime\Windows\Emgu.CV.Runtime.Windows shared project to your project will take care of deploying all the native files.
  • For Emgu CV 3.x+, only package containing -cuda in its name (e.g. libemgucv-xxx-cuda-xxx ) has CUDA processing enabled.
    • Install the latest cuda graphic card driver from NVIDIA on your development workstation.
    • Adding reference: For 3.1 release. You don't need to add extra references. The Cuda namespace is part of the Emgu.CV.World.dll; For 3.0 release. Add Emgu.CV.Cuda.dll to References
    • Optionally put the following lines in the top of your code to include the Emgu.CV.Cuda namespace. using Emgu.CV.Cuda;
  • For Emgu CV 2.x, CUDA (GPU) for image processing is only available for Emgu CV rev 2.2.1 and later. Only package containing -gpu in its name (e.g. libemgucv-xxx-gpu-xxx) has CUDA (GPU) processing enabled.
    • Install the latest cuda graphic card driver from NVIDIA on your development workstation.
    • Add Emgu.CV.GPU.dll to References
    • Optionally put the following lines in the top of your code to include the Emgu.CV.GPU namespace. using Emgu.CV.GPU;
GUI

To display image using Emgu's ImageBox

  • If using nuget, add Emgu.CV.UI nuget package to your project.
  • If adding dlls from release package, add Emgu.CV.UI.dll to References
  • Optionally put the following lines in the top of your code to include the Emgu.CV.UI namespace.

using Emgu.CV.UI;

Start Developing
  • Follow the Tutorial to learn how to use Emgu CV.
  • Hello World (C# or VB .NET) is a good starting point.

The type initializer for 'Emgu.CV.CvInvoke' threw an exception

If you see this exception, please check the following

Have you installed MSVCRT?
  • If you are using nuget packages, you can skip this step. MSVCRT should be installed by the nuget package.
  • For Version 4.5.1+, the required vcrt dlls are included in the "libs\x86" and "libs\x64" folder from the release package. You will be ready as long as you copy all the unmanaged dlls in the "libs\x86" folder to "runtimes\win-x86\native" folder, and "libs\x64" folder to "runtimes\win-x64\native" folder, under the folder of the executable.
  • For Version 3.0+, the required vcrt dlls are included in the "libs\x86" and "libs\x64" folder. You will be ready as long as you copy all the unmanaged dlls in the "libs\x86" folder to "x86" folder, and "libs\x64" folder to "x64" folder, under the folder of the executable.
  • For Version 2.4+, the bundled OpenCV binary is build with Visual Studio 2010, you will needs to installed MSVCRT 10.0 SP1 x86 or MSVCRT 10.0 SP1 x64 to resolve the dependency issue.
  • For Version 2.0+, the bundled OpenCV binary is build with Visual Studio 2008, you will needs to installed MSVCRT 9.0 SP1 to resolve the dependency issue.
  • For Version 1.5, the bundled OpenCV pre1.1 binary is build with Visual Studio 2005, you will needs to installed MSVCRT 8.0 SP1 to resolve the dependency issue.
Have you copied the OpenCV dlls to the execution directory?
  • If you are using the nuget package, you can skip this step. The native 64-bit binaries should be deployed by the nuget package to "runtimes\win-x64\native" subfolder, from your folder of executable. The 32-bit binaries should be deployed by the nuget package to "runtimes\win-x86\native" subfolder, from your folder of executable.
  • If you are not using the nuget package. Make sure the unmanaged DLLs are in the execution directory.
    • For Emgu CV Version >=4.5.1, the required vcrt dlls are included in the "libs\x86" and "libs\x64" folder from the release package. You will be ready as long as you copy all the unmanaged dlls in the "libs\x86" folder to "runtimes\win-x86\native" folder, and "libs\x64" folder to "runtimes\win-x64\native" folder, under the folder of the executable.
    • For Emgu CV version >=2.4.2, this means the "x86" and "x64" folder and all the dlls within the folders. The folder names and file structures should not be altered when deploying with the application.
    • For Emgu CV version >=2.4.2, this means the "x86" and "x64" folder and all the dlls within the folders. The folder names and file structures should not be altered when deploying with the application.
    • For EMGU CV version 2.4 cudart64_42_9.dll, cvextern.dll, npp64_42_9.dll, opencv_calib3dXXX.dll, opencv_contribXXX.dll, opencv_coreXXX.dll, opencv_features2dXXX.dll, opencv_flannXXX.dll, opencv_highguiXXX.dll, opencv_imgprocXXX.dll, opencv_legacyXXX.dll, opencv_mlXXX.dll, opencv_nonfreXXX.dll, opencv_objectdetectXXX.dll, opencv_videoXXX.dll, where XXX is the OpenCV version number.
    • For Emgu CV version 2.2, 2.3 this means the following dlls: 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 where XXX is the OpenCV version number.
    • For Emgu CV version <= 2.1, this means the following dlls:cvXXX.dll, cvauxXXX.dll, cxcoreXXX.dll, highguiXXX.dll, opencv_ffmpegXXX.dll, mlXXX.dllcvextern.dll where XXX is the OpenCV version number.
  • When not using nuget package, the best way to set up your project:
    • Copy the unmanaged DLLs to your project folder
    • Right click on the project, click Add->Existing Item and select all unmanaged DLLs. Add them to the project.
    • For each of the included Dlls, left click on it, find the "Copy to Output Directory" option and select "Copy if newer"
Are you missing any dependency?

Download Dependency Walker and use it to open the "cvextern.dll" file. Check if any dependency is missing. The native 64-bit binaries can be found under the "runtimes\win-x64\native" subfolder, from your fodler of executable. The 32-bit binaries can be found under the "runtimes\win-x86\native" subfolder, from your folder of executable.

You can run depends.exe to bring up the UI, and use it to open the "cvextern.dll" file.

Once the file is open, you can use "File" => "Save" to save the result as a ".dwi" file. If you are planning to file a bug report you should include the ".dwi" file in the bug description.

If you are in a window-less environment (e.g. docker image), download dependency walker to the same folder as the native binary and run the following command from command line:

.\depends.exe -c -f:0 -u:1 -pa:1 -pf:0 -pe:0 -pb -sm:12 -sf:4 -oc:cvextern.csv -od:cvextern.dwi depends.exe

The command may return right away, but the dependency walker will be running in the background to check dependency. You may find that there is no output files generated. Don't panic, take a break. It can take up to 30 minutes for the dependency report to be generated and written to disk. After a while, check the folder for the "cvextern.dwi" file. If it shows up, you can copy it out of docker to exam it.

I have checked all of above but I still got the Exception

In this case, please try to build and run the examples. After building the examples, try to run the "Hello World" Program.

If "Hello World" runs without any problem, compare it with you project, find the difference in configuration and fix it.

If "Hello World" get the same "The type initializer for 'Emgu.CV.CvInvoke' threw an exception." message, try to find out the InnerException and report it to the discussion forum

Building from Git

If you wants to build the development version of Emgu CV from source code, you can to get it from GIT following instructions on This page.

Prerequisite

  • You will need to install CMAKE in-order to build the unmanaged C++ code (OpenCV and cvextern.dll).
  • You will need Visual Studio 2019/ Visual Studio 2017 to build the Managed code (Emgu CV)

Configuring the project

32-Bit Windows

Run Build_Binary_x86_nocuda.bat script located in the platforms\windows folder of GIT.

64-Bit Windows

Run Build_Binary_x86-64_doc.bat script located in the platforms\windows folder of GIT.

Change the build options

If you are happy with the default flags, you can skip this step.

If you want to change the build options, use CMAKE to open the "build_x86" / "build_x64" folder, depends on if you are building for 32-bit or 64-bit. You can change the build flags and regenerate the unmanaged solution.

Building the unmanaged code

Double check if the emgucv.sln file exists in the root folder, if not, run the above step again. Open emgucv.sln solution located in the root folder with the matching version of Visual Studio, switch the configuration to "Release" and build the cvextern project.

At this point, the native Open CV dlls (cvextern.dll and dependencies) should be available under the libs/x86 / libs/x64 folder from the top most directory.

Building the managed code

  • Browse to the "Solution\Windows.Desktop" Folder
  • Open Emgu.CV.sln and build the solution.

At this point, the Emgu CV dlls should be available under the libs folder from the top most directory.

Linux

Getting ready

Ubuntu 20.04

  • dotnet SDK
    • For 4.5.1 release, you will need dotnet SDK 5.0. Please follow this instruction to install asp .net core on Ubuntu. Once that is done, run the following command to verify dotnet is installed:
      ubuntu:~$ dotnet --list-runtimes
      It should show a message similar to the following
      Microsoft.AspNetCore.App 5.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 5.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  • OpenCV
    • We will build a custom version of OpenCV in the next step. It is recommended to remove any OpenCV package if it is installed on your machine.
  • CMake

Emgu CV has adapted to use cmake to compile its source code (as well as OpenCV).

  • Installing GIT so you can check out the project folder, you can install GIT by running
    sudo apt-get install git
  • CUDA

Raspberry Pi OS

  • dotnet SDK
    • For 4.5.1 release, you will need dotnet SDK 5.0
  • OpenCV
    • We will build a custom version of OpenCV in the next step. It is recommended to remove any OpenCV package if it is installed on your machine.
  • CMake

Emgu CV has adapted to use cmake to compile its source code (as well as OpenCV).

  • Installing GIT so you can check out the project folder, you can install GIT by running
    sudo apt-get install git

Getting the source code

  • To build from source, you will need a Git client to check out the source code from SourceForge. For more information, see GIT. The following command can be used to check out the source:
git clone https://github.com/emgucv/emgucv emgucv 
  • Go to emgucv directory
cd emgucv
  • Initialize opencv, tesseract-ocr and cvblob submodules
git submodule update --init --recursive

Configuring & Building the project

Ubuntu 20.04

  • Got to the configuration folder.
    cd platforms/ubuntu/20.04
  • Installing the prerequisites. This only needs to be run once. You can install them by running
    ./apt_install_dependency
  • Use the following command to configure and build the project:
    ./cmake_configure
    If you need to enable CUDA support, make sure you have installed CUDA 11.2 in the previous steps, and use the following command instead
    ./cmake_configure cuda
  • If you want to re-configure the modules you need. Call
    ccmake build
    You can enable / disable modules as you need. e.g. If you do not want Emgu CV to build with tesseract. Set EMGU_CV_WITH_TESSERACT to OFF. Once all flags are set, press c to re-configure. Press q to quite cmake. Rebuild the project with
    cd build; make; cd ..

Raspberry Pi OS

  • Got to the configuration folder
    cd platforms/raspbian
  • Installing the prerequisites. This only needs to be run once. You can install the prerequisites by running
    ./apt_install_dependency
  • Use the following command to configure and build the project:
    ./cmake_configure
  • If you want to re-configure the modules you need. Call
    ccmake build
    You can enable / disable modules as you need. e.g. If you do not want Emgu CV to build with tesseract. Set EMGU_CV_WITH_TESSERACT to OFF. Once all flags are set, press c to re-configure. Press q to quite cmake. Rebuild the project with
    cd build; make; cd ..

Running the Examples

  • We have the native binary compiled. Now let's compile and run our first dot net core program.
cd Emgu.CV.Example\BuildInfo.NetCore.Console
  • make sure dotnet can load the dynamic library from the current location by typing
export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
  • Try to compile and run the program
dotnet run

System.DllNotFoundException

If you encounter this exception, there might be missing dependencies. In this case, go to the folder where the libcvextern.so file is:

  • If you build emgu cv from source, go to libs/x64, libs/arm or libs/x86 folder, depends on your system architecture.
  • If you use emgu cv runtime nuget package, go to bin/{build_config}/{dotnet_version}/runtimes/{arch}/native (e.g. bin/Debug/net5.0/runtimes/ubuntu.20.04-x64/native) folder.

Run this command ldd libcvextern.so

and check if there is any dependency missing.

If no native dependency is missing, you can trace from .Net runtime. Move back to Emgu.CV.Example/BuildInfo.NetCore.Console folder (or the folder of your project) and run this command

gdb dotnet

then, on the (gdb) commandline, type

run run

to debug with GDB.

You can also try

LD_DEBUG=libs dotnet run

to find missing dependencies.

Mac OS

Emgu CV for Mac OS is available under our commercial license. The instructions below applies to the Emgu CV for Mac OS, Professional or Ultimate commercial release.

Adding Emgu CV to your Xamarin Mac App

You can either add Emgu CV to your project by directly adding the binary files, or by adding two projects.

Using binary files

The "libs" folder of the Mac OS (or Pro) release package should contains the files

Emgu.CV.Platform.NetStandard.dll
macos/libcvextern.dylib

Please add Emgu.CV.Platform.NetStandard.dll as a reference to your Xamarin Mac App. Deploy "libcvextern.dylib" file to the folder of executable. Then you are ready to use Emgu CV in your Mac OS App.

If the files "Emgu.CV.Platform.NetStandard.dll" does not exist, you can compile the visual studio solution under "Solution\Mac\Emgu.CV.Mac.Example.sln" to build the dlls.

Using project files

Instead of using the binary files as mention above. You can also add this two projects as references into your existing project:

For v4.4.0

  • Emgu.CV.Platform\Netstandard\Emgu.CV.Platform.Netstandard.csproj
  • Emgu.CV.Runtime\Mac\Emgu.CV.Runtime.Mac.shproj

System.DllNotFoundException

If you encounter this exception, there might be missing dependencies. In this case, go to the folder where the libcvextern.dylib file is:

  • If you build emgu cv from source, go to libs/macos folder.
  • If you use emgu cv runtime nuget package, go to bin/{build_config}/{dotnet_version}/runtimes/osx/native (e.g. bin/Debug/net5.0/runtimes/osx/native) folder.

Run this command otool -L libcvextern.dylib

and check if there is any dependency missing.

If no native dependency is missing, you can trace from .Net runtime. Move back to Emgu.CV.Example/BuildInfo.NetCore.Console folder (or the folder of your project) and run this two commands:

DYLD_PRINT_APIS=1 dotnet run

DYLD_PRINT_LIBRARIES=1 dotnet run

to find missing dependencies.


Demos

If you use the zip file, the demo solution can be found under the "Solution\Mac" folder. To avoid getting security error from Mac OS such as

"{App ID}" is blocked from use because it is not from an identified developer

please change the demo project output folder to somewhere outside the unzipped folder.

iOS

Emgu CV for iOS is only available under our commercial license. The instructions below applies to the Emgu CV for iOS, Professional or Ultimate commercial release.

Adding Emgu CV to your Xamarin IOS App using dlls from the zip package

The iOS (or Pro) release package should contains the following two files:

libs\iOS\Emgu.CV.Platform.NetStandard.dll
libs\Emgu.CV.Platform.IOS.dll

Adding this two dll files as a reference to your Xamarin iOS App should allow you to use Emgu CV in your App.

For 4.5.1 and later release, after adding the references. You should call

CvInvokeIOS.Init()

in the main ios app, to make sure the native binary is included in the compilation. Otherwise you may see a long list of missing native reference errors during compilation. You can add the function call in the AppDelegate.cs file, under the FinishedLaunching function:

        [Export("application:didFinishLaunchingWithOptions:")]
        public bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // Override point for customization after application launch.
            // If not required for your application you can safely delete this method

            Emgu.CV.CvInvokeIOS.Init();

            return true;
        }

Adding Emgu CV to your Xamarin iOS App using nuget package

The commercial download page also provide access to the "Emgu.CV.runtime.ios" nuget pacakge. Similar to the "Emgu.CV.runtime.windows" nuget package that provide runtime dependencies for Windows, it provides the runtime dependencies for Emgu CV targeting iOS application. Once you download the nuget package, you can either put it in your own nuget server, or you can put it in a local folder and configure Visual Studio to use the folder as a local repository.

For 4.5.1 and later release, after adding the nuget package. You should call

CvInvokeIOS.Init()

in the main iOS app, to make sure the native binary is included in the compilation. Otherwise you may see a long list of missing native reference errors during compilation.

Please make sure you don't include more than one "Emgu.CV.runtime" packages for a single project. If you are developing multiplatform applications, you can create a library project that reference "Emgu.CV" without any "Emgu.CV.runtime" pacakge. After that, you can create seperate projects targeting different platforms referencing your common library. Each individual platform targeted project will reference the specific "Emgu.CV.runtime" package. e.g.

MyLibrary -> Add Reference to "Emgu.CV" nuget pacakge
MyWindowsApp -> Add Reference to "MyLibrary" and "Emgu.CV.runtime.windows" nuget pacakge
MyMacApp -> Add Reference to "MyLibrary" and "Emgu.CV.runtime.mac" nuget pacakge
MyAndroidApp -> Add Reference to "MyLibrary" and "Emgu.CV.runtime.android" nuget package
MyIOSApp -> Add Reference to "MyLibrary" and "Emgu.CV.runtime.ios" nuget package

Size of the binary

The "Emgu.CV.Platform.IOS.dll" file size is large. For example, in the 4.4.0 iOS release, this file is 724MB. It contains the native binary for all supported CPU architectures, including those for simulators.

However, if you are building an IPA for app store submission, and is only targeting ARM64 devices, you can select just ARM64 architecture. When the IPA is build, the compiler will strip out all the binary that are not used. It will significantly reduce the final size of the IPA. Depends on the number of functions you used, if you are only targeting a single ARM64 architecture, the final IPA size should be some where around 40MB.

Demos

The demo solution is available under the "Solution\iOS" folder.

Android

Emgu CV for Android is only available under our commercial license. The instructions below applies to the Emgu CV for Android, Professional or Ultimate commercial release.

Adding Emgu CV to your Xamarin Android App using dlls from the zip package

The "libs" folder of the Android (or Pro) release package should contains these two files

Emgu.CV.Platform.NetStandard.dll
Emgu.CV.Platform.Android.dll

Adding the above files as references to your Xamarin Android App should allow you to use Emgu CV in your App.

If the files does not exist, you can compile the visual studio solution under "Solution\Android\Emgu.CV.Android.sln" to build the dlls.

For 4.5.1 and later release, after adding the references. You should call

CvInvokeAndroid.Init()

in the main android app, to make sure the native binary is included in the compilation. Otherwise you may see PInvoke exception when you call an Emgu CV function on Android.

Adding Emgu CV to your Xamarin Android App using nuget package

The commercial download page also provide access to the "Emgu.CV.runtime.android" nuget pacakge. Similar to the "Emgu.CV.runtime.windows" nuget package that provide runtime dependencies for Windows, it provides the runtime dependencies for Emgu CV targeting Andorid application. Once you download the nuget package, you can either put it in your own nuget server, or you can put it in a local folder and configure Visual Studio to use the folder as a local repository.

For 4.5.1 and later release, after adding the nuget package. You should call

CvInvokeAndroid.Init()

in the main android app, to make sure the native binary is included in the compilation. Otherwise you may see PInvoke exception when you call an Emgu CV function on Android.

Please make sure you don't include more than one "Emgu.CV.runtime" packages for a single project. If you are developing multiplatform applications, you can create a library project that reference "Emgu.CV" without any "Emgu.CV.runtime" pacakge. After that, you can create seperate projects targeting different platforms referencing your common library. Each individual platform targeted project will reference the specific "Emgu.CV.runtime" package. e.g.

MyLibrary -> Add Reference to "Emgu.CV" nuget pacakge
MyWindowsApp -> Add Reference to "MyLibrary" and "Emgu.CV.runtime.windows" nuget pacakge
MyMacApp -> Add Reference to "MyLibrary" and "Emgu.CV.runtime.mac" nuget pacakge
MyAndroidApp -> Add Reference to "MyLibrary" and "Emgu.CV.runtime.android" nuget package
MyIOSApp -> Add Reference to "MyLibrary" and "Emgu.CV.runtime.ios" nuget package

Size of the binary

The "Emgu.CV.Platform.Android.dll" file size is large. For example, in the 4.5.1 Android release, this file is 70MB. It contains the native binary for all supported CPU architectures, including "arm64-v8a", "armeabi-v7a", "x86" and "x64".

If you are building an app for Google Play Store submission, we recommend using the AAB (Android App Bundle) format. When you upload the AAB file, The compressed size of the Emgu CV for Android runtime will take about 30MB (4 CPU architectures). However, when end-user download the APK package generated from the AAB file, only one out of 4 CPU architectures matching the user device will be included, resulting in a much smaller size occupied by Emgu CV for Android runtime. FYI, the download size limit of the compressed APK generated from the AAB is 150MB as of Apr 2021. That should give you lots of rooms to include other libraries on top of Emgu CV.

Another option is to build one APK per CPU architecture. The process of submmiting multi-architecture APK is much more compilcated than using AAB. Google recommend using AAB instead.

At last, if you are only targeting arm64-v8a devices, you can select just arm64-v8a architecture. When the final APK is build, the compiler will strip out all the binary for the architectures that are not used. It will significantly reduce the final size of the APK. Depends on the number of functions you used, if you are only targeting a single arm64-v8a architecture, the final APK size should be some where around 20-30MB.

Demos

The demo solution is available under the "Solution\Android" folder.