SlideShare uma empresa Scribd logo
1 de 37
©SIProp Project, 2006-2008 1 
How to Build & Use OpenCL 
on OpenCV & Android NDK 
Noritsuna Imamura 
noritsuna@siprop.org
©SIProp Project, 2006-2008 2 
!!!!!!ATTENTION!!!!!! 
This manual is “How to Build” manual. 
If you want to “Use OpenCL on OpenCV” ONLY, 
Please see 
http://github.com/noritsuna/OpenCVwithOpenCL4 
AndroidNDKSample
How to Build OpenCL on OpenCV 
©SIProp Project, 2006-2008 3 
for Android NDK
©SIProp Project, 2006-2008 4 
Download OpenCV & NDK tool 
› wget 
https://github.com/Itseez/opencv/archive/ 
2.4.10.1tar.gz 
› tar zxfv 2.4.10.1.tar.gz 
› mkdir ~/android/ 
› cd ~/android/ 
› wget http://dl.google.com/android/android-sdk_ 
r23.0.2-linux.tgz 
› wget 
http://dl.google.com/android/ndk/android-ndk- 
r10c-linux-x86_64.bin 
› tar zxfv android-sdk_r23.0.2-linux.tgz 
› ./android-ndk-r10c-linux-x86_64.bin
©SIProp Project, 2006-2008 5 
Edit Setup File 
./opencv- 
2.4.10.1/platforms/scripts/cmake_android_arm.s 
h 
Add WITH_EIGEN=off option. 
Currently version has some bugs. 
› cmake -DWITH_EIGEN=OFF - 
DCMAKE_BUILD_WITH_INSTALL_RPATH=ON - 
DCMAKE_TOOLCHAIN_FILE=../android/android.toolchain.c 
make $@ ../..
©SIProp Project, 2006-2008 6 
Set Path to SDK/NDK 
› export ANDROID_NDK=~/android/android-ndk- 
r10c 
› export ANDROID_SDK=~/android/android-sdk- 
linux
Add “SO loading“ func for Android 1/3 
Change “SO loading“ func for Linux to this func 
without Android. 
~/opencv- 
2.4.10.1/modules/ocl/src/cl_runtime/cl_runtime.cpp 
©SIProp Project, 2006-2008 7 
› #if defined(__linux__) 
↓ 
› #if defined(__linux__) 
&& !defined(__ANDROID__)
Add “SO loading“ func for Android 2/3 
Add “SO loading“ func for Android. (continue to 
next page) 
~/opencv- 
2.4.10.1/modules/ocl/src/cl_runtime/cl_runtime.cpp 
©SIProp Project, 2006-2008 8 
› #if defined(__ANDROID__) 
› #include <dlfcn.h> 
› #include <sys/stat.h> 
› #if defined(__ARM_ARCH_8A__) || defined(_X64_) 
› static const char *default_so_paths[] = { 
› "/system/lib64/libOpenCL.so", 
› "/system/vendor/lib64/libOpenCL.so", 
› "/system/vendor/lib64/egl/libGLES_mali.so" 
› }; 
› #else 
› static const char *default_so_paths[] = { 
› "/system/lib/libOpenCL.so", 
› "/system/vendor/lib/libOpenCL.so", 
› "/system/vendor/lib/egl/libGLES_mali.so" 
› }; 
› #endif 
›
Add “SO loading“ func for Android 3/3 
©SIProp Project, 2006-2008 9 
› static int access_file(const char *filename) 
› { 
› struct stat buffer; 
› return (stat(filename, &buffer) == 0); 
› } 
› static void* GetProcAddress (const char* name) 
› { 
› static void* h = NULL; 
› unsigned int i; 
› if (!h) 
› { 
› const char* name; 
› for(i=0; i<(sizeof(default_so_paths)/sizeof(char*)); i++) 
› { 
› if(access_file(default_so_paths[i])) { 
› name = (char *)default_so_paths[i]; 
› h = dlopen(name, RTLD_LAZY); 
› if (h) break; 
› } 
› } 
› if (!h) 
› return NULL; 
› } 
› return dlsym(h, name); 
› } 
› #define CV_CL_GET_PROC_ADDRESS(name) GetProcAddress(name) 
› #endif
› cd ~/opencv-2.4.10.1/platforms/scripts/ 
› ./cmake_android_arm.sh 
©SIProp Project, 2006-2008 10 
Execute Auto Config & make 
This Script make Makefile for OpenCV. 
In “~/opencv- 
2.4.10.1/platforms/scripts/build_android_arm.sh” 
Make !!! 
› cd ~/opencv- 
2.4.10.1/platforms/scripts/build_android_arm 
/ 
› make
©SIProp Project, 2006-2008 11 
Where are Made Files? 
OpenCV Libs. 
In “~/opencv- 
2.4.10.1/platforms/build_android_arm/lib” 
highgui 
core 
etc... 
3rd Party Libs for OpenCV. 
In “~/opencv- 
2.4.10.1/platforms/build_android_arm/3rdparty/lib” 
libIlmImf 
libjasper 
libjpeg 
libpng 
libtiff
©SIProp Project, 2006-2008 12 
Copy libs to sample program 
OpenCV Libs. 
cp ~/opencv- 
2.4.10.1/platforms/build_android_arm/lib/armeabi-v7a/* 
~/opencv-2.4.10.1/samples/android/native-activity/ 
libs_opencv/ 
3rd Party Libs for OpenCV. 
cp ~/opencv- 
2.4.10.1/platforms/build_android_arm/3rdparty/lib/ar 
meabi-v7a/* ~/opencv- 
2.4.10.1/samples/android/native-activity/ 
libs_opencv/
How to Use OpenCL on OpenCV 
for Android NDK(Native App) 
©SIProp Project, 2006-2008 13
©SIProp Project, 2006-2008 14 
Download Sample Source Code 
http://github.com/noritsuna/OpenCVwithOpenCL4Andr 
oidNDKSample 
Based OpenCV-2.4.10.1 & Android 4.4 
Made Android Native Activity. 
Convert RGB Color Image to Black&White Image.
Call Stack 
Call as C/C++ APIs 
Call as SysCall(C/ASM) 
©SIProp Project, 2006-2008 15 
Native Application 
NDK wo/ADT 
Standard Android 
Application for C/C++ 
Only C/C++ on Limited 
Library Layer 
Advantage 
Only C/C++ 
DirectCall C/C++ API 
Dis-Advantage 
Use a few Android Tools 
A few Docs from Google 
Developer Site & Blogs 
APK File(Your Application) 
(C/C++) 
Library Layer 
(C/C++) 
Kernel/Driver Layer 
(C/ASM)
How to Make this Sample Source Code 
from OpenCV’s Sample Project 
©SIProp Project, 2006-2008 16
©SIProp Project, 2006-2008 17 
Use NativeActivity of OpenCV 
This Sample uses Only C/C++ Code. 
~/opencv-2.4.10.1/samples/android/native-activity 
Structure of NativeActivity 
AndroidManifest.xml <- Property File for Android 
res <- Directory that has Resource file(Image,Voice) 
jni <- Directory that has files for NDK 
Android.mk <- make file of NDK 
Application.mk <- property file of NDK 
native.cpp <- Sample App 
Other Files/Dir, don’t use.
©SIProp Project, 2006-2008 18 
Edit AndroidManifest.xml 
Replace “application” Section 
1. <application android:label="@string/app_name" 
android:hasCode="false"> 
2. <activity android:name="android.app.NativeActivity" 
3. android:label="@string/app_name" 
4. 
android:configChanges="orientation|keyboardHidden"> 
5. <!-- Tell NativeActivity the name of or .so --> 
6. <meta-data android:name="android.app.lib_name" 
7. android:value="native_activity" /> 
8. <intent-filter> 
9. <action 
android:name="android.intent.action.MAIN" /> 
10. <category 
android:name="android.intent.category.LAUNCHER" /> 
11. </intent-filter> 
12. </activity> 
13. </application>
2. <uses-sdk android:minSdkVersion=“9" /> 
©SIProp Project, 2006-2008 19 
About AndroidManifest.xml 
API Level 
1. <!-- This is the platform API where 
NativeActivity was introduced. --> 
Permission 
1. <uses-permission 
android:name="android.permission.CAMERA 
"/>
©SIProp Project, 2006-2008 20 
Create jni/Android.mk 1/9 
1. Delete jni/Android.mk & Create the new 
jni/Android.mk 
2. Set LOCAL_PATH & include 
1. LOCAL_PATH := $(call my-dir) 
2. include $(CLEAR_VARS)
©SIProp Project, 2006-2008 21 
Create jni/Android.mk 2/9 
1. Set OpenCV’s Modules & Libs 
1. OPENCV_MODULES:=contrib legacy ml 
stitching superres objdetect ts videostab 
video photo calib3d features2d highgui 
imgproc flann ocl core androidcamera 
2. OPENCV_3RDPARTY_COMPONENTS:=asse 
tmanager tbb libjpeg libpng libtiff libjasper 
IlmImf 
3. OPENCV_CAMERA_MODULES:= 
native_camera_r2.2.0 native_camera_r2.3.3 
native_camera_r3.0.1 native_camera_r4.0.0 
native_camera_r4.0.3 native_camera_r4.1.1 
native_camera_r4.2.0 native_camera_r4.3.0 
native_camera_r4.4.0
LOCAL_SRC_FILES:=../libs_opencv/libopenc 
v_$1.a 
5. include $(PREBUILT_STATIC_LIBRARY) 
6. endef 
©SIProp Project, 2006-2008 22 
Create jni/Android.mk 3/9 
Set Loading OpenCV Libs Function 
1. define add_opencv_module 
2. include $(CLEAR_VARS) 
3. LOCAL_MODULE:=opencv_$1 
4. 
1. $(foreach 
module,$(OPENCV_MODULES),$(eval $(call 
add_opencv_module,$(module))))
1. define add_opencv_3rdparty_component 
2. include $(CLEAR_VARS) 
3. LOCAL_MODULE:=$1 
4. 
LOCAL_SRC_FILES:=../libs_opencv/lib$1.a 
5. include $(PREBUILT_STATIC_LIBRARY) 
6. endef 
©SIProp Project, 2006-2008 23 
Create jni/Android.mk 4/9 
Set Loading OpenCV Libs Function 
1. $(foreach 
module,$(OPENCV_3RDPARTY_COMPONEN 
TS),$(eval $(call 
add_opencv_3rdparty_component,$(module))))
LOCAL_SRC_FILES:=../libs_opencv/lib$1.so 
5. include $(PREBUILT_SHARED_LIBRARY) 
6. endef 
©SIProp Project, 2006-2008 24 
Create jni/Android.mk 5/9 
Set Loading AndroidCamera Libs Function 
1. define add_opencv_camera_module 
2. include $(CLEAR_VARS) 
3. LOCAL_MODULE:=$1 
4. 
1. $(foreach 
module,$(OPENCV_CAMERA_MODULES),$(e 
val $(call 
add_opencv_camera_module,$(module))))
©SIProp Project, 2006-2008 25 
Create jni/Android.mk 6/9 
Set loading info lib 
1. include $(CLEAR_VARS) 
2. LOCAL_MODULE:=opencv_info 
3. LOCAL_SRC_FILES:=../libs_opencv/libopenc 
v_info.so 
4. include $(PREBUILT_SHARED_LIBRARY)
©SIProp Project, 2006-2008 26 
Create jni/Android.mk 7/9 
Set Include Dir 
Set Module name & Source Code 
OpenCVwithOpenCL4AndroidNDKNativeActivity.cpp 
1. include $(CLEAR_VARS) 
2. LOCAL_C_INCLUDES+=./jni/include 
3. LOCAL_MODULE := OpenCV_CL 
4. LOCAL_SRC_FILES := 
OpenCVwithOpenCL4AndroidNDKNativeActi 
vity.cpp
©SIProp Project, 2006-2008 27 
Create jni/Android.mk 8/9 
Set Loading Lib & OpenCV Lib 
LOCAL_LDLIBS 
-lm -llog -lc -ldl -lz -landroid 
LOCAL_STATIC_LIBRARIES 
$(foreach mod, $(OPENCV_MODULES), opencv_$(mod)) 
$(OPENCV_3RDPARTY_COMPONENTS) 
1. LOCAL_LDLIBS += -lm -llog -lc -ldl -lz - 
landroid 
2. LOCAL_STATIC_LIBRARIES := 
android_native_app_glue $(foreach mod, 
$(OPENCV_MODULES), opencv_$(mod)) 
$(OPENCV_3RDPARTY_COMPONENTS)
©SIProp Project, 2006-2008 28 
Create jni/Android.mk 9/9 
Set Library Type 
Make SO lib 
BUILD_SHARED_LIBRARY 
Set Loading Android module 
Use “native_app_glue” module 
$(call import-module,android/native_app_glue) 
1. include $(BUILD_SHARED_LIBRARY) 
2. $(call import-module, 
android/native_app_glue)
©SIProp Project, 2006-2008 29 
Setup/Make Build.xml 1/2 
Making Setting File for Android using ANT 
Today, Development on CUI Only!!! 
Don’t use Eclipse! 
› android list target 
› Available Android targets: 
› ---------- 
› id: 1 or "android-9" 
› Name: Android 2.3.1 
› Type: Platform 
› API level: 9 
› Revision: 2 
› Skins: WQVGA400, QVGA, HVGA, WVGA800 (default), WVGA854 
› ABIs : armeabi 
› ---------- 
› id: 2 or "android-18" 
› Name: Android 4.3 
› Type: Platform 
› API level: 18 
› Revision: 2 
› Skins: WXGA800, WQVGA400, QVGA, WQVGA432, WXGA800-7in, WVGA800 
(default), HVGA, WXGA720, WSVGA, WVGA854 
› ABIs : armeabi-v7a 
› ----------
©SIProp Project, 2006-2008 30 
Setup/Make Build.xml 2/2 
Make Build.xml 
› android update project --path . --target 2
©SIProp Project, 2006-2008 31 
Build NativeActivity 
Build C/C++ Source Codes 
› ndk-build [clean all] 
Make APK File 
› ant [debug|release]
› adb install bin/NativeActivity-debug.apk 
› adb uninstall com.example.native_activity 
©SIProp Project, 2006-2008 32 
Install NativeActivity.apk 
Install APK File 
UnInstall APK File 
Show Log 
› adb logcat
©SIProp Project, 2006-2008 33 
adb(Android Debug Bridge) 
Functions 
Shell on Android Device 
adb shell 
Show Connected Android Devices 
adb devices 
Install/Uninstall APK File 
adb install/uninstall [App Name]/[Package Name] 
Send/Get File to/from Android Device 
adb push/pull [from File Path] [to File Path] 
Show Log (DDMS) 
adb logcat
©SIProp Project, 2006-2008 34 
Quick Explanation to OpenCL 
1. void android_main(android_app* app) { 
2. (snip) 
3. cv::Mat drawing_frame; 
4. (snip) 
5. colorSampleImage = imread(file_path); 
6. (snip) 
7. // Create Mat Object for OpenCL 
8. cv::ocl::oclMat oclIn(colorSampleImage), oclOut; 
9. // Change Color RGB->Black&White on OpenCL 
10. cv::ocl::cvtColor(oclIn, oclOut, cv::COLOR_BGR2GRAY); 
11. // Download Mat Object for OpenCL to Mat for CPU 
12. oclOut.download(drawing_frame); 
13. 
14. engine_draw_frame(&engine, drawing_frame);
How to Set up OpenCL Driver 
adreno-3xx: Qualcomm's Adreno 3xx GPUs 
©SIProp Project, 2006-2008 35 
mali-t6xx: ARM's Mali-T6xx GPUs
©SIProp Project, 2006-2008 36 
Download OpenCL Drivers 
OpenCL Drivers was deleted since 4.2 
adreno-3xx: Qualcomm's Adreno 3xx GPUs 
mali-t6xx: ARM's Mali-T6xx GPUs 
Download from: 
https://github.com/madeye/opencl-android-proprietary
©SIProp Project, 2006-2008 37 
Set up Drivers to your Android 
Ex. adreno-3xx: Qualcomm's Adreno 3xx GPUs 
1. $ adb push kitkat/system/vendor/lib /sdcard/ 
2. $ adb shell 
3. $ su 
4. # mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 
/system 
5. # cp /sdcard/libOpenCL.so /system/vendor/lib/ 
6. # cp /sdcard/libllvm-a3xx.so /system/vendor/lib/ 
7. # chmod 644 /system/vendor/lib/libOpenCL.so 
8. # chmod 644 /system/vendor/lib/libllvm-a3xx.so

Mais conteúdo relacionado

Mais procurados

Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Opersys inc.
 
"Building Complete Embedded Vision Systems on Linux—From Camera to Display," ...
"Building Complete Embedded Vision Systems on Linux—From Camera to Display," ..."Building Complete Embedded Vision Systems on Linux—From Camera to Display," ...
"Building Complete Embedded Vision Systems on Linux—From Camera to Display," ...
Edge AI and Vision Alliance
 
Observer design pattern
Observer design patternObserver design pattern
Observer design pattern
Sara Torkey
 
Android+init+process
Android+init+processAndroid+init+process
Android+init+process
Hong Jae Kwon
 

Mais procurados (20)

Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)
 
XDP in Practice: DDoS Mitigation @Cloudflare
XDP in Practice: DDoS Mitigation @CloudflareXDP in Practice: DDoS Mitigation @Cloudflare
XDP in Practice: DDoS Mitigation @Cloudflare
 
HKG15-311: OP-TEE for Beginners and Porting Review
HKG15-311: OP-TEE for Beginners and Porting ReviewHKG15-311: OP-TEE for Beginners and Porting Review
HKG15-311: OP-TEE for Beginners and Porting Review
 
Understanding the Android System Server
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System Server
 
Q4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsQ4.11: Porting Android to new Platforms
Q4.11: Porting Android to new Platforms
 
AstriCon 2017 - Docker Swarm & Asterisk
AstriCon 2017  - Docker Swarm & AsteriskAstriCon 2017  - Docker Swarm & Asterisk
AstriCon 2017 - Docker Swarm & Asterisk
 
Linux Containers (LXC)
Linux Containers (LXC)Linux Containers (LXC)
Linux Containers (LXC)
 
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
 
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)
 
Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)
 
"Learning AOSP" - Android Hardware Abstraction Layer (HAL)
"Learning AOSP" - Android Hardware Abstraction Layer (HAL)"Learning AOSP" - Android Hardware Abstraction Layer (HAL)
"Learning AOSP" - Android Hardware Abstraction Layer (HAL)
 
"Building Complete Embedded Vision Systems on Linux—From Camera to Display," ...
"Building Complete Embedded Vision Systems on Linux—From Camera to Display," ..."Building Complete Embedded Vision Systems on Linux—From Camera to Display," ...
"Building Complete Embedded Vision Systems on Linux—From Camera to Display," ...
 
Vulkan 1.1 Reference Guide
Vulkan 1.1 Reference GuideVulkan 1.1 Reference Guide
Vulkan 1.1 Reference Guide
 
Epoxy 介紹
Epoxy 介紹Epoxy 介紹
Epoxy 介紹
 
Observer design pattern
Observer design patternObserver design pattern
Observer design pattern
 
Parceable serializable
Parceable serializableParceable serializable
Parceable serializable
 
Android+init+process
Android+init+processAndroid+init+process
Android+init+process
 
Linux Internals - Part II
Linux Internals - Part IILinux Internals - Part II
Linux Internals - Part II
 
Android Booting Sequence
Android Booting SequenceAndroid Booting Sequence
Android Booting Sequence
 
[KubeConEU] Building images efficiently and securely on Kubernetes with BuildKit
[KubeConEU] Building images efficiently and securely on Kubernetes with BuildKit[KubeConEU] Building images efficiently and securely on Kubernetes with BuildKit
[KubeConEU] Building images efficiently and securely on Kubernetes with BuildKit
 

Destaque

OpenCV 3.0 - Latest news and the Roadmap
OpenCV 3.0 - Latest news and the RoadmapOpenCV 3.0 - Latest news and the Roadmap
OpenCV 3.0 - Latest news and the Roadmap
Eugene Khvedchenya
 
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres..."The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
Edge AI and Vision Alliance
 

Destaque (20)

OpenCV acceleration battle:OpenCL on Firefly-RK3288(MALI-T764) vs. FPGA on Ze...
OpenCV acceleration battle:OpenCL on Firefly-RK3288(MALI-T764) vs. FPGA on Ze...OpenCV acceleration battle:OpenCL on Firefly-RK3288(MALI-T764) vs. FPGA on Ze...
OpenCV acceleration battle:OpenCL on Firefly-RK3288(MALI-T764) vs. FPGA on Ze...
 
Zedroid - Android (5.0 and later) on Zedboard
Zedroid - Android (5.0 and later) on ZedboardZedroid - Android (5.0 and later) on Zedboard
Zedroid - Android (5.0 and later) on Zedboard
 
How to Add Original Library to Android NDK
How to Add Original Library to Android NDKHow to Add Original Library to Android NDK
How to Add Original Library to Android NDK
 
將DNA在廚房抽出的程序
將DNA在廚房抽出的程序將DNA在廚房抽出的程序
將DNA在廚房抽出的程序
 
Introduction to OpenCV
Introduction to OpenCVIntroduction to OpenCV
Introduction to OpenCV
 
Looking into the past - feature extraction from historic maps using Python, O...
Looking into the past - feature extraction from historic maps using Python, O...Looking into the past - feature extraction from historic maps using Python, O...
Looking into the past - feature extraction from historic maps using Python, O...
 
Introduction to OpenCV with python (at taichung.py)
Introduction to OpenCV with python (at taichung.py)Introduction to OpenCV with python (at taichung.py)
Introduction to OpenCV with python (at taichung.py)
 
OpenCV 에서 OpenCL 살짝 써보기
OpenCV 에서 OpenCL 살짝 써보기OpenCV 에서 OpenCL 살짝 써보기
OpenCV 에서 OpenCL 살짝 써보기
 
Using openCV 3.1.0 with vs2015
Using openCV 3.1.0 with vs2015Using openCV 3.1.0 with vs2015
Using openCV 3.1.0 with vs2015
 
Using openCV 2.0 with Dev C++
Using openCV 2.0 with Dev C++Using openCV 2.0 with Dev C++
Using openCV 2.0 with Dev C++
 
OpenCV 3.0 - Latest news and the Roadmap
OpenCV 3.0 - Latest news and the RoadmapOpenCV 3.0 - Latest news and the Roadmap
OpenCV 3.0 - Latest news and the Roadmap
 
Face Recognition with OpenCV and scikit-learn
Face Recognition with OpenCV and scikit-learnFace Recognition with OpenCV and scikit-learn
Face Recognition with OpenCV and scikit-learn
 
OpenCV Workshop
OpenCV WorkshopOpenCV Workshop
OpenCV Workshop
 
PYNQ 祭り: Pmod のプログラミング
PYNQ 祭り: Pmod のプログラミングPYNQ 祭り: Pmod のプログラミング
PYNQ 祭り: Pmod のプログラミング
 
OpenCV Introduction
OpenCV IntroductionOpenCV Introduction
OpenCV Introduction
 
PYNQで○○してみた!
PYNQで○○してみた!PYNQで○○してみた!
PYNQで○○してみた!
 
PYNQ祭り
PYNQ祭りPYNQ祭り
PYNQ祭り
 
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres..."The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
 
Image Processing with OpenCV
Image Processing with OpenCVImage Processing with OpenCV
Image Processing with OpenCV
 
Computer Vision, Deep Learning, OpenCV
Computer Vision, Deep Learning, OpenCVComputer Vision, Deep Learning, OpenCV
Computer Vision, Deep Learning, OpenCV
 

Semelhante a How to Build & Use OpenCL on OpenCV & Android NDK

Kandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_finalKandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_final
NAVER D2
 
Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013
Opersys inc.
 
Native Android for Windows Developers
Native Android for Windows DevelopersNative Android for Windows Developers
Native Android for Windows Developers
Yoss Cohen
 
Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud
Shekhar Gulati
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
catherinewall
 

Semelhante a How to Build & Use OpenCL on OpenCV & Android NDK (20)

How to Use OpenMP on Native Activity
How to Use OpenMP on Native ActivityHow to Use OpenMP on Native Activity
How to Use OpenMP on Native Activity
 
State ofappdevelopment
State ofappdevelopmentState ofappdevelopment
State ofappdevelopment
 
Kandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_finalKandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_final
 
Lecture02web 140phpapp01
Lecture02web 140phpapp01Lecture02web 140phpapp01
Lecture02web 140phpapp01
 
Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013
 
Native Android for Windows Developers
Native Android for Windows DevelopersNative Android for Windows Developers
Native Android for Windows Developers
 
Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014
 
Pwning mobile apps without root or jailbreak
Pwning mobile apps without root or jailbreakPwning mobile apps without root or jailbreak
Pwning mobile apps without root or jailbreak
 
DEEP: a user success story
DEEP: a user success storyDEEP: a user success story
DEEP: a user success story
 
MicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexus
MicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexusMicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexus
MicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexus
 
Docker module 1
Docker module 1Docker module 1
Docker module 1
 
Mastering the NDK with Android Studio 2.0 and the gradle-experimental plugin
Mastering the NDK with Android Studio 2.0 and the gradle-experimental pluginMastering the NDK with Android Studio 2.0 and the gradle-experimental plugin
Mastering the NDK with Android Studio 2.0 and the gradle-experimental plugin
 
How to Make Android Native Application
How to Make Android Native ApplicationHow to Make Android Native Application
How to Make Android Native Application
 
Getting Native with NDK
Getting Native with NDKGetting Native with NDK
Getting Native with NDK
 
Mac ruby deployment
Mac ruby deploymentMac ruby deployment
Mac ruby deployment
 
Core Android
Core AndroidCore Android
Core Android
 
An OpenShift Primer for Developers to get your Code into the Cloud (PTJUG)
An OpenShift Primer for Developers to get your Code into the Cloud (PTJUG)An OpenShift Primer for Developers to get your Code into the Cloud (PTJUG)
An OpenShift Primer for Developers to get your Code into the Cloud (PTJUG)
 
Android development beginners faq
Android development  beginners faqAndroid development  beginners faq
Android development beginners faq
 
Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
 

Mais de Industrial Technology Research Institute (ITRI)(工業技術研究院, 工研院)

Mais de Industrial Technology Research Institute (ITRI)(工業技術研究院, 工研院) (20)

What is the world where you can make your own semiconductors?
What is the world where you can make your own semiconductors?What is the world where you can make your own semiconductors?
What is the world where you can make your own semiconductors?
 
半導体製造(TinyTapeout)に挑戦しよう!
半導体製造(TinyTapeout)に挑戦しよう!半導体製造(TinyTapeout)に挑戦しよう!
半導体製造(TinyTapeout)に挑戦しよう!
 
Introduction of ISHI-KAI with OpenMPW
Introduction of ISHI-KAI with OpenMPWIntroduction of ISHI-KAI with OpenMPW
Introduction of ISHI-KAI with OpenMPW
 
Kernel/VMレイヤーを自分色に染める!By ISHI会
Kernel/VMレイヤーを自分色に染める!By ISHI会Kernel/VMレイヤーを自分色に染める!By ISHI会
Kernel/VMレイヤーを自分色に染める!By ISHI会
 
Principle Representation of The 8 Qubits Quantum Computer by RaspberryPi
Principle Representation of The 8 Qubits Quantum Computer by RaspberryPiPrinciple Representation of The 8 Qubits Quantum Computer by RaspberryPi
Principle Representation of The 8 Qubits Quantum Computer by RaspberryPi
 
Microwaveguquantum
MicrowaveguquantumMicrowaveguquantum
Microwaveguquantum
 
The easiest way of setup QuTiP on Windows
The easiest way of setup QuTiP on WindowsThe easiest way of setup QuTiP on Windows
The easiest way of setup QuTiP on Windows
 
GNU Radio Study for Super beginner
GNU Radio Study for Super beginnerGNU Radio Study for Super beginner
GNU Radio Study for Super beginner
 
The Self-Contained SDR Satellite Grand Station with Raspberry Pi 3
The Self-Contained SDR Satellite Grand Station with Raspberry Pi 3The Self-Contained SDR Satellite Grand Station with Raspberry Pi 3
The Self-Contained SDR Satellite Grand Station with Raspberry Pi 3
 
Self‐Contained SDR Grand Station with Raspberry Pi 3
Self‐Contained SDR Grand Station with Raspberry Pi 3Self‐Contained SDR Grand Station with Raspberry Pi 3
Self‐Contained SDR Grand Station with Raspberry Pi 3
 
衛星追尾用パラボラアンテナ建設記
衛星追尾用パラボラアンテナ建設記衛星追尾用パラボラアンテナ建設記
衛星追尾用パラボラアンテナ建設記
 
All list of the measuring machines for microwave
All list of the measuring machines for microwaveAll list of the measuring machines for microwave
All list of the measuring machines for microwave
 
5000円で誰でも作れる新世代衛星地上局
5000円で誰でも作れる新世代衛星地上局5000円で誰でも作れる新世代衛星地上局
5000円で誰でも作れる新世代衛星地上局
 
How to setup mastodon in chinese
How to setup mastodon in chineseHow to setup mastodon in chinese
How to setup mastodon in chinese
 
Radiation Test -Raspberry PI Zero-
Radiation Test -Raspberry PI Zero-Radiation Test -Raspberry PI Zero-
Radiation Test -Raspberry PI Zero-
 
Protocol of the DNA Extraction in Kitchen
Protocol of the DNA Extraction in KitchenProtocol of the DNA Extraction in Kitchen
Protocol of the DNA Extraction in Kitchen
 
3D Printed Google Cardboard for workshop
3D Printed Google Cardboard for workshop3D Printed Google Cardboard for workshop
3D Printed Google Cardboard for workshop
 
計算機(物理)
計算機(物理)計算機(物理)
計算機(物理)
 
Resume
ResumeResume
Resume
 
How to Make a Scanning Drone in Chinese
How to Make a Scanning Drone in ChineseHow to Make a Scanning Drone in Chinese
How to Make a Scanning Drone in Chinese
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

How to Build & Use OpenCL on OpenCV & Android NDK

  • 1. ©SIProp Project, 2006-2008 1 How to Build & Use OpenCL on OpenCV & Android NDK Noritsuna Imamura noritsuna@siprop.org
  • 2. ©SIProp Project, 2006-2008 2 !!!!!!ATTENTION!!!!!! This manual is “How to Build” manual. If you want to “Use OpenCL on OpenCV” ONLY, Please see http://github.com/noritsuna/OpenCVwithOpenCL4 AndroidNDKSample
  • 3. How to Build OpenCL on OpenCV ©SIProp Project, 2006-2008 3 for Android NDK
  • 4. ©SIProp Project, 2006-2008 4 Download OpenCV & NDK tool › wget https://github.com/Itseez/opencv/archive/ 2.4.10.1tar.gz › tar zxfv 2.4.10.1.tar.gz › mkdir ~/android/ › cd ~/android/ › wget http://dl.google.com/android/android-sdk_ r23.0.2-linux.tgz › wget http://dl.google.com/android/ndk/android-ndk- r10c-linux-x86_64.bin › tar zxfv android-sdk_r23.0.2-linux.tgz › ./android-ndk-r10c-linux-x86_64.bin
  • 5. ©SIProp Project, 2006-2008 5 Edit Setup File ./opencv- 2.4.10.1/platforms/scripts/cmake_android_arm.s h Add WITH_EIGEN=off option. Currently version has some bugs. › cmake -DWITH_EIGEN=OFF - DCMAKE_BUILD_WITH_INSTALL_RPATH=ON - DCMAKE_TOOLCHAIN_FILE=../android/android.toolchain.c make $@ ../..
  • 6. ©SIProp Project, 2006-2008 6 Set Path to SDK/NDK › export ANDROID_NDK=~/android/android-ndk- r10c › export ANDROID_SDK=~/android/android-sdk- linux
  • 7. Add “SO loading“ func for Android 1/3 Change “SO loading“ func for Linux to this func without Android. ~/opencv- 2.4.10.1/modules/ocl/src/cl_runtime/cl_runtime.cpp ©SIProp Project, 2006-2008 7 › #if defined(__linux__) ↓ › #if defined(__linux__) && !defined(__ANDROID__)
  • 8. Add “SO loading“ func for Android 2/3 Add “SO loading“ func for Android. (continue to next page) ~/opencv- 2.4.10.1/modules/ocl/src/cl_runtime/cl_runtime.cpp ©SIProp Project, 2006-2008 8 › #if defined(__ANDROID__) › #include <dlfcn.h> › #include <sys/stat.h> › #if defined(__ARM_ARCH_8A__) || defined(_X64_) › static const char *default_so_paths[] = { › "/system/lib64/libOpenCL.so", › "/system/vendor/lib64/libOpenCL.so", › "/system/vendor/lib64/egl/libGLES_mali.so" › }; › #else › static const char *default_so_paths[] = { › "/system/lib/libOpenCL.so", › "/system/vendor/lib/libOpenCL.so", › "/system/vendor/lib/egl/libGLES_mali.so" › }; › #endif ›
  • 9. Add “SO loading“ func for Android 3/3 ©SIProp Project, 2006-2008 9 › static int access_file(const char *filename) › { › struct stat buffer; › return (stat(filename, &buffer) == 0); › } › static void* GetProcAddress (const char* name) › { › static void* h = NULL; › unsigned int i; › if (!h) › { › const char* name; › for(i=0; i<(sizeof(default_so_paths)/sizeof(char*)); i++) › { › if(access_file(default_so_paths[i])) { › name = (char *)default_so_paths[i]; › h = dlopen(name, RTLD_LAZY); › if (h) break; › } › } › if (!h) › return NULL; › } › return dlsym(h, name); › } › #define CV_CL_GET_PROC_ADDRESS(name) GetProcAddress(name) › #endif
  • 10. › cd ~/opencv-2.4.10.1/platforms/scripts/ › ./cmake_android_arm.sh ©SIProp Project, 2006-2008 10 Execute Auto Config & make This Script make Makefile for OpenCV. In “~/opencv- 2.4.10.1/platforms/scripts/build_android_arm.sh” Make !!! › cd ~/opencv- 2.4.10.1/platforms/scripts/build_android_arm / › make
  • 11. ©SIProp Project, 2006-2008 11 Where are Made Files? OpenCV Libs. In “~/opencv- 2.4.10.1/platforms/build_android_arm/lib” highgui core etc... 3rd Party Libs for OpenCV. In “~/opencv- 2.4.10.1/platforms/build_android_arm/3rdparty/lib” libIlmImf libjasper libjpeg libpng libtiff
  • 12. ©SIProp Project, 2006-2008 12 Copy libs to sample program OpenCV Libs. cp ~/opencv- 2.4.10.1/platforms/build_android_arm/lib/armeabi-v7a/* ~/opencv-2.4.10.1/samples/android/native-activity/ libs_opencv/ 3rd Party Libs for OpenCV. cp ~/opencv- 2.4.10.1/platforms/build_android_arm/3rdparty/lib/ar meabi-v7a/* ~/opencv- 2.4.10.1/samples/android/native-activity/ libs_opencv/
  • 13. How to Use OpenCL on OpenCV for Android NDK(Native App) ©SIProp Project, 2006-2008 13
  • 14. ©SIProp Project, 2006-2008 14 Download Sample Source Code http://github.com/noritsuna/OpenCVwithOpenCL4Andr oidNDKSample Based OpenCV-2.4.10.1 & Android 4.4 Made Android Native Activity. Convert RGB Color Image to Black&White Image.
  • 15. Call Stack Call as C/C++ APIs Call as SysCall(C/ASM) ©SIProp Project, 2006-2008 15 Native Application NDK wo/ADT Standard Android Application for C/C++ Only C/C++ on Limited Library Layer Advantage Only C/C++ DirectCall C/C++ API Dis-Advantage Use a few Android Tools A few Docs from Google Developer Site & Blogs APK File(Your Application) (C/C++) Library Layer (C/C++) Kernel/Driver Layer (C/ASM)
  • 16. How to Make this Sample Source Code from OpenCV’s Sample Project ©SIProp Project, 2006-2008 16
  • 17. ©SIProp Project, 2006-2008 17 Use NativeActivity of OpenCV This Sample uses Only C/C++ Code. ~/opencv-2.4.10.1/samples/android/native-activity Structure of NativeActivity AndroidManifest.xml <- Property File for Android res <- Directory that has Resource file(Image,Voice) jni <- Directory that has files for NDK Android.mk <- make file of NDK Application.mk <- property file of NDK native.cpp <- Sample App Other Files/Dir, don’t use.
  • 18. ©SIProp Project, 2006-2008 18 Edit AndroidManifest.xml Replace “application” Section 1. <application android:label="@string/app_name" android:hasCode="false"> 2. <activity android:name="android.app.NativeActivity" 3. android:label="@string/app_name" 4. android:configChanges="orientation|keyboardHidden"> 5. <!-- Tell NativeActivity the name of or .so --> 6. <meta-data android:name="android.app.lib_name" 7. android:value="native_activity" /> 8. <intent-filter> 9. <action android:name="android.intent.action.MAIN" /> 10. <category android:name="android.intent.category.LAUNCHER" /> 11. </intent-filter> 12. </activity> 13. </application>
  • 19. 2. <uses-sdk android:minSdkVersion=“9" /> ©SIProp Project, 2006-2008 19 About AndroidManifest.xml API Level 1. <!-- This is the platform API where NativeActivity was introduced. --> Permission 1. <uses-permission android:name="android.permission.CAMERA "/>
  • 20. ©SIProp Project, 2006-2008 20 Create jni/Android.mk 1/9 1. Delete jni/Android.mk & Create the new jni/Android.mk 2. Set LOCAL_PATH & include 1. LOCAL_PATH := $(call my-dir) 2. include $(CLEAR_VARS)
  • 21. ©SIProp Project, 2006-2008 21 Create jni/Android.mk 2/9 1. Set OpenCV’s Modules & Libs 1. OPENCV_MODULES:=contrib legacy ml stitching superres objdetect ts videostab video photo calib3d features2d highgui imgproc flann ocl core androidcamera 2. OPENCV_3RDPARTY_COMPONENTS:=asse tmanager tbb libjpeg libpng libtiff libjasper IlmImf 3. OPENCV_CAMERA_MODULES:= native_camera_r2.2.0 native_camera_r2.3.3 native_camera_r3.0.1 native_camera_r4.0.0 native_camera_r4.0.3 native_camera_r4.1.1 native_camera_r4.2.0 native_camera_r4.3.0 native_camera_r4.4.0
  • 22. LOCAL_SRC_FILES:=../libs_opencv/libopenc v_$1.a 5. include $(PREBUILT_STATIC_LIBRARY) 6. endef ©SIProp Project, 2006-2008 22 Create jni/Android.mk 3/9 Set Loading OpenCV Libs Function 1. define add_opencv_module 2. include $(CLEAR_VARS) 3. LOCAL_MODULE:=opencv_$1 4. 1. $(foreach module,$(OPENCV_MODULES),$(eval $(call add_opencv_module,$(module))))
  • 23. 1. define add_opencv_3rdparty_component 2. include $(CLEAR_VARS) 3. LOCAL_MODULE:=$1 4. LOCAL_SRC_FILES:=../libs_opencv/lib$1.a 5. include $(PREBUILT_STATIC_LIBRARY) 6. endef ©SIProp Project, 2006-2008 23 Create jni/Android.mk 4/9 Set Loading OpenCV Libs Function 1. $(foreach module,$(OPENCV_3RDPARTY_COMPONEN TS),$(eval $(call add_opencv_3rdparty_component,$(module))))
  • 24. LOCAL_SRC_FILES:=../libs_opencv/lib$1.so 5. include $(PREBUILT_SHARED_LIBRARY) 6. endef ©SIProp Project, 2006-2008 24 Create jni/Android.mk 5/9 Set Loading AndroidCamera Libs Function 1. define add_opencv_camera_module 2. include $(CLEAR_VARS) 3. LOCAL_MODULE:=$1 4. 1. $(foreach module,$(OPENCV_CAMERA_MODULES),$(e val $(call add_opencv_camera_module,$(module))))
  • 25. ©SIProp Project, 2006-2008 25 Create jni/Android.mk 6/9 Set loading info lib 1. include $(CLEAR_VARS) 2. LOCAL_MODULE:=opencv_info 3. LOCAL_SRC_FILES:=../libs_opencv/libopenc v_info.so 4. include $(PREBUILT_SHARED_LIBRARY)
  • 26. ©SIProp Project, 2006-2008 26 Create jni/Android.mk 7/9 Set Include Dir Set Module name & Source Code OpenCVwithOpenCL4AndroidNDKNativeActivity.cpp 1. include $(CLEAR_VARS) 2. LOCAL_C_INCLUDES+=./jni/include 3. LOCAL_MODULE := OpenCV_CL 4. LOCAL_SRC_FILES := OpenCVwithOpenCL4AndroidNDKNativeActi vity.cpp
  • 27. ©SIProp Project, 2006-2008 27 Create jni/Android.mk 8/9 Set Loading Lib & OpenCV Lib LOCAL_LDLIBS -lm -llog -lc -ldl -lz -landroid LOCAL_STATIC_LIBRARIES $(foreach mod, $(OPENCV_MODULES), opencv_$(mod)) $(OPENCV_3RDPARTY_COMPONENTS) 1. LOCAL_LDLIBS += -lm -llog -lc -ldl -lz - landroid 2. LOCAL_STATIC_LIBRARIES := android_native_app_glue $(foreach mod, $(OPENCV_MODULES), opencv_$(mod)) $(OPENCV_3RDPARTY_COMPONENTS)
  • 28. ©SIProp Project, 2006-2008 28 Create jni/Android.mk 9/9 Set Library Type Make SO lib BUILD_SHARED_LIBRARY Set Loading Android module Use “native_app_glue” module $(call import-module,android/native_app_glue) 1. include $(BUILD_SHARED_LIBRARY) 2. $(call import-module, android/native_app_glue)
  • 29. ©SIProp Project, 2006-2008 29 Setup/Make Build.xml 1/2 Making Setting File for Android using ANT Today, Development on CUI Only!!! Don’t use Eclipse! › android list target › Available Android targets: › ---------- › id: 1 or "android-9" › Name: Android 2.3.1 › Type: Platform › API level: 9 › Revision: 2 › Skins: WQVGA400, QVGA, HVGA, WVGA800 (default), WVGA854 › ABIs : armeabi › ---------- › id: 2 or "android-18" › Name: Android 4.3 › Type: Platform › API level: 18 › Revision: 2 › Skins: WXGA800, WQVGA400, QVGA, WQVGA432, WXGA800-7in, WVGA800 (default), HVGA, WXGA720, WSVGA, WVGA854 › ABIs : armeabi-v7a › ----------
  • 30. ©SIProp Project, 2006-2008 30 Setup/Make Build.xml 2/2 Make Build.xml › android update project --path . --target 2
  • 31. ©SIProp Project, 2006-2008 31 Build NativeActivity Build C/C++ Source Codes › ndk-build [clean all] Make APK File › ant [debug|release]
  • 32. › adb install bin/NativeActivity-debug.apk › adb uninstall com.example.native_activity ©SIProp Project, 2006-2008 32 Install NativeActivity.apk Install APK File UnInstall APK File Show Log › adb logcat
  • 33. ©SIProp Project, 2006-2008 33 adb(Android Debug Bridge) Functions Shell on Android Device adb shell Show Connected Android Devices adb devices Install/Uninstall APK File adb install/uninstall [App Name]/[Package Name] Send/Get File to/from Android Device adb push/pull [from File Path] [to File Path] Show Log (DDMS) adb logcat
  • 34. ©SIProp Project, 2006-2008 34 Quick Explanation to OpenCL 1. void android_main(android_app* app) { 2. (snip) 3. cv::Mat drawing_frame; 4. (snip) 5. colorSampleImage = imread(file_path); 6. (snip) 7. // Create Mat Object for OpenCL 8. cv::ocl::oclMat oclIn(colorSampleImage), oclOut; 9. // Change Color RGB->Black&White on OpenCL 10. cv::ocl::cvtColor(oclIn, oclOut, cv::COLOR_BGR2GRAY); 11. // Download Mat Object for OpenCL to Mat for CPU 12. oclOut.download(drawing_frame); 13. 14. engine_draw_frame(&engine, drawing_frame);
  • 35. How to Set up OpenCL Driver adreno-3xx: Qualcomm's Adreno 3xx GPUs ©SIProp Project, 2006-2008 35 mali-t6xx: ARM's Mali-T6xx GPUs
  • 36. ©SIProp Project, 2006-2008 36 Download OpenCL Drivers OpenCL Drivers was deleted since 4.2 adreno-3xx: Qualcomm's Adreno 3xx GPUs mali-t6xx: ARM's Mali-T6xx GPUs Download from: https://github.com/madeye/opencl-android-proprietary
  • 37. ©SIProp Project, 2006-2008 37 Set up Drivers to your Android Ex. adreno-3xx: Qualcomm's Adreno 3xx GPUs 1. $ adb push kitkat/system/vendor/lib /sdcard/ 2. $ adb shell 3. $ su 4. # mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system 5. # cp /sdcard/libOpenCL.so /system/vendor/lib/ 6. # cp /sdcard/libllvm-a3xx.so /system/vendor/lib/ 7. # chmod 644 /system/vendor/lib/libOpenCL.so 8. # chmod 644 /system/vendor/lib/libllvm-a3xx.so