I want to create an Android app which uses BOW + SVM in native (using C++) for predicting. Unfortunately I have problem with building the native part. Since the non-free module is not included in the OpenCV SDK for Android, I need to build the module myself, using this tutorial. It seems I built the .so file successfully. Here is the output:
[armeabi-v7a] Prebuilt : libopencv_java.so <= /home/crash-id/Development/SDK/OpenCV-2.4.9-android-sdk/sdk/native/jni/../libs/armeabi-v7a/
[armeabi-v7a] SharedLibrary : libnonfree.so
[armeabi-v7a] Install : libnonfree.so => libs/armeabi-v7a/libnonfree.so
[armeabi-v7a] Install : libopencv_java.so => libs/armeabi-v7a/libopencv_java.so
So the problem comes here, when I have to add this .so file to my project. I added libnonfree.so to my jni folder. Then I edited the Android.mk. Here I provide my .mk files.
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := nonfree_prebuilt
LOCAL_SRC_FILES := libnonfree.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
OPENCV_CAMERA_MODULES := on
OPENCV_INSTALL_MODULES := on
include /home/crash-id/Development/SDK/OpenCV-2.4.9-android-sdk/sdk/native/jni/OpenCV.mk
#LOCAL_SHARED_LIBRARIES := nonfree_prebuilt #if I add this, it says undefined reference for everything in the cv namespace.
LOCAL_SRC_FILES := SVMDetector.cpp
LOCAL_MODULE := svm_detector
LOCAL_C_INCLUDES += /home/crash-id/Development/SDK/OpenCV-2.4.9-android-sdk/sdk/native/jni/include
LOCAL_CFLAGS := -Werror -O3 -ffast-math
LOCAL_LDLIBS += -llog -ldl
include $(BUILD_SHARED_LIBRARY)
Application.mk
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-15
But this doesn't work. When I try to build the app, I get the following error:
./obj/local/armeabi-v7a/objs/svm_detector/SVMDetector.o: in function Java_org_elsys_thesisdiploma_cammect_FrameProcess_SVMDetect:jni/SVMDetector.cpp:23: error: undefined reference to 'cv::initModule_nonfree()'
When I click right button on initModule_nonfree();
, Eclipse opens the nonfree.hpp file and here are it's contents:
#ifndef __OPENCV_NONFREE_HPP__
#define __OPENCV_NONFREE_HPP__
#include "opencv2/nonfree/features2d.hpp"
namespace cv
{
CV_EXPORTS_W bool initModule_nonfree();
}
#endif
But I'm not sure the linker knows where is the implementation of this method. Since it gives an error, it doesn't.
EDIT
If I add LOCAL_ALLOW_UNDEFINED_SYMBOLS := true
, the project compiles successfully but it causes run time error:
02-17 00:15:58.197: E/AndroidRuntime(8793): FATAL EXCEPTION: main
02-17 00:15:58.197: E/AndroidRuntime(8793): Process: com.example.cammect, PID: 8793
02-17 00:15:58.197: E/AndroidRuntime(8793): java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_ZN2cv18initModule_nonfreeEv" referenced by "libsvm_detector.so"...
Do you know what am I doing wrong? Thanks in advance!
test_sift.cpp
) with theAndroid.mk
attached in the zip file? – ShirkerLOCAL_SHARED_LIBRARIES
. – Shirker