OpenCV + Unity3D集成 [英] OpenCV + Unity3D integration

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

问题描述

我是一个团结的开发人员第一次尝试我的手在opencv。我的初始目标是运行相机,并通过opencv在unity3d中检测blob。我是OpenCV的新人,我试图将其集成到Unity3D(在Windows 8与Unity 4.3.2和在一个mac与Unity 4.2.1f)。我按照主题。但我收到以下错误,只要我添加一个新的C#脚本。现在我删除这个脚本,错误发生了(这个脚本是Unity生成的C#脚本)。

I am a unity developer trying my hands on opencv for the first time. My initial goal is to run the camera and detect blobs via opencv in unity3d. I am new to OpenCV and am trying to integrate it in Unity3D (on Windows 8 with Unity 4.3.2 and on a mac with Unity 4.2.1f). I followed this thread. But I am getting the following error as soon as I add a new C# script. And the moment I delete this script, the error goes (this script is Unity generated C# script).

Internal compiler error. See the console log for more information. output was:
Unhandled Exception: System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.
  at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (bool)
  at System.Reflection.Assembly.GetTypes () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.RootNamespace.ComputeNamespaces (System.Reflection.Assembly assembly, System.Type extensionType) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.RootNamespace.ComputeNamespace (Mono.CSharp.CompilerContext ctx, System.Type extensionType) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.GlobalRootNamespace.ComputeNamespaces (Mono.CSharp.CompilerContext ctx) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Driver.LoadReferences () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0 

我找不到很多关于Unity和OpenCV集成。

I couldn't find much about Unity and OpenCV integration. It would be great if you could help me out with this error and point me to a recent tutorial to learn more.

提前感谢!

推荐答案

我们最近不得不处理同样的问题,我会发布一些通用的信息,可以解决你的问题,并帮助其他人。

We recently had to deal with the same problem, I'll post some generic information that would solve your problem and help other people.


  1. OpenCV库和OpenCV项目必须编译为静态库(请参见OpenCV作为静态库)

  2. OpenCV库和OpenCV项目必须为32位和64位架构

  3. 32位版本将在编辑器中使用(因为Unity3D编辑器仅支持32位架构),64位版本用于生产。

  4. 编译的OpenCV项目必须在Asset> Plugins文件夹中复制,OpenCV库必须复制到Assets文件夹中。

  5. 要在C#脚本中使用OpenCV项目,请遵循以下代码示例:

  1. OpenCV library and your OpenCV project must be compiled as static libraries (see OpenCV as a static library).
  2. OpenCV library and your OpenCV project must be compiled for both 32bit and 64bit architectures.
  3. The 32bit version will be used inside the editor (since the Unity3D editor supports 32bit architectures only), the 64 bit version for production.
  4. The compiled OpenCV project must be copied inside the Asset > Plugins folder, the OpenCV library must be copied inside the Assets folder.
  5. To use your OpenCV project inside a C# script, follow this code example:

using UnityEngine;
using System.Collections;
using System;
using System.Runtime.InteropServices;

public class PluginImport : MonoBehaviour {
    //Lets make our calls from the Plugin
    [DllImport ("OpenCVProject")]
    private static extern int openCVFunction(); 

    void Start () {
        openCVFunction();
    }
}

注意

其他信息来源:

  • Unity Manual:Plugins

这篇关于OpenCV + Unity3D集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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