Using OpenCV nonfree module in Android

坚强是说给别人听的谎言 提交于 2019-12-24 08:41:05

问题


I'm trying to use the nonfree module with OpenCV on Android. I'm following this answer https://stackoverflow.com/a/28557686/6126070 but I'm having trouble understanding it since this is my first application using Android and NDK.

Right now, OpenCV (without nonfree) is working on my application and I'm using it in C++ code with NDK and JNI. What I'm having trouble with is editing my current Android.mk and Application.mk files to thoses in the answer to compile nonfree.

Here is my Android.mk and Application.mk files with the structure of my project.

Android.mk :

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

#opencv
OPENCVROOT:= C:\OpenCV-2.4.10-android-sdk
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
OPENCV_LIB_TYPE:=SHARED
include ${OPENCVROOT}/sdk/native/jni/OpenCV.mk

LOCAL_SRC_FILES := com_example_adrien_ndkopencvtest4_OpencvNativeClass.cpp


LOCAL_LDLIBS += -llog
LOCAL_MODULE := MyOpencvLibs 


include $(BUILD_SHARED_LIBRARY)

Application.mk :

APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-16

Project structure :

My project crashes with the line #include <opencv2/nonfree/nonfree.hpp> in my jni .h file so that's why I'm trying to import nonfree module.

So as I said, I'm trying to implement the answer linked above but I'm having trouble.

In the answer :

Building the nonfree module :

Step 1 : I'm copying the files just fine.

Step 2 : I don't understand where I'm supposed to create this folder, in my application or in my computer ?

Step 3 : Here is the big problem, I don't know how I can merge the Android.mk and Application.mk files provided in the answer with mine. Furthermore, I don't understand the line "cd into the project folder libnonfree and type ndk-build to build the libnonfree.so."

For the "Building a sample appliaction" I haven't been to this part yet but I supposed I don't need to do it I can just keep using OpenCV with my application except the #include <opencv2/nonfree/nonfree.hpp> line will work.

I tried to make this question clear, if you need more information I will gladly edit it.


回答1:


Step2: Create folder under your jniLibs file or put 4 file directly.

Step3:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

#opencv
OPENCVROOT:= C:\OpenCV-2.4.10-android-sdk
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
OPENCV_LIB_TYPE:=SHARED
include ${OPENCVROOT}/sdk/native/jni/OpenCV.mk

LOCAL_SRC_FILES := com_example_adrien_ndkopencvtest4_OpencvNativeClass.cpp


LOCAL_LDLIBS += -llog
LOCAL_MODULE := MyOpencvLibs 


include $(BUILD_SHARED_LIBRARY)


include $(CLEAR_VARS)

LOCAL_C_INCLUDES:= ${OPENCVROOT}/sdk/native/jni/include
LOCAL_MODULE    := nonfree
LOCAL_CFLAGS    := -Werror -O3 -ffast-math
LOCAL_LDLIBS    += -llog

# for 2.4.8, delete the line precomp.cpp \
LOCAL_SRC_FILES := nonfree_init.cpp \
sift.cpp \
surf.cpp
include $(BUILD_SHARED_LIBRARY)

and you can search how to add External tool in android studio (ndk-build)



来源:https://stackoverflow.com/questions/44212588/using-opencv-nonfree-module-in-android

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