OpenCV(EMGUCV包装器)在Unity中的集成 [英] OpenCV (EMGUCV wrapper) integration in Unity

查看:139
本文介绍了OpenCV(EMGUCV包装器)在Unity中的集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如您所知,OpenCV是一个非常有用的库,可让您在计算机视觉方面做奇妙而强大的事情.因此,我度过了一个愉快的时光,想出如何在Unity3d中使用它,我遇到了很多问题,并且在网上搜索时,我发现了一些建议,但没有一个对我有用.

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.

  • 我正在使用Unity Pro 4.0
  • 此版本的Emgu CV(emgucv-windows-universal-gpu 2.4.9.1847)
  • 我的统一项目目标是:Windows,而不是网络播放器

推荐答案

这是我为每个想要使用它的人所做的:

This is what I did for everyone who want to use it:

  1. 安装此版本的EmguCV,该版本在C中创建一个文件夹EMGU:
  2. 在此文件夹中,您将有一个名为"emgucv-windows-universal-gpu 2.4.9.1847"的文件夹.
  3. 转到"bin文件夹"
  4. 从"bin文件夹"中,您需要复制x86文件夹中的所有dll(22个dll),以及直接复制到bin中的所有dll(12个dll:Emgu.CV,Emgu.CV.UI….).对于X64目标,您可以尝试同样的方法,我认为这可以通过从X64文件夹中提取dll来实现.
  5. 在您的Unity项目(资产->插件)中创建一个名为Plugins的文件夹
  6. 将所有这34个dll文件粘贴到Plugins文件夹中
  7. 从这34个dll文件中,将"npp32_50_35"和"cudart32_50_35"复制到Unity编辑器文件夹中,在我的情况下为"C:\ Program Files(x86)\ Unity \ Editor"
  8. 您已经完成了Dlls的工作.

这是测试方法:

  1. 创建一个小脚本,该脚本需要一个"picture1.jpg",并将前200个对角像素的颜色更改为白色(255,255,255),然后保存新的"picture2.jpg".必须输入脚本:

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

  • 通过在Plugins文件夹中添加不同的dll,它们将在Mono编辑器中被自动引用,但是"System.Drawing"库可能会出现问题,因此请不要忘记using System.Drawing;并且您还必须通过转到脚本编辑器来引用它.

  • 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.

    如果是MonoDevelop-Unity,请转到左侧的解决方案资源管理器,右键单击参考"->编辑参考"->,然后在左列中搜索system.drawing,并在右列中进行查看以查看它,然后按OK.

    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

    也不要忘记以这种方式在Unity-> file->构建设置中更改构建设置:

    Also don’t forget to change the build settings in Unity->file->build settings in this way:

    • PC Mac和Linux而不是网络播放器
    • Target =窗口
    • Architecture = x86
    • 然后按播放器设置按钮"转到新屏幕中的其他设置",并将Api兼容性标准设置为.NET 2.0,而不是.NET 2.0子集

    目前,您可以自由测试脚本并使用OpenCV做出色的工作

    For now you’re free to test your script and do awesome work using OpenCV

    PS:我不确定为什么"npp32_50_35"和"cudart32_50_35"必须确切地放在编辑器"文件夹中,但这是唯一对我有用的情况.

    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.

    这篇关于OpenCV(EMGUCV包装器)在Unity中的集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆