As you know OpenCV is very useful library that let you do amazing and powerful things in Computer vision. So I passed a good time to figure out how to use it in Unity3d, I had many problems, and searching in the Net, I have found several suggestions but not one worked for me.
Emgu CV is a cross-platform library that can be used to practically explore really interesting features from image capturing to character recognition. Emgu CV Essentials is a practical guide to the Emgu CV library, a . Net wrapper for the OpenCV image processing library.
This is what I did for everyone who want to use it:
This is how to test it:
Create a small script, that takes a “picture1.jpg” and change the color of the first 200 diagonal pixels color to white color (255,255,255) and then save the new “picture2.jpg” This is what you have to put in the script:
using UnityEngine;
using System.Collections;
using Emgu.CV;
using Emgu.CV.Util;
using Emgu.CV.UI;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
using System.Runtime.InteropServices;
using System;
using System.Drawing;
Image<Bgr, byte> picture = new Image<Bgr, byte>("C:\\picture1.jpg");
Bgr myWhiteColor = new Bgr(255, 255, 255);
For (int i=0; i<200; i++)
{picture[i,i]= color;}
picture.Save("C:\\picture2.jpg");
By adding the different dlls in the Plugins folder they will be referenced automatically in the Mono Editor, but probably you will have a problem with “System.Drawing” library, so don’t forget using System.Drawing
; and also you have to reference it by going to your script editor.
If MonoDevelop-Unity, go the solution explorer in the left, right click on Refrences->Edit references-> and search for system.drawing in the left column and check it to see it in the right column, then press ok
Also don’t forget to change the build settings in Unity->file->build settings in this way:
For now you’re free to test your script and do awesome work using OpenCV
PS: I’m not sure why exactly the “npp32_50_35” and “cudart32_50_35” have to be in the Editor folder, but it’s the only situation that worked for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With