在Unity3D中使用EmguCV

2015.10.28

最近才發現以前自己寫的。

更新一下,unity已經有官方插件了 opencvforunity http://forum.unity3d.com/threads/released-opencv-for-unity.277080/

此外, emgucv3.0 也可開始支持unity5.0了,但是要商業版,需要掏錢,小問題是unity版本的例程不多。

另外沒錢可以從opencvsharp入手。 如http://sourceforge.net/projects/unityopencvsharpcamshift/


以下內容是以前寫的。

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

轉自國外網站http://stackoverflow.com/questions/16612513/opencv-emgucv-wrapper-integration-in-unity,先記下來,免得我忘了,我自己先測試一下,再來更新。

  1. Install this version of EmguCV, witch create a folder EMGU in C: disc
  2. In this folder you will have a single folder named “emgucv-windows-universal-gpu 2.4.9.1847”
  3. Go to “bin folder”
  4. From the “bin folder” you need to Copy all the dlls in the x86 folder (22 dlls), and also those in the bin directly (12 dlls: Emgu.CV, Emgu.CV.UI….) For X64 target, you can try the same thing, I think this will work by taking the dlls from the X64 folder.
  5. Create a folder named Plugins, in your Unity project (Assets Plugins)
  6. Paste all these 34 dlls file in the Plugins folder
  7. From this 34 dll files, copy the “npp32_50_35” and “cudart32_50_35” into the Unity editor folder, in my case it’s “C:\Program Files (x86)\Unity\Editor”
  8. You are done for the Dlls stuff.

This is how to test it:

1- 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"); 

2- 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

3- Also don’t forget to change the build settings in Unityfilebuild settings in this way: - PC Mac and Linux instead of webplayer
- Target= windows
- Architecture= x86
- Then push the “player settings button” go to the “other settings in the new screen” and set Api Compatibility lavel to .NET 2.0, instead of .NET 2.0 subset

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, and sorry if my English isn’t good. Good luck for everyone

 --------------------------------

2013-9-12我自己裝了一下,擦 感覺不太靠譜,各種報錯。而且好多是源文件的完全無能爲力了。然後我就去找了一下OpenCVSharp.這個是證實可以用的。下載OpenCVSharp源碼,去掉system.drawing,生成dll就可以直接用了。這個國內論壇上搜得到的。http://www.cocoachina.com/bbs/read.php?tid=94103&page=2&toread=1#810634  cocoaChina上的。在國外的話是一個日本人做的原創工作。還有代碼也很不錯。但是網速和牆的原因不一定能下下來。網址是:

http://ux.getuploader.com/aimino/   強烈建議多試幾次,還是不錯的。這個還有好多人用這種方法做了人臉識別的視頻,上傳到了youtube(需要翻牆),直接搜索就能搜到了搜索unity opencv。網址比較多,就不寫了。

總結:不讓上谷歌和youtube,國家是希望自己的科研一直落後到清朝去。


-------------------------------------------

2014-05-27 我發現現在有人弄出來了,搜搜一下csdn就可以了。有個哥們生成了一個用於unity的system.drawing.dll。

靠譜。歡迎大家試試,留個言能否使用。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章