2

I want to use some native c++ code/library in my Android application. The c++ part is heavily based on openCV.

I am aware of opencv-android-sdk and have seen plenty of detailed tutorials on how to do it with Android Studio (like this one), but these all just use the opencv-android-sdk that only supports a limited subset of openCV functions (I am not talking about those that do not make sense on a mobile device, like gpu-related functionalities, but some other functions that simply do not exist in the opencv-android-sdk and I need them for the c++ code).

Anyway, my question is: can I somehow compile and use the "full set of modules" of openCV in my Android Studio project (using NDK, etc.)?

I saw also this one, and it claims that "[it] will build most of the OpenCV modules [for android]", but it is not clear to me how to use it...

Any hint would be highly appreciated!

0

2 Answers 2

1

OK! I guess I figured it out! Basically one needs to follow this tutorial, but just replace the path in Android.mk to point to the compiled full version of openCV, instead of openCV-Android-SDK (as well as some other small changes; for those I just copy here what I have in Android.mk and Application.mk).

Eventually, my Android.mk looks like this (OPENCVROOT need to be set properly):

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
OPENCVROOT:= /path/to/opencv-2.4.10/platforms/build_android_arm
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
OPENCV_LIB_TYPE:=SHARED
include ${OPENCVROOT}/OpenCV.mk
LOCAL_SRC_FILES := main.cpp
LOCAL_LDLIBS += -llog
LOCAL_MODULE := hello
include $(BUILD_SHARED_LIBRARY)

And Application.mk looks like this:

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

Just a short note on compiling openCV with Android NDK:

For compiling full openCV using NDK, one can still use the method mentioned here; the description is based on NDK-r8e, but if needed, one can download NDK-r10d and use it instead. I had to turn-off cuda-related parts in openCV source, in order to successfully compile it with NDK (just adding -D WITH_CUDA=OFF to opencv-2.4.10/platforms/scripts/cmake_android_arm.sh , in the last line, after cmake, does the job!). In case you need to have the nonfree modules (like SURF and SIFT, do NOT clone it from github, just download it in a single zip from here; I used version 2.4.10 by the way).

Now I have access to almost all openCV functions in the native c++ code that I am integrating into my Android App!

I hope this helps others, too!

Sign up to request clarification or add additional context in comments.

Comments

0

You should investigate JNI (The Java Native Interface) which is a means of wrapping C libraries with Java.

Also you may want to consider getting hold of this book: Mastering OpenCV with Practical Computer Vision Projects

Which goes into this in some detail.

2 Comments

Thanks for the reply! I actually don't have any problems with integrating, compiling and running my c++ native code into an Android app as long as it is solely dependent on opencv-android-sdk; the problems arise when I want to use opencv with some extra modules and not the SDK. (the book by the way is great! Thanks; but it still lacks what I need)
This does not answer the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.