Download And Installation
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.
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 package 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.
- If you have the Professional / Ultimate license. The commercial nuget server url can be found at the bottom of the page once you clicked into the "windows" folder.
- If you have the Windows only license. The commercial nuget server url can be found at the bottom of the page as soon as you logged in.
- Instructions on how to add a nuget source to Visual Studio can be found here
- 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.
Upgrade from packages.config to package reference
If you are using packages.config for your project, nuget's dependency resolution is broken when using "package.config" to managed nuget package. Microsoft recommend upgrading "package.config" to "package reference":
https://docs.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference
All visual studio 2019+ project templates also use "package reference" instead of "package.config".
If your project does not contains any package.config file and doesn't reference any nuget package, it is possible that your project may still default to use "package.config" to manage nuget packages. In this case, you will need to first install "Emgu.CV" nuget pacakge from nuget.org, afterwhich the "package.config" file will be visible in your project, and you can continute with the following steps.
You can perform the migration by right clicking on "packages.config", follows by a click on the circled option:
The project will be upgraded to use "package reference".
Once that is done, the error for installing Emgu.CV.runtime.windows nuget package should be gone, you can install the nuget package with dependency correctly resolved.
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 4.0+, the required vcrt dlls are included in the
Emgu.CV.Runtime\Windows\Emgu.CV.Runtime.Windows
shared project. You will be ready as long as you reference this shared project. - 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.6 release. Add the
Emgu.CV.dll
to Reference. AddEmgu.CV.Runtime\Windows\Emgu.CV.Runtime.Windows
shared project to include the native dlls into your project. - For 4.4 release. Add the
Emgu.CV.Platform.NetStandard.dll
to Reference. AddEmgu.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. AddEmgu.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
andEmgu.CV.dll
to References of the project.
- For 4.6 release. Add the
- 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:
- For .Net Framework, add
Emgu.CV.Platform.NetFramework.dll
to References - For .Net 3.1+, add
Emgu.CV.Platform.NetCore.dll
to References
- For .Net Framework, add
- 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,
whereXXX
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
whereXXX
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
whereXXX
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 2022 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_x86_64" 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/runtimes/win-x86/native
or libs/runtimes/win-x64/native
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
Nuget
Using nuget package manager is probably the easiest way to include Emgu CV library in your project.
Open Source / Commercial Release
From your project, you will need to add the Emgu.CV.runtime.{platform} nuget pacakge from nuget.org, if you have commercial license, you can use these package under the commercial license instead of GPL open source license.
Ubuntu on x86-64 architecture
- You can install Emgu.CV.runtime.ubuntu-x64 package from nuget.org, from commandline, you can do this with the following command:
dotnet add package Emgu.CV.runtime.ubuntu-x64
- You will need to install the dependencies for using Emgu CV runtime for the specific Ubuntu release. It can be found on github
https://github.com/emgucv/emgucv/blob/[version]/platforms/ubuntu/[ubuntu release name]/apt_install_dependency
e.g. For 4.9 release, you will need to run this script on the Ubuntu system:https://github.com/emgucv/emgucv/blob/4.9.0/platforms/ubuntu/24.04/apt_install_dependency
Raspberry Pi running Arm64 Raspberry Pi OS
- You can install Emgu.CV.runtime.debian-arm64 package from nuget.org, from commandline, you can do this with the following command:
dotnet add package Emgu.CV.runtime.debian-arm64
- You will need to install the dependencies for using Emgu CV for the specific Raspberry Pi OS release. It can be found on github
https://github.com/emgucv/emgucv/blob/[version]/platforms/debian/[debian release name]/apt_install_dependency
e.g. For 4.9 release, you will need to run this script on the Raspberry Pi OS:https://github.com/emgucv/emgucv/blob/4.9.0/platforms/debian/bullseye/apt_install_dependency
Raspberry Pi running 32-bit Arm Raspberry Pi OS
- You can install Emgu.CV.runtime.debian-arm package from nuget.org, from commandline, you can do this with the following command:
dotnet add package Emgu.CV.runtime.debian-arm
- You will need to install the dependencies for using Emgu CV for the specific Raspberry Pi OS release. It can be found on github
https://github.com/emgucv/emgucv/blob/[version]/platforms/debian/[debian release name]/apt_install_dependency
e.g. For 4.9 release, you will need to run this script on the Raspberry Pi OS:https://github.com/emgucv/emgucv/blob/4.9.0/platforms/debian/bullseye/apt_install_dependency
Build from Source
Getting Ready
Ubuntu 24.04
- dotnet SDK
- For 4.8.0+ releases, you will need dotnet SDK 8.0.
- For 4.7.0 release, you will need dotnet SDK 7.0.
- For 4.6.0 release, you will need dotnet SDK 6.0.
- For 4.5.4 and prior releases, 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 8.0.5 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.5 [/usr/lib/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 install git
Raspberry Pi OS
- dotnet SDK
- For 4.8.0+ releases, you will need dotnet SDK 8.0
- For 4.7.0 release, you will need dotnet SDK 7.0
- For 4.6.0 release, you will need dotnet SDK 6.0
- For 4.5.4 and prior releases, you will need dotnet SDK 5.0
- Instructions for installing dotnet SDK on Raspberry Pi OS can be found here
- 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 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 other submodules
git submodule update --init --recursive
Configuring & Building the project
Ubuntu 24.04
- Got to the configuration folder.
cd platforms/ubuntu/24.04
- Installing the prerequisites (e.g. dotnet sdk, libraries used by Open CV during compilation). This only needs to be run once. You can install them by running
./apt_install_dependency
If you need to enable CUDA support, use the following command instead./apt_install_dependency cuda
. This will also install CUDA SDK. - Use the following command to configure and build the project:
./cmake_configure
If you need to enable CUDA support, 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. SetEMGU_CV_WITH_TESSERACT
toOFF
. Once all flags are set, pressc
to re-configure. Pressq
to quite cmake. Rebuild the project withcd build; make; cd ..
Raspberry Pi OS
- Got to the configuration folder
cd platforms/raspberry_pi_os
- 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. SetEMGU_CV_WITH_TESSERACT
toOFF
. Once all flags are set, pressc
to re-configure. Pressq
to quite cmake. Rebuild the project withcd 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
- If you run into this error:
A fatal error occurred. The required library libhostfxr.so could not be found. If this is a self-contained application, that library should exist in [...]. If this is a framework-dependent application, install the runtime in the global location [/usr/local/sbin] or use the DOTNET_ROOT environment variable to specify the runtime location or register the runtime location in [/etc/dotnet/instal_location].
You need to set the DOTNET_ROOT variable. If dotnet is in the path, you can set the variable by calling:
export DOTNET_ROOT=$(dirname $(realpath $(which dotnet)))
After which you can re-compile and run the program:
dotnet run
System.DllNotFoundException
If you are using .Net 8.0+. One of the reason is the change of .Net change in the RID graph:
https://learn.microsoft.com/en-ca/dotnet/core/rid-catalog#using-rids
If this is the case, you will need to add the following to your project such that the project can use the RID graph to load the native library:
<PropertyGroup><UseRidGraph>true</UseRidGraph></PropertyGroup>
Without the flag above, .Net 8.0 will not look for platform specific native runtime folders.
If you already have this flag set in your project, or, if you are using .Net 7 or older, then 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/{arch}
,libs/runtimes/ubuntu-{arch}/native
orlibs/runtimes/linux-{arch}/native
folder, depends on your OS and system architecture. - If you use emgu cv runtime nuget package, go to
bin/{build_config}/{dotnet_version}/runtimes/{arch}/native
(e.g.bin/Debug/{dotnet_version}/runtimes/ubuntu-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
4.6.0 release
The "libs" folder of the Mac OS (or Pro) release package should contains the files
Emgu.CV.dll
runtimes/osx/native/libcvextern.dylib
Please add Emgu.CV.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.
4.5.1 - 4.5.5 releases
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
4.6.0 release
The iOS (or Pro) release package should contains the following two files:
libs\iOS\Emgu.CV.dll
libs\Emgu.CV.Platform.Xamarin.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.
4.5.1 - 4.5.5 releases
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.
Adding Emgu CV to your Xamarin iOS App using nuget package
The commercial download page also provide access to the "Emgu.CV.runtime.xamarin.ios" nuget package. Similar to the "Emgu.CV.runtime.windows" nuget package that provide runtime dependencies for Windows, these two packages provide the runtime dependencies for Emgu CV targeting Xamarin 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. You can find information about setting up a local nuget repository here
Initializing the runtime for Xamarin
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;
}
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.xamarin" package. After that, you can create separate projects targeting different platforms referencing your common library. Each individual platform targeted project will reference the specific "Emgu.CV.runtime.xamarin" package. e.g.
MyLibrary -> Add Reference to "Emgu.CV" nuget package MyWindowsApp -> Add Reference to "MyLibrary" and "Emgu.CV.runtime.windows" nuget package MyMacApp -> Add Reference to "MyLibrary" and "Emgu.CV.runtime.xamarin.mac" nuget package MyAndroidApp -> Add Reference to "MyLibrary" and "Emgu.CV.runtime.xamarin.android" nuget package MyIOSApp -> Add Reference to "MyLibrary" and "Emgu.CV.runtime.xamarin.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
4.6.0 release
The "libs" folder of the Android (or Pro) release package should contains these two files
Emgu.CV.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.
4.5.1 - 4.5.5 releases
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.
Adding Emgu CV to your Xamarin Android App using nuget package
The commercial download page also provide access to the "Emgu.CV.runtime.xamarin.android" nuget package. Similar to the "Emgu.CV.runtime.windows" nuget package that provide runtime dependencies for Windows, it provides the runtime dependencies for Emgu CV targeting Xamarin 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. You can find information about setting up a local nuget repository here
Initializing the runtime
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" package. 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 package MyWindowsApp -> Add Reference to "MyLibrary" and "Emgu.CV.runtime.windows" nuget package MyMacApp -> Add Reference to "MyLibrary" and "Emgu.CV.runtime.xamarin.mac" nuget package MyAndroidApp -> Add Reference to "MyLibrary" and "Emgu.CV.runtime.xamarin.android" nuget package MyIOSApp -> Add Reference to "MyLibrary" and "Emgu.CV.runtime.xamarin.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.