OpenCV + Unity3D integration

瘦欲@ 提交于 2019-11-28 17:20:29
Alberto Malagoli

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

    pay attention to the using directives!

Other sources of information:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!