Ask Your Question

BenT's profile - activity

2020-03-07 21:55:00 -0600 received badge  Popular Question (source)
2015-11-07 09:44:15 -0600 commented question Using Contrib modules with OpenCV4Android (OpenCV3.0.0)

Hi, did you manage to include the contrib module? If yes, how? I already built the SDK using the script and all the .a files are generated fine, but how can I use them in my project?

2015-10-29 03:23:44 -0600 received badge  Enthusiast
2015-10-26 06:53:56 -0600 answered a question Trouble setting up NDK build

important note to self: always put the Android.mk file in the right folder. I put the file in the subdirectory UVCCamera where the code that uses opencv is and it is working now. Includes are fine and I can use opencv on ndk level finally!

2015-10-26 04:01:27 -0600 commented question Trouble setting up NDK build

Hi. I used the latest version. Actually I solved this yesterday evening, but I am not allowed to post my answer for another few hours since I am new to the forum. The error was that I had the include in the wrong Android.mk file, it was supposed to be in the subdirectory UVCCamera, where the source file that uses opencv is.

2015-10-24 07:00:25 -0600 asked a question Trouble setting up NDK build

Hi, I would like to use OpenCV in the NDK Part of my Android Project, but I can't get it to compile properly. I am using Android Studio and did the following steps: encouraged gradle to not generate a makefile, but to use mine instead:


apply plugin: 'com.android.library'
import org.apache.tools.ant.taskdefs.condition.Os

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 22
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    sourceSets {
        main {
            jniLibs.srcDir 'src/main/libs'
            jni.srcDirs = []
        }
    }
}

dependencies {
    compile fileTree(dir: new File(buildDir, 'libs'), include: '*.jar')
}

tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn ndkBuild
}

task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
    println('executing ndkBuild')
    def ndkBuildingDir = project.plugins.findPlugin('com.android.library').sdkHandler.getNdkFolder().absolutePath
    def ndkBuildPath = ndkBuildingDir
    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
        ndkBuildPath = ndkBuildingDir + '/ndk-build.cmd'
    } else {
        ndkBuildPath = ndkBuildingDir + '/ndk-build'
    }
    commandLine ndkBuildPath, '-j8', '-C', file('src/main').absolutePath
}

Then I set up my Android.mk file like this:
PROJ_PATH   := $(call my-dir)
LOCAL_PATH  := $PROJ_PATH

include $(CLEAR_VARS)

include $(PROJ_PATH)/other_libs

OPENCV_DIR:=$(PROJ_PATH)/../../../../../OpenCV-android-sdk


OPENCV_INSTALL_MODULES:=off
OPENCV_CAMERA_MODULES:=off
OPENCV_LIB_TYPE:=LOCAL_SHARED
include $(OPENCV_DIR)/sdk/native/jni/OpenCV.mk

LOCAL_SRC_FILES := UVCCamera/UVCPreview.cpp
LOCAL_MODULE     := libuvccamera
LOCAL_C_INCLUDES += $(OPENCV_DIR)/sdk/native/jni/include/
LOCAL_C_INCLUDES += $(LOCAL_PATH)
LOCAL_LDLIBS     += -llog -ldl

include $(BUILD_SHARED_LIBRARY)
I am unsure on how to set LOCAL_SRC_FILES and LOCAL_C_INCLUDES. UVCCamera/UVCPreview.cpp includes opencv headers and the opencv include directory is stored in $(OPENCV_DIR)/sdk/native/jni/include/

Is this setup ok?

The problem I am having is that the ndk builder cant find the opencv header files, and I get an error:
jni/UVCCamera/UVCPreview.cpp:3:33: fatal error: opencv2/core/core.hpp: No such file or directory
[armeabi-v7a] Install        : libusb100.so => libs/armeabi-v7a/libusb100.so
make: *** No rule to make target `jni/libuvc/android/jni/../../UVCCamera/UVCPreview.cpp', needed by `obj/local/armeabi-v7a/objs/uvccamera/UVCCamera/UVCPreview.o'.  Stop.
compilation terminated.
make: *** [obj/local/armeabi-v7a/objs/UVCCamera/UVCPreview.o] Error 1
[armeabi-v7a] Compile arm    : uvc_static <= stream.c
                                 ^
 #include <opencv2 core="" core.hpp="">
make: *** Waiting for unfinished jobs....

The "No rule to make target" disappears if I leave the LOCAL_SRC_FILES empty, but the builder still cant find the opencv headers.

Can anybody find an error in my setup?


The Application.mk is basically the same as in the sample projects.


APP_PLATFORM := android-14
APP_ABI := armeabi-v7a
APP_OPTIM := release
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions

Thank you!