在cmakelists.txt android中添加opencv [英] add opencv in cmakelists.txt android

查看:470
本文介绍了在cmakelists.txt android中添加opencv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用本机代码,并通过使用ndk-build在android studio项目中打开cv,但我想使用cmake.请告诉我如何在cmakelists.txt文件中设置这些内容. 这是我的Android.mk文件

I am using native code and open cv in android studio project by using ndk-build but i want to use cmake. please tell me how to set these things in cmakelists.txt file. this is my Android.mk file

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

OpenCV_INSTALL_MODULES:=on
OPENCV_CAMERA_MODULES:=off
OPENCV_LIB_TYPE:=STATIC

ifeq ("$(wildcard $(OPENCV_MK_PATH))","")
include D:/OpenCV-3.1.0-android-sdk/sdk/native/jni/OpenCV.mk
else
include $(OPENCV_MK_PATH)
endif

LOCAL_MODULE := module_name

LOCAL_CFLAGS := -DANDROID_NDK \
                -DDISABLE_IMPORTGL

LOCAL_SRC_FILES := src/main/cpp/test.cpp

LOCAL_LDLIBS    += -lm -llog -ljnigraphics
include $(BUILD_SHARED_LIBRARY)

如何在cmake中设置这些东西

how to set these things in cmake

推荐答案

为时已晚,但有人可能会发现它有用. 首先,将opencv 2的libopencv_java.so或oepncv3的libopencv_java3.so放置在不同体系结构下的app/src/main/jniLibs文件夹中,如果您还对ninifree文件夹也输入linonfree.so.将cmake链接到gradle中.
这是CmakeLists.

It is too late but someone may find it useful. First place the libopencv_java.so for opencv 2 or libopencv_java3.so for oepncv3 in the app/src/main/jniLibs folder under different architecture add if you have also linonfree.so to the jniLibs folder. Link the cmake into gradle.
Here is the CmakeLists.

    cmake_minimum_required(VERSION 3.4.1)
       set(EXECUTABLE_OUTPUT_PATH      "${CMAKE_CURRENT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}")
    add_library( # Sets the name of the library.
                 native-lib

                 # Sets the library as a shared library.
                 SHARED

                 # Provides a relative path to your source file(s).
                 src/main/cpp/native-lib.cpp )
 #the nonfree optional if you have build the nonfree.so of the xfeature2d module    
add_library( # Sets the name of the library 
             nonfree
             # Sets the library as shared library.
             SHARED
             # indicate the library is prebuilt.
             IMPORTED )
set_target_properties( # Specifies the targeted library.
                         nonfree
                       # Specifies the parameter you want to define.
                          PROPERTIES IMPORTED_LOCATION
                        # Specifies the location of the library.
                         ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libnonfree.so )
    include_directories(C:/Users/what/Documents/OpenCV-android-sdk/sdk/native/jni/include)
    add_library( lib-opencv SHARED IMPORTED )
    set_target_properties(lib-opencv PROPERTIES IMPORTED_LOCATION  ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libopencv_java3.so)
    find_library( # Sets the name of the path variable.
                  log-lib

                  # Specifies the name of the NDK library that
                  # you want CMake to locate.
                  log )
    target_link_libraries( # Specifies the target library.
                           native-lib
                           # prebuilt library nonfree.
                           nonfree
                           # prebuilt library opencv java.
                           lib-opencv
                           # Links the target library to the log library
                           # included in the NDK.
                           ${log-lib} )

在build.gradle(app)中设置jniLis.srcDirs文件夹路径.

Set the jniLis.srcDirs folder path in build.gradle(app).

sourceSets {
    main {
        // let gradle pack the shared library into apk
        jniLibs.srcDirs = ['src/main/jniLibs']
    }
    }

这篇关于在cmakelists.txt android中添加opencv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆