在MacO上使用OpenCl进行Android编译的项目

时间:2019-05-05 09:55:32

标签: android opencv android-ndk opencl

我试图在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 stringvectorextension中的解析。

CLprocessor.cpp被发现here

我做了什么

  1. 我使用了本教程的代码(找到here
  2. 我下载了here找到的OpenCl的标题
  3. 我下载了cl.hpp here
  4. 我更新了CMakelist.txt

CMakeList

在我的CMakelist.txt中,将路径添加到了

  • OpenCV
  • OpenCL标头和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项目上运行,但是我找不到任何信息。

有人可以帮我正确地完成这项工作吗?

注释

OpenCv

我正在使用适用于Android的OpenCv4.1.0,发现here OpenCV作为模块添加到我的Android项目中。 OpenCV给出的以下代码有效:

Gradle

我不熟悉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代码一样有效。

0 个答案:

没有答案