user1590438
user1590438

Reputation:

OpenCV opencv2/core/core.hpp: No such file or directory

I'm creating a small project to test the opencv (2.4) on Android Studio 1.4 but when I try execute the app I have one problem with the NDK compiler. I think that the cpp files can't find the path to opencv but I dont know why.

Any ideia how to fix this problem??

Error:

/home/User/AndroidStudioProjects/OpenCV/app/src/main/jni/native_processing.h Error:(10, 33) opencv2/core/core.hpp: No such file or directory

JNI:

OpenCV/app/src/main/jni/native_processing.cpp

OpenCV/app/src/main/jni/native_processing.h

#ifndef OPENCV_SAMPLE_NATIVE_PROCESSING_H
#define OPENCV_SAMPLE_NATIVE_PROCESSING_H

#include <jni.h>

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <vector>

extern "C" {
JNIEXPORT void JNICALL      Java_com_projeto_opencv_MainActivity_FindFeatures(JNIEnv *, jobject,
                                                                                 jlong addrGray,
                                                                                 jlong addrRgba);
 }
 #endif

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
OPENCV_LIB_TYPE:=STATIC


PENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
OPENCV_LIB_TYPE:=SHARED
include /home/User/AndroidStudioProjects/OpenCV/OpenCV-android-sdk2/sdk/native/jni/OpenCV.mk

LOCAL_C_INCLUDE :=/home/User/Download/OpenCV-android-sdk2/sdk/native/jni/include
LOCAL_SRC_FILES := native_processing.cpp
LOCAL_LDLIBS +=  -llog -ldl
LOCAL_MODULE:= native_test


include $(BUILD_SHARED_LIBRARY)

 

Error: Warning:Native C/C++ source code is found, but it seems that
NDK option is not configured.  Note that if you have an Android.mk, it is
not used for compilation.  The recommended workaround is to remove the
default jni source code directory by adding:

 android {
    sourceSets {
        main {
            jni.srcDirs = []
        }
    }
}    

to build.gradle, manually compile the code with ndk-build, and then
place the resulting shared object in src/main/jniLibs.
/home/User/AndroidStudioProjects/OpenCV/app/src/main/jni/native_processing.cpp
Information:(1) (Unknown) In file included
/home/User/AndroidStudioProjects/OpenCV/app/src/main/jni/native_processing.h
Error:(10, 33) opencv2/core/core.hpp: No such file or directory
compilation terminated.
make: ***
 [/home/User/AndroidStudioProjects/OpenCV/app/build/intermediates/ndk/debug/obj/local/arm64-v8a/objs/app//home/geison/AndroidStudioProjects/OpenCV/app/src/main/jni/native_processing.o] Error 1
:app:compileDebugNdk FAILED
Error:Execution failed for task ':app:compileDebugNdk'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/home/User/Android/Sdk/ndk-bundle/ndk-build'' finished with non-zero exit value 2

Upvotes: 3

Views: 11239

Answers (3)

M. Usman Khan
M. Usman Khan

Reputation: 4408

comment out the following from build.gradle (if it is there):

externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }

Add this to gradle:

sourceSets.main {
    jni.srcDirs = [] //disable automatic ndk-build call
}

Upvotes: 3

Alex Cohn
Alex Cohn

Reputation: 57173

The included OpenCV.mk defines the include paths for you, so don't try to redefine it again after Include. Also, you probably prefer OPENCV_LIB_TYPE:=STATIC, so cleanup the Android.mk file a bit:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
OPENCV_CAMERA_MODULES:=on
OPENCV_LIB_TYPE:=STATIC
include /home/User/AndroidStudioProjects/OpenCV/OpenCV-android-sdk2/sdk/native/jni/OpenCV.mk

LOCAL_SRC_FILES := native_processing.cpp
LOCAL_LDLIBS +=  -llog -ldl
LOCAL_MODULE:= native_test

include $(BUILD_SHARED_LIBRARY)

Do you really use the camera modules?

Upvotes: 0

bdanos
bdanos

Reputation: 141

Have you tried only #include <opencv2/core.hpp> (instead of #include <opencv2/core/core.hpp>)? That worked for me (ubuntu 14.04 and opencv 2.4).

Upvotes: 2

Related Questions