Skip to content

Instantly share code, notes, and snippets.

@iago-suarez
Last active July 9, 2025 01:49
Show Gist options
  • Save iago-suarez/13c82b416ce6b07a93b5b6eee6bd29f3 to your computer and use it in GitHub Desktop.
Save iago-suarez/13c82b416ce6b07a93b5b6eee6bd29f3 to your computer and use it in GitHub Desktop.

Revisions

  1. iago-suarez revised this gist Jan 4, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions opencv-opencl-android.md
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,7 @@ The first step in order to be able to execute the [tutorial example](https://git
    ```bash
    # Export your NDK, it will be looked for OpenCV to compile your project. In my case
    export ANDROID_NDK=~/graffter/libs/android-ndk-r10d/

    # Download the necessary code
    cd graffter/libs/
    mkdir contrib_release_armv7a && contrib_release_armv7a
  2. iago-suarez revised this gist Jan 4, 2017. 1 changed file with 2 additions and 4 deletions.
    6 changes: 2 additions & 4 deletions opencv-opencl-android.md
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,8 @@ The tutorial [Use OpenCL in Android camera preview based CV application](http://
    The first step in order to be able to execute the [tutorial example](https://github.com/opencv/opencv/tree/73a8fa8e6e50660a671620563156b8d7cddecf82/samples/android/tutorial-4-opencl) is to re-compile opencv with the correct flags:

    ```bash
    # Export your NDK, it will be looked for OpenCV to compile your project. In my case
    export ANDROID_NDK=~/graffter/libs/android-ndk-r10d/
    # Download the necessary code
    cd graffter/libs/
    mkdir contrib_release_armv7a && contrib_release_armv7a
    @@ -44,10 +46,6 @@ make -j8
    adb install samples/android/tutorial-4-opencl/.build/bin/example-tutorial-4-opencl-debug.apk
    ```
    Notes:
    * I've previous exported the ANDROID_NDK as:
    ```
    export ANDROID_NDK=~/graffter/libs/android-ndk-r10d/
    ```
    * Here I'm compiling with the contrib modules, but if you don't need them just remove the line "-DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \"
    * Here I'm only building the library for ARMv7a devices with NEON support, but you should add other architectures in the string. The full list is:

  3. iago-suarez revised this gist Jan 4, 2017. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions opencv-opencl-android.md
    Original file line number Diff line number Diff line change
    @@ -45,9 +45,9 @@ adb install samples/android/tutorial-4-opencl/.build/bin/example-tutorial-4-open
    ```
    Notes:
    * I've previous exported the ANDROID_NDK as:
    export ANDROID_NDK=~/graffter/libs/android-ndk-r10d/

    ```
    export ANDROID_NDK=~/graffter/libs/android-ndk-r10d/
    ```
    * Here I'm compiling with the contrib modules, but if you don't need them just remove the line "-DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \"
    * Here I'm only building the library for ARMv7a devices with NEON support, but you should add other architectures in the string. The full list is:

  4. iago-suarez revised this gist Jan 4, 2017. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion opencv-opencl-android.md
    Original file line number Diff line number Diff line change
    @@ -45,7 +45,9 @@ adb install samples/android/tutorial-4-opencl/.build/bin/example-tutorial-4-open
    ```
    Notes:
    * I've previous exported the ANDROID_NDK as:
    export ANDROID_NDK=~/graffter/libs/android-ndk-r10d/

    export ANDROID_NDK=~/graffter/libs/android-ndk-r10d/

    * Here I'm compiling with the contrib modules, but if you don't need them just remove the line "-DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \"
    * Here I'm only building the library for ARMv7a devices with NEON support, but you should add other architectures in the string. The full list is:

  5. iago-suarez revised this gist Jan 4, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions opencv-opencl-android.md
    Original file line number Diff line number Diff line change
    @@ -44,6 +44,8 @@ make -j8
    adb install samples/android/tutorial-4-opencl/.build/bin/example-tutorial-4-opencl-debug.apk
    ```
    Notes:
    * I've previous exported the ANDROID_NDK as:
    export ANDROID_NDK=~/graffter/libs/android-ndk-r10d/
    * Here I'm compiling with the contrib modules, but if you don't need them just remove the line "-DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \"
    * Here I'm only building the library for ARMv7a devices with NEON support, but you should add other architectures in the string. The full list is:

  6. iago-suarez revised this gist Dec 24, 2016. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions opencv-opencl-android.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    # Setting Up OpenCL for OpenCV on Android, the full story
    The tutorial [Use OpenCL in Android camera preview based CV application](http://docs.opencv.org/trunk/d7/dbd/tutorial_android_ocl_intro.html) show us how we can use the Transparent API to dramatically increase the performance of some expensive operations.

    The first step in order to be able to execute the [tutorial example](https://github.com/opencv/opencv/tree/73a8fa8e6e50660a671620563156b8d7cddecf82/samples/android/tutorial-4-opencl) is to re-compile opencv with the correct flags:
  7. iago-suarez renamed this gist Dec 24, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  8. iago-suarez created this gist Dec 24, 2016.
    51 changes: 51 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    The tutorial [Use OpenCL in Android camera preview based CV application](http://docs.opencv.org/trunk/d7/dbd/tutorial_android_ocl_intro.html) show us how we can use the Transparent API to dramatically increase the performance of some expensive operations.

    The first step in order to be able to execute the [tutorial example](https://github.com/opencv/opencv/tree/73a8fa8e6e50660a671620563156b8d7cddecf82/samples/android/tutorial-4-opencl) is to re-compile opencv with the correct flags:

    ```bash
    # Download the necessary code
    cd graffter/libs/
    mkdir contrib_release_armv7a && contrib_release_armv7a
    git clone [email protected]:opencv/opencv.git
    mv opencv opencv-3.1.0
    git clone [email protected]:opencv/opencv_contrib.git

    # Creating our custom OpenCL SDK
    export OPENCL_SDK=~/graffter/libs/MotoX_OpenCL_SDK
    mkdir $OPENCL_SDK && cd $OPENCL_SDK
    mkdir lib include
    # Copy the OpenCL headers used to compile OpenCV
    cp -r ~/graffter/libs/opencv-3.1.0/3rdparty/include/opencl/1.2/CL/ include/
    # Download the multiplattaform version of the C++ OpenCL Wrapper
    cd include/CL/ && wget https://www.khronos.org/registry/cl/api/1.2/cl.hpp && cd ../..
    # Connect you OpenCL supported android device and use adb to get the library
    adb pull /system/vendor/lib/libOpenCL.so lib
    # Set the folder where we are going to compile opencv, it will be used when we run the ndk-build of the project
    export OPENCV_ANDROID_SDK=~/graffter/libs/contrib_release_armv7a
    cd $OPENCV_ANDROID_SDK

    # Now configure and compile opencv
    cmake -Wno-dev \
    -DCMAKE_TOOLCHAIN_FILE=../opencv-3.1.0/platforms/android/android.toolchain.cmake \
    -DANDROID_ABI="armeabi-v7a with NEON" \
    -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
    -DBUILD_ANDROID_EXAMPLES=ON \
    -DINSTALL_ANDROID_EXAMPLES=ON \
    -DWITH_OPENCL=YES \
    -DANDROID_OPENCL_SDK=$OPENCL_SDK \
    -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \
    -DANDROID_NATIVE_API_LEVEL=14 \
    -DANDROID_SDK_TARGET=24 \
    ../opencv-3.1.0
    make -j8

    # Now you would be able to install the generated APK with:
    adb install samples/android/tutorial-4-opencl/.build/bin/example-tutorial-4-opencl-debug.apk
    ```
    Notes:
    * Here I'm compiling with the contrib modules, but if you don't need them just remove the line "-DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \"
    * Here I'm only building the library for ARMv7a devices with NEON support, but you should add other architectures in the string. The full list is:

    > armeabi-v7a; armeabi; armeabi-v7a with NEON; armeabi-v7a-hard with NEON; armeabi-v7a with VFPV3; armeabi-v6 with VFP; arm64-v8a x86 x86_64 mips mips64"

    * **-DANDROID_NATIVE_API_LEVEL=14** Is necessary because lower API_LEVEL will cause problems compiling the tutorial-4-opencl [here](https://github.com/opencv/opencv/blob/fbf2383d5dfffeb7c60748be310f86327fb4a335/samples/android/tutorial-4-opencl/CMakeLists.txt#L7).