Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use opencv in android studio in native c++ code

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!

like image 604
dowi Avatar asked Jan 13 '15 17:01

dowi


People also ask

Can OpenCV be used in Android Studio?

To work with the OpenCV Android library, you have to add it to your app module as a dependency. To easily do this on Android Studio, click on File -> Project Structure. When the project structure dialog opens, click on the app module or any other module that you want to use OpenCV library in.

What is OpenCV library in Android?

Basically OpenCV is an open source computer vision and machine learning software library. Based on the documentation this library has more than 2500 optimized algorithm inside of it.

How do I use OpenCV on my phone?

Download and install IP Webcam application on your mobile phone. Then make sure your PC and Phone both are connected to the same network. Open your IP Webcam application on your both, click “Start Server” (usually found at the bottom). This will open a camera on your Phone.


1 Answers

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

like image 126
dowi Avatar answered Sep 23 '22 03:09

dowi