Created
June 9, 2019 02:47
-
-
Save astarasikov/9088745a49401fced5f1a3503b07e593 to your computer and use it in GitHub Desktop.
compiling OpenCV for Android with OpenCL support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 5f17f284266fcc3d78d28c08f20b0bbb71584ae2 | |
Author: Alexander Tarasikov <[email protected]> | |
Date: Sun Feb 19 01:16:54 2017 +0100 | |
OpenCL Hacks | |
diff --git a/CMakeLists.txt b/CMakeLists.txt | |
index 71b4b3608..223f75f95 100644 | |
--- a/CMakeLists.txt | |
+++ b/CMakeLists.txt | |
@@ -221,7 +221,7 @@ OCV_OPTION(WITH_MSMF "Build VideoIO with Media Foundation support" OFF | |
OCV_OPTION(WITH_XIMEA "Include XIMEA cameras support" OFF IF (NOT ANDROID AND NOT WINRT) ) | |
OCV_OPTION(WITH_XINE "Include Xine support (GPL)" OFF IF (UNIX AND NOT APPLE AND NOT ANDROID) ) | |
OCV_OPTION(WITH_CLP "Include Clp support (EPL)" OFF) | |
-OCV_OPTION(WITH_OPENCL "Include OpenCL Runtime support" NOT ANDROID IF (NOT IOS AND NOT WINRT) ) | |
+OCV_OPTION(WITH_OPENCL "Include OpenCL Runtime support" (NOT IOS AND NOT WINRT) ) | |
OCV_OPTION(WITH_OPENCL_SVM "Include OpenCL Shared Virtual Memory support" OFF ) # experimental | |
OCV_OPTION(WITH_OPENCLAMDFFT "Include AMD OpenCL FFT library support" ON IF (NOT ANDROID AND NOT IOS AND NOT WINRT) ) | |
OCV_OPTION(WITH_OPENCLAMDBLAS "Include AMD OpenCL BLAS library support" ON IF (NOT ANDROID AND NOT IOS AND NOT WINRT) ) | |
diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake | |
index 5bb047911..89c5f1596 100644 | |
--- a/cmake/OpenCVCompilerOptions.cmake | |
+++ b/cmake/OpenCVCompilerOptions.cmake | |
@@ -116,21 +116,21 @@ if(CMAKE_COMPILER_IS_GNUCXX) | |
add_extra_compiler_option(-Wformat) | |
add_extra_compiler_option(-Werror=format-security -Wformat) | |
add_extra_compiler_option(-Wmissing-declarations) | |
- add_extra_compiler_option(-Wmissing-prototypes) | |
- add_extra_compiler_option(-Wstrict-prototypes) | |
+ #add_extra_compiler_option(-Wmissing-prototypes) | |
+ #add_extra_compiler_option(-Wstrict-prototypes) | |
add_extra_compiler_option(-Wundef) | |
add_extra_compiler_option(-Winit-self) | |
add_extra_compiler_option(-Wpointer-arith) | |
add_extra_compiler_option(-Wshadow) | |
- add_extra_compiler_option(-Wsign-promo) | |
+ #add_extra_compiler_option(-Wsign-promo) | |
if(ENABLE_NOISY_WARNINGS) | |
add_extra_compiler_option(-Wcast-align) | |
add_extra_compiler_option(-Wstrict-aliasing=2) | |
else() | |
add_extra_compiler_option(-Wno-narrowing) | |
- add_extra_compiler_option(-Wno-delete-non-virtual-dtor) | |
- add_extra_compiler_option(-Wno-unnamed-type-template-args) | |
+ #add_extra_compiler_option(-Wno-delete-non-virtual-dtor) | |
+ #add_extra_compiler_option(-Wno-unnamed-type-template-args) | |
add_extra_compiler_option(-Wno-comment) | |
endif() | |
add_extra_compiler_option(-fdiagnostics-show-option) | |
@@ -367,7 +367,7 @@ set(OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG "${OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG | |
# set default visibility to hidden | |
if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_OPENCV_GCC_VERSION_NUM GREATER 399) | |
add_extra_compiler_option(-fvisibility=hidden) | |
- add_extra_compiler_option(-fvisibility-inlines-hidden) | |
+ #add_extra_compiler_option(-fvisibility-inlines-hidden) | |
endif() | |
if(NOT OPENCV_FP16_DISABLE AND NOT IOS) | |
diff --git a/modules/core/include/opencv2/core/ocl.hpp b/modules/core/include/opencv2/core/ocl.hpp | |
index 1a9549df4..86c0e9ca5 100644 | |
--- a/modules/core/include/opencv2/core/ocl.hpp | |
+++ b/modules/core/include/opencv2/core/ocl.hpp | |
@@ -329,7 +329,7 @@ CV_EXPORTS void convertFromBuffer(void* cl_mem_buffer, size_t step, int rows, in | |
CV_EXPORTS void convertFromImage(void* cl_mem_image, UMat& dst); | |
// TODO Move to internal header | |
-void initializeContextFromHandle(Context& ctx, void* platform, void* context, void* device); | |
+CV_EXPORTS void initializeContextFromHandle(Context& ctx, void* platform, void* context, void* device); | |
class CV_EXPORTS Queue | |
{ | |
diff --git a/modules/core/src/ocl.cpp b/modules/core/src/ocl.cpp | |
index 33bed26c8..52feafead 100644 | |
--- a/modules/core/src/ocl.cpp | |
+++ b/modules/core/src/ocl.cpp | |
@@ -49,6 +49,11 @@ | |
#include <inttypes.h> | |
#endif | |
+#include <android/log.h> | |
+#define DPRINT(fmt, args...) do { \ | |
+ __android_log_print(ANDROID_LOG_ERROR, "OPENCV OPENCL", fmt, ##args); \ | |
+} while (0) | |
+ | |
#define CV_OPENCL_ALWAYS_SHOW_BUILD_LOG 0 | |
#define CV_OPENCL_SHOW_RUN_ERRORS 0 | |
#define CV_OPENCL_SHOW_SVM_ERROR_LOG 1 | |
@@ -1460,7 +1465,7 @@ inline bool operator < (const HashKey& h1, const HashKey& h2) | |
bool haveOpenCL() | |
{ | |
-#ifdef HAVE_OPENCL | |
+#if 1//def HAVE_OPENCL | |
static bool g_isOpenCLInitialized = false; | |
static bool g_isOpenCLAvailable = false; | |
@@ -1470,11 +1475,14 @@ bool haveOpenCL() | |
{ | |
cl_uint n = 0; | |
g_isOpenCLAvailable = ::clGetPlatformIDs(0, NULL, &n) == CL_SUCCESS; | |
+ DPRINT("%s: %d g_isOpenCLAvailable=%d n=%d\n", __func__, __LINE__, g_isOpenCLAvailable, n); | |
} | |
catch (...) | |
{ | |
+ DPRINT("%s: %d g_isOpenCLAvailable=%d\n", __func__, __LINE__, g_isOpenCLAvailable); | |
g_isOpenCLAvailable = false; | |
} | |
+ DPRINT("%s: %d g_isOpenCLAvailable=%d\n", __func__, __LINE__, g_isOpenCLAvailable); | |
g_isOpenCLInitialized = true; | |
} | |
return g_isOpenCLAvailable; | |
@@ -1497,6 +1505,7 @@ bool useOpenCL() | |
data->useOpenCL = 0; | |
} | |
} | |
+ DPRINT("%s: %d data->useOpenCL=%d\n", __func__, __LINE__, data->useOpenCL); | |
return data->useOpenCL > 0; | |
} | |
@@ -1715,6 +1724,7 @@ struct Platform::Impl | |
initialized = true; | |
} | |
+ DPRINT("%s: %d initialized=%d\n", __func__, __LINE__, initialized); | |
} | |
IMPLEMENT_REFCOUNTABLE(); | |
@@ -2517,6 +2527,8 @@ struct Context::Impl | |
} | |
else | |
handle = NULL; | |
+ | |
+ DPRINT("%s: %d handle=%p\n", __func__, __LINE__, handle); | |
} | |
Impl(int dtype0) | |
@@ -2556,6 +2568,7 @@ struct Context::Impl | |
name0 = name; | |
dlist_new[nd++] = dlist[i]; | |
} | |
+ DPRINT("%s: %d nd=%p\n", __func__, __LINE__, nd); | |
if(nd == 0) | |
return; | |
@@ -2779,6 +2792,7 @@ bool Context::create() | |
delete p; | |
p = 0; | |
} | |
+ DPRINT("%s: %d p=%p handle=%p\n", __func__, __LINE__, p, (p ? (p->handle) : NULL)); | |
return p != 0; | |
} | |
@@ -2794,6 +2808,7 @@ bool Context::create(int dtype0) | |
delete p; | |
p = 0; | |
} | |
+ DPRINT("%s: %d p=%p handle=%p\n", __func__, __LINE__, p, (p ? (p->handle) : NULL)); | |
return p != 0; | |
} | |
@@ -2856,6 +2871,7 @@ Context& Context::getDefault(bool initialize) | |
if (ctx->p->handle == NULL) | |
ctx->p->setDefault(); | |
} | |
+ DPRINT("%s: %d p=%p handle=%p\n", __func__, __LINE__, ctx->p, (ctx->p ? (ctx->p->handle) : NULL)); | |
} | |
return *ctx; | |
@@ -2956,6 +2972,8 @@ void attachContext(const String& platformName, void* platformID, void* context, | |
{ | |
cl_uint cnt = 0; | |
+if (false) { | |
+ | |
if(CL_SUCCESS != clGetPlatformIDs(0, 0, &cnt)) | |
CV_ErrorNoReturn(cv::Error::OpenCLApiCallError, "clGetPlatformIDs failed!"); | |
@@ -2991,6 +3009,8 @@ void attachContext(const String& platformName, void* platformID, void* context, | |
if (platformName != actualPlatformName) | |
CV_ErrorNoReturn(cv::Error::OpenCLApiCallError, "No matched platforms available!"); | |
+} //if false | |
+ | |
// do not initialize OpenCL context | |
Context ctx = Context::getDefault(false); | |
@@ -3014,21 +3034,35 @@ void initializeContextFromHandle(Context& ctx, void* platform, void* _context, v | |
cl_context context = (cl_context)_context; | |
cl_device_id device = (cl_device_id)_device; | |
+ DPRINT("%s: %d haveOpenCL()=%d\n", __func__, __LINE__, haveOpenCL()); | |
+#ifndef HAVE_OPENCL | |
+ DPRINT("%s: HAVE_OPENCL not defined\n", __func__); | |
+#endif | |
// cleanup old context | |
Context::Impl * impl = ctx.p; | |
+ DPRINT("%s: %d impl=%p, handle=%p\n", __func__, __LINE__, impl, (impl ? (impl->handle) : NULL)); | |
+ | |
if (impl->handle) | |
{ | |
CV_OclDbgAssert(clReleaseContext(impl->handle) == CL_SUCCESS); | |
} | |
+ DPRINT("%s: %d\n", __func__, __LINE__); | |
impl->devices.clear(); | |
+ DPRINT("%s: %d\n", __func__, __LINE__); | |
impl->handle = context; | |
+ DPRINT("%s: %d\n", __func__, __LINE__); | |
impl->devices.resize(1); | |
+ DPRINT("%s: %d\n", __func__, __LINE__); | |
impl->devices[0].set(device); | |
+ DPRINT("%s: %d\n", __func__, __LINE__); | |
Platform& p = Platform::getDefault(); | |
+ DPRINT("%s: %d\n", __func__, __LINE__); | |
Platform::Impl* pImpl = p.p; | |
+ DPRINT("%s: %d\n", __func__, __LINE__); | |
pImpl->handle = (cl_platform_id)platform; | |
+ DPRINT("%s: %d\n", __func__, __LINE__); | |
} | |
/////////////////////////////////////////// Queue ///////////////////////////////////////////// | |
diff --git a/platforms/scripts/cmake_android_arm.sh b/platforms/scripts/cmake_android_arm.sh | |
index 84c88a815..463c0a745 100755 | |
--- a/platforms/scripts/cmake_android_arm.sh | |
+++ b/platforms/scripts/cmake_android_arm.sh | |
@@ -4,4 +4,14 @@ cd `dirname $0`/.. | |
mkdir -p build_android_arm | |
cd build_android_arm | |
-cmake -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON -DCMAKE_TOOLCHAIN_FILE=../android/android.toolchain.cmake $@ ../.. | |
+cmake \ | |
+ -DHAVE_C_WNO_MISLEADING_INDENTATION=NO \ | |
+ -DHAVE_CXX_WNO_MISLEADING_INDENTATION=NO \ | |
+ -DHAVE_CXX_WNO_UNUSED_CONST_VARIABLE=NO \ | |
+ -DCMAKE_POLICY_DEFAULT_CMP0045=OLD \ | |
+ -DCMAKE_POLICY_DEFAULT_CMP0040=OLD \ | |
+ -DANDROID_NATIVE_API_LEVEL=21 \ | |
+ -DANDROID_PLATFORM=android-21 \ | |
+ -DANDROID_OPENCL_SDK=${ANDROID_OPENCL_SDK} \ | |
+ -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \ | |
+ -DCMAKE_TOOLCHAIN_FILE=../android/android.toolchain.cmake $@ ../.. | |
diff --git a/samples/android/tutorial-4-opencl/CMakeLists.txt b/samples/android/tutorial-4-opencl/CMakeLists.txt | |
index e8036cfbd..bf7b75c69 100644 | |
--- a/samples/android/tutorial-4-opencl/CMakeLists.txt | |
+++ b/samples/android/tutorial-4-opencl/CMakeLists.txt | |
@@ -8,6 +8,12 @@ if(ANDROID_NATIVE_API_LEVEL LESS 14) | |
return() | |
endif() | |
+# | |
+# I couldn't get it to build with cmake, but we can build it with ant manually | |
+# but keep the previous checks so that we can see if OPENCL fails | |
+# | |
+return() | |
+ | |
if(BUILD_FAT_JAVA_LIB) | |
set(native_deps opencv_java) | |
else() | |
diff --git a/samples/android/tutorial-4-opencl/build_with_sdk.sh b/samples/android/tutorial-4-opencl/build_with_sdk.sh | |
new file mode 100755 | |
index 000000000..1b0b723dc | |
--- /dev/null | |
+++ b/samples/android/tutorial-4-opencl/build_with_sdk.sh | |
@@ -0,0 +1,55 @@ | |
+#!/bin/bash | |
+ | |
+# | |
+# Please also take a look at the following blog | |
+# http://yati-sagade.github.io/2014/11/02/opencv-android-setup/ | |
+# | |
+ | |
+set -e | |
+set -u | |
+ | |
+export OUR_ANDROID_WORKSPACE=${OUR_ANDROID_WORKSPACE:-/Users/alexander/Documents/workspace/bin/android} | |
+ | |
+export ANDROID_SDK_ROOT=${OUR_ANDROID_WORKSPACE}/android-sdk-macosx | |
+export ANDROID_NDK=${OUR_ANDROID_WORKSPACE}/android-ndk-r13b | |
+export PATH=${ANDROID_NDK}:${ANDROID_SDK_ROOT}/platform-tools:$PATH | |
+ | |
+export OPENCV_ANDROID_SDK=/Users/alexander/Documents/workspace/builds/android/opencv/platforms/build_android_arm | |
+export OPENCV_ANDROID_SDK_JAVA=${OPENCV_ANDROID_SDK}/sdk/java | |
+ | |
+export OPENCL_SDK=/Users/alexander/Documents/workspace/bin/android/adreno_opencl | |
+ | |
+export ANDROID_TARGET=android-24 | |
+ | |
+export OPENCV_ANDROID_SDK_JAVA=${OUR_ANDROID_WORKSPACE}/sdk/opencv/OpenCV-android-sdk/sdk/java | |
+ | |
+pushd . | |
+ cd ${OPENCV_ANDROID_SDK_JAVA} | |
+ android update lib-project --target ${ANDROID_TARGET} --path . | |
+ ant clean | |
+ ant debug | |
+popd | |
+ | |
+# | |
+# cleanup stage | |
+# | |
+rm local.properties | |
+rm project.properties | |
+ | |
+# | |
+# "android update project" appends the relative path to "project.properties" | |
+# there's no easy way to convert an absolute path to relative in bash | |
+# so create a symlink to the root of the file system | |
+# | |
+ | |
+[[ -e link_to_root ]] && rm link_to_root | |
+ln -s / link_to_root | |
+android update project --target ${ANDROID_TARGET} -p . | |
+android update project --path . --library link_to_root/${OPENCV_ANDROID_SDK_JAVA} | |
+ | |
+ndk-build clean | |
+ndk-build | |
+ | |
+ant clean | |
+ant debug | |
+ant installd | |
diff --git a/samples/android/tutorial-4-opencl/jni/Android.mk b/samples/android/tutorial-4-opencl/jni/Android.mk | |
index dacd0f665..28db80ee6 100644 | |
--- a/samples/android/tutorial-4-opencl/jni/Android.mk | |
+++ b/samples/android/tutorial-4-opencl/jni/Android.mk | |
@@ -1,7 +1,106 @@ | |
LOCAL_PATH := $(call my-dir) | |
+QCOM_PREBUILTS := | |
+ | |
+##add CB | |
+#include $(CLEAR_VARS) | |
+#LOCAL_MODULE := CB-prebuilt | |
+#LOCAL_SRC_FILES := $(LOCAL_PATH)/$(TARGET_ARCH_ABI)/libCB.so | |
+#LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.. | |
+#QCOM_PREBUILTS += $(LOCAL_MODULE) | |
+#include $(PREBUILT_SHARED_LIBRARY) | |
+# | |
+##add EGL_adreno | |
+#include $(CLEAR_VARS) | |
+#LOCAL_MODULE := EGL_adreno-prebuilt | |
+#LOCAL_SRC_FILES := $(LOCAL_PATH)/$(TARGET_ARCH_ABI)/libEGL_adreno.so | |
+#LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.. | |
+#QCOM_PREBUILTS += $(LOCAL_MODULE) | |
+#include $(PREBUILT_SHARED_LIBRARY) | |
+# | |
+##add GLESv1_CM_adreno | |
+#include $(CLEAR_VARS) | |
+#LOCAL_MODULE := GLESv1_CM_adreno-prebuilt | |
+#LOCAL_SRC_FILES := $(LOCAL_PATH)/$(TARGET_ARCH_ABI)/libGLESv1_CM_adreno.so | |
+#LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.. | |
+#QCOM_PREBUILTS += $(LOCAL_MODULE) | |
+#include $(PREBUILT_SHARED_LIBRARY) | |
+# | |
+##add GLESv2_adreno | |
+#include $(CLEAR_VARS) | |
+#LOCAL_MODULE := GLESv2_adreno-prebuilt | |
+#LOCAL_SRC_FILES := $(LOCAL_PATH)/$(TARGET_ARCH_ABI)/libGLESv2_adreno.so | |
+#LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.. | |
+#QCOM_PREBUILTS += $(LOCAL_MODULE) | |
+#include $(PREBUILT_SHARED_LIBRARY) | |
+ | |
+##add OpenCL | |
+#include $(CLEAR_VARS) | |
+#LOCAL_MODULE := OpenCL-prebuilt | |
+#LOCAL_SRC_FILES := $(LOCAL_PATH)/$(TARGET_ARCH_ABI)/libOpenCL.so | |
+#LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.. | |
+#QCOM_PREBUILTS += $(LOCAL_MODULE) | |
+#include $(PREBUILT_SHARED_LIBRARY) | |
+ | |
+##add adreno_utils | |
+#include $(CLEAR_VARS) | |
+#LOCAL_MODULE := adreno_utils-prebuilt | |
+#LOCAL_SRC_FILES := $(LOCAL_PATH)/$(TARGET_ARCH_ABI)/libadreno_utils.so | |
+#LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.. | |
+#QCOM_PREBUILTS += $(LOCAL_MODULE) | |
+#include $(PREBUILT_SHARED_LIBRARY) | |
+# | |
+##add C++ | |
+#include $(CLEAR_VARS) | |
+#LOCAL_MODULE := c++-prebuilt | |
+#LOCAL_SRC_FILES := $(LOCAL_PATH)/$(TARGET_ARCH_ABI)/libc++.so | |
+#LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.. | |
+#QCOM_PREBUILTS += $(LOCAL_MODULE) | |
+#include $(PREBUILT_SHARED_LIBRARY) | |
+# | |
+##add GSL | |
+#include $(CLEAR_VARS) | |
+#LOCAL_MODULE := gsl-prebuilt | |
+#LOCAL_SRC_FILES := $(LOCAL_PATH)/$(TARGET_ARCH_ABI)/libgsl.so | |
+#LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.. | |
+#QCOM_PREBUILTS += $(LOCAL_MODULE) | |
+#include $(PREBUILT_SHARED_LIBRARY) | |
+# | |
+##add llvm-glnext | |
+#include $(CLEAR_VARS) | |
+#LOCAL_MODULE := llvm-glnext-prebuilt | |
+#LOCAL_SRC_FILES := $(LOCAL_PATH)/$(TARGET_ARCH_ABI)/libllvm-glnext.so | |
+#LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.. | |
+#QCOM_PREBUILTS += $(LOCAL_MODULE) | |
+#include $(PREBUILT_SHARED_LIBRARY) | |
+# | |
+##add llvm-qcom | |
+#include $(CLEAR_VARS) | |
+#LOCAL_MODULE := llvm-qcom-prebuilt | |
+#LOCAL_SRC_FILES := $(LOCAL_PATH)/$(TARGET_ARCH_ABI)/libllvm-qcom.so | |
+#LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.. | |
+#QCOM_PREBUILTS += $(LOCAL_MODULE) | |
+#include $(PREBUILT_SHARED_LIBRARY) | |
+# | |
+##add q3dtools_adreno | |
+#include $(CLEAR_VARS) | |
+#LOCAL_MODULE := q3dtools_adreno-prebuilt | |
+#LOCAL_SRC_FILES := $(LOCAL_PATH)/$(TARGET_ARCH_ABI)/libq3dtools_adreno.so | |
+#LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.. | |
+#QCOM_PREBUILTS += $(LOCAL_MODULE) | |
+#include $(PREBUILT_SHARED_LIBRARY) | |
+# | |
+##add q3dtools_esx | |
+#include $(CLEAR_VARS) | |
+#LOCAL_MODULE := q3dtools_esx-prebuilt | |
+#LOCAL_SRC_FILES := $(LOCAL_PATH)/$(TARGET_ARCH_ABI)/libq3dtools_esx.so | |
+#LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.. | |
+#QCOM_PREBUILTS += $(LOCAL_MODULE) | |
+#include $(PREBUILT_SHARED_LIBRARY) | |
+ | |
# add OpenCV | |
include $(CLEAR_VARS) | |
+ | |
OPENCV_INSTALL_MODULES:=on | |
ifdef OPENCV_ANDROID_SDK | |
ifneq ("","$(wildcard $(OPENCV_ANDROID_SDK)/OpenCV.mk)") | |
@@ -24,4 +123,6 @@ LOCAL_LDLIBS += -L$(OPENCL_SDK)/lib/$(TARGET_ARCH_ABI) -lOpenCL | |
LOCAL_MODULE := JNIpart | |
LOCAL_SRC_FILES := jni.c CLprocessor.cpp | |
LOCAL_LDLIBS += -llog -lGLESv2 -lEGL | |
-include $(BUILD_SHARED_LIBRARY) | |
\ No newline at end of file | |
+LOCAL_SHARED_LIBRARIES += $(QCOM_PREBUILTS) | |
+ | |
+include $(BUILD_SHARED_LIBRARY) | |
diff --git a/samples/android/tutorial-4-opencl/jni/Application.mk b/samples/android/tutorial-4-opencl/jni/Application.mk | |
index 06db65762..19bbaaed4 100644 | |
--- a/samples/android/tutorial-4-opencl/jni/Application.mk | |
+++ b/samples/android/tutorial-4-opencl/jni/Application.mk | |
@@ -1,4 +1,6 @@ | |
APP_STL := gnustl_static | |
-APP_GNUSTL_FORCE_CPP_FEATURES := exceptions rtti | |
+#APP_STL=c++_shared | |
+APP_STL_FORCE_CPP_FEATURES := exceptions rtti | |
APP_ABI := armeabi-v7a | |
APP_PLATFORM := android-14 | |
+APP_CPPFLAGS := -fexceptions -frtti | |
diff --git a/samples/android/tutorial-4-opencl/jni/CLprocessor.cpp b/samples/android/tutorial-4-opencl/jni/CLprocessor.cpp | |
index b71dc1018..e872f27a9 100644 | |
--- a/samples/android/tutorial-4-opencl/jni/CLprocessor.cpp | |
+++ b/samples/android/tutorial-4-opencl/jni/CLprocessor.cpp | |
@@ -118,14 +118,31 @@ extern "C" void initCL() | |
LOGE("Warning: CL-GL sharing isn't supported by DEVICE"); | |
theQueue = cl::CommandQueue(theContext, devs[0]); | |
+ LOGE("initCL: created command queue"); | |
cl::Program::Sources src(1, std::make_pair(oclProgI2I, sizeof(oclProgI2I))); | |
theProgI2I = cl::Program(theContext, src); | |
+ LOGE("initCL: created program"); | |
theProgI2I.build(devs); | |
+ LOGE("initCL: built program"); | |
+ | |
+ | |
+ if (false) { | |
+ using namespace cv::ocl; | |
+ Context ctx = Context::getDefault(false); | |
+ LOGE("got default context"); | |
+ initializeContextFromHandle(ctx, p(), theContext(), devs[0]()); | |
+ LOGE("cv::ocl Initialized Context"); | |
+ clRetainContext((cl_context)theContext()); | |
+ LOGE("retained context"); | |
+ } | |
+ else { | |
+ cl_device_id dev = devs[0](); | |
+ cv::ocl::attachContext(p.getInfo<CL_PLATFORM_NAME>(), p(), theContext(), dev); | |
+ } | |
- cv::ocl::attachContext(p.getInfo<CL_PLATFORM_NAME>(), p(), theContext(), devs[0]()); | |
if( cv::ocl::useOpenCL() ) | |
- LOGD("OpenCV+OpenCL works OK!"); | |
+ LOGE("OpenCV+OpenCL works OK!"); | |
else | |
LOGE("Can't init OpenCV with OpenCL TAPI"); | |
haveOpenCL = true; | |
@@ -153,6 +170,7 @@ extern "C" void closeCL() | |
void procOCL_I2I(int texIn, int texOut, int w, int h) | |
{ | |
LOGD("Processing OpenCL Direct (image2d)"); | |
+ initCL(); | |
if(!haveOpenCL) | |
{ | |
LOGE("OpenCL isn't initialized"); | |
@@ -198,36 +216,65 @@ void procOCL_OCV(int texIn, int texOut, int w, int h) | |
return; | |
} | |
+ LOGE("texIn=%d texOut=%d\n", texIn, texOut); | |
+ | |
int64_t t = getTimeMs(); | |
+ LOGE("%s:%d\n", __func__, __LINE__); | |
cl::ImageGL imgIn (theContext, CL_MEM_READ_ONLY, GL_TEXTURE_2D, 0, texIn); | |
+ LOGE("%s:%d\n", __func__, __LINE__); | |
std::vector < cl::Memory > images(1, imgIn); | |
+ LOGE("%s:%d\n", __func__, __LINE__); | |
theQueue.enqueueAcquireGLObjects(&images); | |
+ LOGE("%s:%d\n", __func__, __LINE__); | |
theQueue.finish(); | |
+ LOGE("%s:%d\n", __func__, __LINE__); | |
cv::UMat uIn, uOut, uTmp; | |
+ LOGE("%s:%d\n", __func__, __LINE__); | |
cv::ocl::convertFromImage(imgIn(), uIn); | |
+ LOGE("%s:%d\n", __func__, __LINE__); | |
LOGD("loading texture data to OpenCV UMat costs %d ms", getTimeInterval(t)); | |
+ LOGE("%s:%d\n", __func__, __LINE__); | |
theQueue.enqueueReleaseGLObjects(&images); | |
+ LOGE("%s:%d\n", __func__, __LINE__); | |
t = getTimeMs(); | |
+ LOGE("%s:%d\n", __func__, __LINE__); | |
//cv::blur(uIn, uOut, cv::Size(5, 5)); | |
+ LOGE("%s:%d\n", __func__, __LINE__); | |
cv::Laplacian(uIn, uTmp, CV_8U); | |
+ LOGE("%s:%d\n", __func__, __LINE__); | |
cv:multiply(uTmp, 10, uOut); | |
+ LOGE("%s:%d\n", __func__, __LINE__); | |
cv::ocl::finish(); | |
+ LOGE("%s:%d\n", __func__, __LINE__); | |
LOGD("OpenCV processing costs %d ms", getTimeInterval(t)); | |
t = getTimeMs(); | |
+ LOGE("%s:%d\n", __func__, __LINE__); | |
cl::ImageGL imgOut(theContext, CL_MEM_WRITE_ONLY, GL_TEXTURE_2D, 0, texOut); | |
+ LOGE("%s:%d\n", __func__, __LINE__); | |
images.clear(); | |
+ LOGE("%s:%d\n", __func__, __LINE__); | |
images.push_back(imgOut); | |
+ LOGE("%s:%d\n", __func__, __LINE__); | |
theQueue.enqueueAcquireGLObjects(&images); | |
+ LOGE("%s:%d\n", __func__, __LINE__); | |
cl_mem clBuffer = (cl_mem)uOut.handle(cv::ACCESS_READ); | |
+ LOGE("%s:%d\n", __func__, __LINE__); | |
cl_command_queue q = (cl_command_queue)cv::ocl::Queue::getDefault().ptr(); | |
+ LOGE("%s:%d\n", __func__, __LINE__); | |
size_t offset = 0; | |
+ LOGE("%s:%d\n", __func__, __LINE__); | |
size_t origin[3] = { 0, 0, 0 }; | |
- size_t region[3] = { w, h, 1 }; | |
+ LOGE("%s:%d\n", __func__, __LINE__); | |
+ size_t region[3] = { static_cast<size_t>(w), static_cast<size_t>(h), 1 }; | |
+ LOGE("%s:%d\n", __func__, __LINE__); | |
CV_Assert(clEnqueueCopyBufferToImage (q, clBuffer, imgOut(), offset, origin, region, 0, NULL, NULL) == CL_SUCCESS); | |
+ LOGE("%s:%d\n", __func__, __LINE__); | |
theQueue.enqueueReleaseGLObjects(&images); | |
+ LOGE("%s:%d\n", __func__, __LINE__); | |
cv::ocl::finish(); | |
+ LOGE("%s:%d\n", __func__, __LINE__); | |
LOGD("uploading results to texture costs %d ms", getTimeInterval(t)); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment