OpenCV + Unity3D集成

我是团结开发人员,第一次尝试使用opencv。 我最初的目标是运行相机并通过unity3d中的opencv检测blob。 我是OpenCV的新手,我正在尝试将它集成到Unity3D中(在Windows 8上使用Unity 4.3.2,在Mac上使用Unity 4.2.1f)。 我跟着这个post。 但是,一旦添加新的C#脚本,我就会收到以下错误。 当我删除这个脚本的那一刻,错误发生了(这个脚本是Unity生成的C#脚本)。

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 :0 at Mono.CSharp.RootNamespace.ComputeNamespaces (System.Reflection.Assembly assembly, System.Type extensionType) [0x00000] in :0 at Mono.CSharp.RootNamespace.ComputeNamespace (Mono.CSharp.CompilerContext ctx, System.Type extensionType) [0x00000] in :0 at Mono.CSharp.GlobalRootNamespace.ComputeNamespaces (Mono.CSharp.CompilerContext ctx) [0x00000] in :0 at Mono.CSharp.Driver.LoadReferences () [0x00000] in :0 at Mono.CSharp.Driver.Compile () [0x00000] in :0 at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in :0 

我找不到有关Unity和OpenCV集成的更多信息。 如果你可以帮助我解决这个错误并指出我最近的教程以了解更多信息,那将是很棒的。

提前致谢!

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

  1. 必须将OpenCV库和OpenCV项目编译为静态库(请参阅OpenCV作为静态库) 。
  2. 必须为32位和64位架构编译OpenCV库和OpenCV项目。
  3. 32位版本将在编辑器中使用(因为Unity3D编辑器仅支持32位架构),64位版本用于生产。
  4. 必须将已编译的OpenCV项目复制到Asset> Plugins文件夹中,必须将OpenCV库复制到Assets文件夹中。
  5. 要在C#脚本中使用OpenCV项目,请遵循以下代码示例:

     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(); } } 

    注意using指令!

其他信息来源:

  • Unity手册:插件