如何OpenCV的集成到Qt创建者的Andr​​oid项目创建者、项目、Qt、OpenCV

由网友(冷风)分享简介:我用Qt Creator的编译Android应用程序。我需要的OpenCV融入它,我花了半天的时间配置正确,所以我想记录我把这里的步骤,以防其他​​人曾经有这样做。I use Qt Creator to compile an Android application. I needed to integrate Ope...

我用Qt Creator的编译Android应用程序。我需要的OpenCV融入它,我花了半天的时间配置正确,所以我想记录我把这里的步骤,以防其他​​人曾经有这样做。

I use Qt Creator to compile an Android application. I needed to integrate OpenCV into it, and it took me half a day to configure it properly, so I want to document the steps I took here, in case somebody else ever has to do it.

推荐答案

编辑:我忘了提,但我已经尝试运行的样本之一,当安装OpenCV的经理对我的手机,配备了OpenCV的-2.4.10-Android的SDK,所以我不知道它是否需要与否。在任何情况下,请记住它,如果它甚至后,我的步骤失败,您可能需要OpenCV的下载管理器(它可在谷歌商店)。

I forgot to mention, but I already had installed OpenCV Manager on my phone when trying to run one of the samples that come with OpenCV-2.4.10-android-sdk, so I don't know if it's needed or not. In any event, keep it in mind, if it fail even after my steps, you might need to download OpenCV Manager (it's available on the Google Store).

编辑2 :我使用ADT-束的Windows x86-20140702,Android的NDK-r10d,OpenCV的-2.4.10-Android的SDK,Qt Creator的3.3.0,和我的构建目标是机器人的armeabi-V7A(GCC 4.9,Qt的5.4.0)。

Edit 2: I'm using adt-bundle-windows-x86-20140702, android-ndk-r10d, OpenCV-2.4.10-android-sdk, Qt Creator 3.3.0, and my build target is "Android for armeabi-v7a (GCC 4.9, Qt 5.4.0)".

首先,我下载 OpenCV的-2.4.10-Android的SDK < /一>,并把我的项目目录。它包含了静态库,and链接顺序事项静态库GCC 。所以,你需要对它们进行排序不过如此。这是我的.pro文件看上去到底($$_PRO_FILE_PWD_指的是项目目录):

First, I downloaded OpenCV-2.4.10-android-sdk, and put into my project directory. It contains static libraries, and link order matters for static libraries for GCC. So you need to order them just so. This is how my .pro file looked in the end ($$_PRO_FILE_PWD_ refers to the project directory):

INCLUDEPATH += "$$_PRO_FILE_PWD_/OpenCV-2.4.10-android-sdk/sdk/native/jni/include"
android {
    LIBS += 
        -L"$$_PRO_FILE_PWD_/OpenCV-2.4.10-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a"
        -L"$$_PRO_FILE_PWD_/OpenCV-2.4.10-android-sdk/sdk/native/libs/armeabi-v7a"
        -llibtiff
        -llibjpeg
        -llibjasper
        -llibpng
        -lIlmImf
        -ltbb
        -lopencv_core
        -lopencv_androidcamera
        -lopencv_flann
        -lopencv_imgproc
        -lopencv_highgui
        -lopencv_features2d
        -lopencv_calib3d
        -lopencv_ml
        -lopencv_objdetect
        -lopencv_video
        -lopencv_contrib
        -lopencv_photo
        -lopencv_java
        -lopencv_legacy
        -lopencv_ocl
        -lopencv_stitching
        -lopencv_superres
        -lopencv_ts
        -lopencv_videostab

    ANDROID_PACKAGE_SOURCE_DIR=$$_PRO_FILE_PWD_/android
}

在该项目将编译,但它会失败与错误运行

After that the project will compile but it will fail to run with the error

E/AndroidRuntime(11873): java.lang.UnsatisfiedLinkError: Cannot load library: link_image[1891]:   176 could not load needed library 'libopencv_java.so' for 'libMyProject.so' (load_library[1093]: Library 'libopencv_java.so' not found)

要克服这一点,你需要添加libopencv_java.so到您的APK 和然后手动从QtActivity.java加载它。这是什么 ANDROID_PACKAGE_SOURCE_DIR = $$ _ PRO_FILE_PWD_ /安卓一行在结束了对。现在,你需要libopencv_java.so放在这里:

To overcome this, you need to add libopencv_java.so to your APK, and then manually load it from QtActivity.java. That's what the ANDROID_PACKAGE_SOURCE_DIR=$$_PRO_FILE_PWD_/android line at the end was for. Now you need to place libopencv_java.so here:

project_root/android/libs/armeabi-v7a/libopencv_java.so
project_root/android/src/org/qtproject/qt5/android/bindings/QtActivity.java

您可以从Android的目标构建目录中获取QtActivity.java,在我的情况的完整路径是c:Workspacebuild-MyProject-Android_for_armeabi_v7a_GCC_4_9_Qt_5_4_0-Debugandroid-buildsrcorgqtprojectqt5androidbindingsQtActivity.java,并将其直接复制。

You can get QtActivity.java from the Android target build directory, in my case the full path was c:Workspacebuild-MyProject-Android_for_armeabi_v7a_GCC_4_9_Qt_5_4_0-Debugandroid-buildsrcorgqtprojectqt5androidbindingsQtActivity.java, and just copy it.

这时你发现那些线是:

        // now load the application library so it's accessible from this class loader
        if (libName != null)
            System.loadLibrary(libName);

和负载 libopencv_java.so 在他们面前,让他们成为:

And load libopencv_java.so before them, so they become:

        // This is needed for OpenCV!!!
        System.loadLibrary("opencv_java");

        // now load the application library so it's accessible from this class loader
        if (libName != null)
            System.loadLibrary(libName);

请注意,您通过 opencv_java 的System.loadLibrary(),即使该文件是 libopencv_java.so

Note that you pass opencv_java to System.loadLibrary(), even though the file is libopencv_java.so.

阅读全文

相关推荐

最新文章