unity3d

时间:2015-04-22 11:12:12

标签: visual-studio opencv unity3d static-libraries

我尝试在unity3d中使用opencv。 This page建议整合unity + opencv的一些步骤。要做第一步,我在visual studio 2013上创建一个静态库项目。我将opencv库添加到此vs项目中。

我已经安装了opencv2.4.10,因此我没有再次安装opencv。 我的步骤如下:

1. Download OpenCV 2.4.10 

2. Create a Win32 console application - Select static library

3. Config opencv..
   3.1. Menu Project ---- $ProjectName Properties

   3.2. Choose Configuration Manager... and add x64 platform

   3.3. At configuration field, choose All configuration
         3.3.1. At Configuration Properties ---- C/C++ ---- Additional   Include Directories, add opencv include folders
     $opencv\build\include
     $opencv\build\opencv
     $opencv\build\opencv2 NOTE: $opencv is a folder that you have installed opencv

   3.3.2. At Configuration Properties ---- Linker ---- Additional Library         Directories, add opencv library folder
     $opencv\build\x64\vc12\lib

  3.4. At configuration field, choose Debug mode
       < <3.4.1. At Configuration Properties ---- Linker ---- Additional dependencies ---- add dependence libraries
      opencv_stitching248d.lib
      opencv_contrib248d.lib
      opencv_videostab248d.lib
      opencv_superres248d.lib
      opencv_nonfree248d.lib
      opencv_gpu248d.lib
      opencv_ocl248d.lib
      opencv_legacy248d.lib
      opencv_ts248d.lib
      opencv_calib3d248d.lib
      opencv_features2d248d.lib
      opencv_objdetect248d.lib
      opencv_highgui248d.lib
      opencv_video248d.lib
      opencv_photo248d.lib
      opencv_imgproc248d.lib
      opencv_flann248d.lib
      opencv_ml248d.lib
      opencv_core248d.lib
      NOTE: These file above are located at .\opencv\build\x64\vc12\staticlib\

 3.5. At configuration field, choose Release mode
        3.5.1. At Configuration Properties ---- Linker ---- Additional dependencies ---- add dependence libraries
  opencv_***.lib

 NOTE: These file above are located at .\opencv\build\x64\vc12\staticlib\

 3.6. Add $opencv\build\x64\v12\bin to System Environment Path
 3.7. Restart Visual studio
 3.8. Build project

现在我应该做第三步。但是我应该将哪些文件复制到Asset > Plugins文件夹中?所有项目或特定文件?

我在Asset&gt;中放置了2个文件(使用64位lib文件创建),名为Visual Studio 2013\Projects\OpenCVStaticDll\x64\Debug\OpenCVStatic(目标文件库)和Visual Studio 2013\Projects\OpenCVStaticDll\OpenCVStaticDll\x64\Debug\OpenCVStatic(预编译头文件)。 step 4上的插件文件夹。我使用32位相同的方式创建它们,并将它们放在C:/Program Fİles(x86)/Unity/Editor下。

我将所有opencv _ **。lib(x86/vc12/staticlib下)放在C:/Program Fİles(x86)/Unity/Editor下。

Opencv-C ++代码:

#include "stdafx.h"

#include <opencv2\core\core.hpp>    
#include <opencv2\imgproc\imgproc.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <iostream>

#pragma once
extern "C" {
    int func();
}


extern "C" {

int func()
{

    cv::Point p;
    p.x = 1;
    p.y = 0;
    return p.y;
}

}

Unity C#代码:

public class DefaultTrackableEventHandler : MonoBehaviour,
                                        ITrackableEventHandler
{

[DllImport ("OpenCVStaticDll")]
private static extern int func();
void Update () {
    if (Input.GetMouseButtonDown (0)) {
        mTrackableBehaviour.gameObject.transform.position = new Vector3 (
            mTrackableBehaviour.gameObject.transform.position.x + (int) (func ()*3),
            mTrackableBehaviour.gameObject.transform.position.y,
            mTrackableBehaviour.gameObject.transform.position.z);
    }
}

0 个答案:

没有答案