OpenCV + Android + Unity

前端 未结 3 1074
無奈伤痛
無奈伤痛 2021-01-30 03:44

I am looking for a way to use OpenCV in a Unity project and my target platform is an Android device.

I know that some assets exists on Unity asset store but I DO

3条回答
  •  情歌与酒
    2021-01-30 04:21

    Just to share what i had to do to compile the .so using C++17 with OpenCV 4.1.0 in Visual Studio.

    First, i had to update my AndroidNDK via the VS-Installer to n15c. Using a separately downloaded NDK did not work for me. When starting to build, the NDK_ROOT will be printed so you can check if it's setup correctly.

    Follow Pierre's Steps 1 and 2. In Linker->Input, i only set the library name in "Library Dependencies". I my case, that's opencv_java4, which is how the Linker likes it, derived from libopencv_java4.so

    In Tab General set:

    • Platform Toolset: Clang 5.0
    • Configuration Type: Dynamic Library (.so)
    • Target API: Nougat 7.0 (android-24) (others might be fine, too)
    • Use of STL: LLVM libc++ shared (c++_shared)

    In Tab Language set:

    • Enable Run-Time Information: true
    • C++ Language Standard: c++17 (-std=c++1z)

    In Tab Code Generation set Enable C++ Exceptions to yes

    In Tab Linker->Command Line add -lm -lz

    I also had to set Not using Precompiled Headers in C/C++ -> Precompiled Headers. I don't think this is generally necessary though.

    Hope this will be helpful for someone!

提交回复
热议问题