Guide for getting Emgu CV to work in the GHPython component:
You want to do something with Computer Vision and Grasshopper?
Already Realised that OpenCV doesn’t work with IronPython?
Scrapped the forums and found that Emgu CV is an option?
Can’t figure out how to install the damn thing?
I feel for you because I’ve been there too. That’s why I made this guide!
Follow these 7 easy steps and you will be ready to detect faces (and other body parts) from the comfort of the GHPython component in Grasshopper:
Turn on your Computer.
Download the latest version of EmguCV from SourceForge (in my case it was 4.2.0).
Link for EmguCV download: https://sourceforge.net/projects/emgucv/files/
Install EmguCV to “C:\Emgu”
Create a python file called “EmguInit.py” and save it at “C:\Emgu\bin”.
The file should contain the following code:
import clr clr.AddReferenceToFile("Emgu.CV.World.NetStandard.dll") clr.AddReferenceToFile("Emgu.CV.UI.dll") from Emgu.CV import * from Emgu.CV.UI import * from Emgu.CV.Structure import * from System import *
In Rhino add a Module Search path for python.
You can do this by typing in EditPythonScript in the command line. When the Rhino Python Editor opens, go to Tools --> Options and add “C:\Emgu\bin” to the search paths.
Under “C:\Emgu\libs” you are going to find two folders “x64” and “x86”. Copy both of them to the “C:\Program Files\Rhino 6\System” folder.
After Rhino starts again you will be able to use Emgu CV from GHPython by importing EmguInit:
import EmguInit from EmguInit import *
To use OpenCV methods you will need to utilise the Emgu CV “CvInvoke” class:
img = cv2.imread('test_2.png') – OpenCV syntax
img = CvInvoke.Imread('test_2.png') – Emgu CV syntax
You can find more information on EmguCV CvInvoke methods here:
Good luck in anything you are trying to do!