Skip to content
Snippets Groups Projects

EmguCv_Unity

Getting started

Hello this is a tutorial to use Open CV on Unity-Windows with the use of Emgu CV.

This is open source but for commercial uses you need to purchase licenses, for more details see : https://www.emgu.com/wiki/index.php/Licensing:#A_Quick_Overview

Downloads

You'll need .Net

then you can copy the /Plugins directory above and put it in your Unity's /Assets/ directory
Or build it step by step see below (skip to Test otherwise)

Step by Step

On this link https://github.com/emgucv/emgucv/releases
Go find the release 4.9.0 (latest currently) download "libemgucv-windesktop-4.9.0.5494.zip"

Unzip it and go into \libs

Make a directory anywhere called Plugins (It'll go in your unity project later)
Copy all the dynamic link library ( .dll) here into Plugins.

Now go into \libs\runtimes\win-x64\native (change win-x64 if you're not in 64 bit)

And again copy all the dynamic link library ( .dll) here into Plugins.

Unity

I didn't test in all version but it worked in my 2021 version's project I'm using 2022.3.37f1 version here. We'll start from a blank 3D project (if you can't make it work in your project you can create a blank project quickly and try)

Dans Assets we will (create a Scripts directory for later)
and copy the Plugins directory. You will have a lot of Dependencies issues :

We'll need to go on www.nuget.org and download those dependencies :
Here I need System.Text.Json , PresentationCore , System.Drawing.Common , Microsoft.VisualStudio.DebuggerVisualizers First download the nupkg and extract it (same as downlading a .zip and unzip)

Then inside we go to lib/netstandard2.0 and copy the .dll to Plugins

We keep downloading until all dependencies are resolved (note that some dependencies will have dependencies of their own) I deleted Emgu.CV.Wpf in Plugins because I couldn't find his dependencies PresentationCore. it's a minor part of EmguCv we should stil be able to use the majority of it.

Test

Wether you downloaded my /Plugins/ directory or built it step by step, we can now make a few test.

(We'll add a ball and a move script to have something to look at in our blank project see Scripts/move.cs)

First test: Recording

a real time recording feature to place on a camera see Scripts/Recorder. Place the script on the camera tou want to record.

There is a colorConversion because OpenCv is in BGR while Unity is in RGB. And a Flip because OpenCv places the origin on the top left of images and Unity in the bottom left (=> going up means an increasing Y_coordinate in Unity but decreasing in Open_Cv)

Second test: Basic tracking