OpenCV opencv2 / core / core.hpp:没有这样的文件或目录

时间:2015-10-20 15:49:51

标签: android c++ opencv java-native-interface

我正在创建一个小项目来测试Android Studio 1.4上的opencv(2.4),但是当我尝试执行app时,我遇到了NDK编译器的一个问题。我认为cpp文件找不到opencv的路径,但我不知道为什么。

任何ideia如何解决这个问题??

错误:

/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 /应用/ SRC /主/ JNI / native_processing.cpp

的OpenCV /应用/ SRC /主/ 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

3 个答案:

答案 0 :(得分:3)

从build.gradle中注释掉以下内容(如果它在那里):

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

将此添加到gradle:

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

答案 1 :(得分:2)

您是否仅尝试#include <opencv2/core.hpp>(而不是#include <opencv2/core/core.hpp>)? 这对我有用(ubuntu 14.04和opencv 2.4)。

答案 2 :(得分:0)

包含的 OpenCV.mk 为您定义了包含路径,因此请勿在包含后再次尝试重新定义。此外,您可能更喜欢OPENCV_LIB_TYPE:=STATIC,因此请稍微清理 Android.mk 文件:

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)

你真的使用相机模块吗?