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

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

问题描述

如您所知,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 项目 (Assets->Plugins) 中创建一个名为 Plugins 的文件夹
  6. 将所有这 34 个 dll 文件粘贴到 Plugins 文件夹中
  7. 从这 34 个 dll 文件中,将npp32_50_35"和cudart32_50_35"复制到 Unity 编辑器文件夹中,在我的例子中是C:Program Files (x86)UnityEditor"
  8. 您已经完成了 Dll 的工作.

测试方法如下:

  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"库的问题,所以不要忘记 使用 System.绘图;并且您还必须通过转到脚本编辑器来引用它.

  • 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,进入左边的解决方案资源管理器,右击Refrences->Edit references->并在左栏中搜索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->build settings中的构建设置:

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

    • PC Mac 和 Linux 而不是 webplayer
    • 目标=窗口
    • 架构= x86
    • 然后按播放器设置按钮"转到新屏幕中的其他设置"并将Api Compatibility lavel设置为.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.

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

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