我试图在MacOs Mojave的AndroidStudio 3.4中集成示例 Use OpenCL in Android camera preview based CV application 。
我以找不到标准库的类的错误结尾:
cl.hpp
文件atomic
中找不到In file included from <project_path>/app/src/main/cpp/CLprocessor.cpp:7:
<opencl_lib_path>/CL/cl.hpp:176:10: fatal error: 'atomic' file not found
#include <atomic>
^~~~~~~~
1 warning and 1 error generated.
CLprocessor.cpp
string
,vector
和extension
中的解析。 CLprocessor.cpp
被发现here
在我的CMakelist.txt
中,将路径添加到了
cl.hpp
文件我在缩小类型方面也遇到了问题,我通过添加set(CMAKE_CXX_FLAGS "-Wc++11-narrowing")
最后,我的CmakeLists
如下:
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.6)
# Enable C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(target mixed_sample)
project(${target} CXX)
# Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
# "OpenCV_DIR" to a directory containing one of the above files. If "OpenCV"
# provides a separate development package or SDK, be sure it has been
# installed.
set(OpenCV_DIR "<path_to_lib>/OpenCV-android-sdk/sdk/native/jni/")
message(STATUS "+++ OpenCV_DIR: " ${OpenCV_DIR})
# OpenCl
set(OpenCL_HEADER_CL "<path_to_lib>/OpenCL-Headers-master")
message(STATUS "+++ OpenCL_HEADER: " ${OpenCL_HEADER_CL})
include_directories( ${OpenCL_HEADER_CL} )
set(ANDROID_OPENCV_COMPONENTS "opencv_java" CACHE STRING "")
message(STATUS "ANDROID_ABI=${ANDROID_ABI}")
find_package(OpenCV REQUIRED COMPONENTS ${ANDROID_OPENCV_COMPONENTS})
file(GLOB srcs *.cpp *.c)
file(GLOB hdrs *.hpp *.h)
# fix error: non-constant-expression cannot be narrowed from type 'int' to 'size_t' (aka 'unsigned long') in initializer list [-Wc++11-narrowing]
set(CMAKE_CXX_FLAGS "-Wc++11-narrowing")
include_directories("${CMAKE_CURRENT_LIST_DIR}")
add_library(${target} SHARED ${srcs} ${hdrs})
target_link_libraries(${target} ${ANDROID_OPENCV_COMPONENTS} -lGLESv2 -lEGL -lOpenCL)
我觉得问题不仅仅在于找不到一些库,还在于问题更深,因此我搜索了如何使OpenCl在MacOs上的Android项目上运行,但是我找不到任何信息。
有人可以帮我正确地完成这项工作吗?
我正在使用适用于Android的OpenCv4.1.0,发现here OpenCV作为模块添加到我的Android项目中。 OpenCV给出的以下代码有效:
我不熟悉OpenCV和OpenCL问题,所以我不知道它是否相关,但是我的build.gradle
是:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.aklal.andropencpp"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-std=c++11 -frtti -fexceptions"
arguments "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni" // , "-DANDROID_ARM_NEON=TRUE"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version "3.10.2"
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation project(':opencv410')
}
所有cpp代码和CMakeList.txt
都位于/src/main/cpp
下,而不是jni
文件夹中,如在OpenCv给出的代码中一样。这种使用cpp文件的方式与我尝试使用cpp文件的其他OpenCv代码一样有效。