5

how can i use openCV in an android studio's project - but i need to use it in other native cpp files and not in java.

all the guides and tutorials i found explain how to use openCV in java files (loadLibrary..) for example this and this

eventually i have all the .so in jniLibs folder or add openCV as a module with a dependency, but what do i "#include .. " ? how can i not get

error: 'cv' is not a namespace-name

for

using namespace cv;

? (and of course other openCV code...)

thanks a lot!

1 Answer 1

5

finally i succeeded:

i created my own android.mk file:

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


# OpenCV
OPENCV_INSTALL_MODULES:=on

include path/to/OpenCV-2.4.10-android-sdk/sdk/native/jni/OpenCV.mk


LOCAL_MODULE := glucomesdk
LOCAL_CFLAGS := -I/path tp/OpenCV-2.4.10-android-sdk/sdk/native/jni/include -Wall -Werror 
LOCAL_SRC_FILES := \ all my cpp files

LOCAL_C_INCLUDES += /path to/src/main/jni
LOCAL_C_INCLUDES += /path to/src/debug/jni
LOCAL_C_INCLUDES += /path to/OpenCV-2.4.10-android-sdk/sdk/native/jni/include

LOCAL_STATIC_LIBRARIES := /path to/OpenCV-2.4.10-android-sdk/sdk/native/libs/armeabi-v7a/libopencv_core.a

LOCAL_LDLIBS += -llog -ldl

include $(BUILD_SHARED_LIBRARY)

then i use this code in terminal to build the shared library (.so)

/path/to/android-ndk/ndk-build NDK_PROJECT_PATH=/path/to/project APP_BUILD_SCRIPT=/path/to/Android.mk NDK_OUT=/path/to/project/module/build/intermediates/ndk/debug/obj NDK_LIBS_OUT=/path/to/project/module/build/intermediates/ndk/debug/lib APP_STL=stlport_static APP_ABI=armeabi-v7a

after that i use gradle's assemble(debug) to create an aar file that contains both java code and the shared library

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.