Skip to content
Snippets Groups Projects
README.md 2.91 KiB
Newer Older
CHEREL Vincent's avatar
CHEREL Vincent committed
# EmguCv_Unity



## Getting started

CHEREL Vincent's avatar
CHEREL Vincent committed
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

CHEREL Vincent's avatar
CHEREL Vincent committed
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)
CHEREL Vincent's avatar
CHEREL Vincent committed
### Step by Step
CHEREL Vincent's avatar
CHEREL Vincent committed

CHEREL Vincent's avatar
CHEREL Vincent committed
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"   
CHEREL Vincent's avatar
CHEREL Vincent committed

CHEREL Vincent's avatar
CHEREL Vincent committed
<img src="screenshots/emgucv_release_4_9_0.png" width="150"> 
CHEREL Vincent's avatar
CHEREL Vincent committed

CHEREL Vincent's avatar
CHEREL Vincent committed
Unzip it and go into \libs
CHEREL Vincent's avatar
CHEREL Vincent committed

CHEREL Vincent's avatar
CHEREL Vincent committed
![](screenshots/libemgucv_libs.png)   
CHEREL Vincent's avatar
CHEREL Vincent committed

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

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

CHEREL Vincent's avatar
CHEREL Vincent committed
![](screenshots/libemgucv_libs_native.png)  
CHEREL Vincent's avatar
CHEREL Vincent committed

CHEREL Vincent's avatar
CHEREL Vincent committed
And again copy all the dynamic link library ( .dll) here into Plugins.

CHEREL Vincent's avatar
CHEREL Vincent committed
### Unity
CHEREL Vincent's avatar
CHEREL Vincent committed

CHEREL Vincent's avatar
CHEREL Vincent committed
I didn't test in all version but it worked in my 2021 version's project
CHEREL Vincent's avatar
CHEREL Vincent committed
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)
CHEREL Vincent's avatar
CHEREL Vincent committed

CHEREL Vincent's avatar
CHEREL Vincent committed
![](screenshots/unity_blank3D.PNG) 
CHEREL Vincent's avatar
CHEREL Vincent committed

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

CHEREL Vincent's avatar
CHEREL Vincent committed
![](screenshots/erreur_drag_plugins.PNG)
CHEREL Vincent's avatar
CHEREL Vincent committed

CHEREL Vincent's avatar
CHEREL Vincent committed
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)
CHEREL Vincent's avatar
CHEREL Vincent committed

CHEREL Vincent's avatar
CHEREL Vincent committed
![](screenshots/ex_nuget_pack.PNG)  
CHEREL Vincent's avatar
CHEREL Vincent committed

CHEREL Vincent's avatar
CHEREL Vincent committed
Then inside we go to lib/netstandard2.0 and copy the .dll to Plugins
CHEREL Vincent's avatar
CHEREL Vincent committed

CHEREL Vincent's avatar
CHEREL Vincent committed
![](screenshots/inside_nupkg.PNG)  
CHEREL Vincent's avatar
CHEREL Vincent committed

CHEREL Vincent's avatar
CHEREL Vincent committed
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.
CHEREL Vincent's avatar
CHEREL Vincent committed

CHEREL Vincent's avatar
CHEREL Vincent committed
## Test

CHEREL Vincent's avatar
CHEREL Vincent committed
Wether you downloaded my /Plugins/ directory or built it step by step, we can now make a few test.
CHEREL Vincent's avatar
CHEREL Vincent committed

(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
CHEREL Vincent's avatar
CHEREL Vincent committed
a real time recording feature to place on a camera see [Scripts/Recorder](Scripts/Recorder.cs). 
CHEREL Vincent's avatar
CHEREL Vincent committed
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