Objective : I wanted to change my existing OpenCV applications which were written in cpp for desktop version (X_86) processor to an ARM Architecture (imx6). At the initial stage I was not interested to change my cpp applications to java and compile it on Android Studio IDE, Before developing an Android app I wanted to benchmark the imx6 device, is capable to run my OpenCV applications how much time it take to process the video frames etc. So retaining my cpp applications as it is, I wanted to cross compile it for ARM Arch. and run it on Android Device (without GUI ).
I have done this experiment on imx6dl board running marshmallow Android and kernel 4.x.
I have followed many links and blogs to compile and build opencv cpp applications for ARM processor. One good link is https://www.learnopencv.com/install-opencv-on-android-tiny-and-optimized/ all credits goes to above mentioned blog author.
This link is very good for beginners, till step no 8 it is very clearly written and I could follow it but Step no 9 onwards it is not properly written about where to keep demo applications, link & include libraries etc. when I tried step 9 in from that blog & tried to compile demo.cpp, It used to give an error *.hpp not found. I tried all the ways but was not able to solve.
Then I thought that let me first build sample applications comes with opencv sdk. my approach is as shown below.
Build Set-up used
a. Ubuntu 14.04 and installed all the packages mentioned in https://www.learnopencv.com/install-opencv3-on-ubuntu/
link. (link followed for only installation of dependent packages).
b. Download and install NDK r14b
c. Download and install OpenCV 3.4.1
d. Target armeabi-v7a (ARM based) & Android API -23
Steps 1-4 are required for first time setup
Step 1 : Download and Setup NDK :
unzip it and go inside ndk folder.
$ ./build/tools/make_standalone_toolchain.py \ --arch arm \ --api 23 \ --install-dir /my-android-toolchain
Step 2 : Setup ANDROID_NDK Path
$ export ANDROID_STANDALONE_TOOLCHAIN=/my-android-toolchain/
Step 3 Download and Install OpenCV 3.4.1
$ cd opencv/
$ mkdir build
$ cd build
$ cmake -DCMAKE_TOOLCHAIN_FILE=../platforms/android/android.toolchain.cmake -DANDROID_STL=gnustl_shared -DBUILD_EXAMPLES=ON -DANDROID_NATIVE_API_LEVEL=23 ..
(-DBUILD_EXAMPLES=ON is important to build the samples).
$ make -j4
Step 4 Neon and VFPV3 optimizations (optional)
For ARM based devices, optimization i usually enable using: NEON VFPV3 Check out preamble of platforms/android/android.toolchain.cmake for various configuration options.
Step 5 Building your code Go to Working Diretory
$ cd path-to-opencv
Place your newly created cpp file in opencv/samples/cpp/
$ cd build/
$ cmake -DCMAKE_TOOLCHAIN_FILE=../platforms/android/android.toolchain.cmake -DANDROID_STL=gnustl_shared -DBUILD_EXAMPLES=ON -DANDROID_NATIVE_API_LEVEL=23 ..
$ make -j4
Step 6 Copying on android and running
$ cd path-to-opencv
$ adb push build/bin/example_cpp_your_program /system/xbin/
$ adb push build/libs/armeabi-v7a/libgnustl_shared.so /system/lib/ ****(If Required)****
(for me while executing cpp binary it said library not found to link so)
$ adb shell
$ cd /system/xbin/
$ ./example_cpp_your_program
This method perfectly worked on my Android device without using Android Studio IDE.
Yes you are true, openCV project exists in external folder of AOSP but that will create .so (library shared object) I think, correct me if I am wrong !!
For that, user again has to develop Android app right? I don't know how to make use of it. The above method is to use as it is existing C++ applications directly on imx6 Android.
methods I know
1. Using Android Studio build Android App, link OpenCV SDK to Android Studio for building and compiling
2. The above mentioned method using standalone Android NDK and arm toolchain & OpenCV sdk.
Another one what you have mentioned in your reply, I am not very clear about that method. we need to build an android app or one more project in external folder and build it? If you know kindly update.
Thanks & Regards.
Hello Prasanna,
God work!, But in android for MX6 is supported already the openCV.
Regards