Building OpenCV & OpenCV Extra Modules For Android From Source

Background

In my last blog, I described how to set up Android Studio (AS) to work with OpenCV4Android. Initially Android supported ADT plugin in Eclipse. If you are an Eclipse user in Android development, build OpenCV java wrapper for java or simply build OpenCV for C++ API following the respective blogs. You will need standalone SDK for Android in this case. However recently Android announced that their support for ADT plugin in Eclipse has ended and requested all the developments in Eclipse to shift to Android Studio environment.

OpenCV4Android has two forms as follows.

  1. Using OpenCV’s native interface. This would be a little hectic task for a fresh OpenCV starter. You will have to learn NDK stuffs but promising when it comes to performance optimization. Isn’t it nice to code in C++ and make work on a mobile, just forgetting the interconnections?
  2. Using Java-API. This is easier than the native interface. You just need to import OpenCV classes and move on. Not to forget, computations are performed at native level and hence their is a cost in comparably high JNI calls. On the other hand, Java has its own advantage and so does this method.

Both the methods need OpenCV4Android distribution either pre-built one or building from the source. OpenCV4Android pre-built libraries has only modules in OpenCV main repository and if you need more than that, you need a pure building from the source. Though you can build java wrapper for OpenCV using this, the ‘opencv-xxx.jar’ file does not contain android module. Even after you include android in the jar file, you will have to manually configure the dependency setup for AS. Therefore it is again advised to go for a building from the source for Android. Let’s start!

Pre-requisites

  1. Download OpenCV and unzip (say at <opencv-source>)
  2. Download OpenCV extra modules and unzip (say at <opencv-contrib-source>)
  3. Download Android NDK (say at <ndk-dir>)
  4. Download CMake (to say <cmake-dir>) and MinGW (to say <mingw-dir>)
  5. Install Android Studio

 

Configuration

Go to ‘<opencv-source>/platforms’ and create a folder named ‘android_arm’

Run ‘<cmake-dir>/bin/cmake-gui’ set paths as follows.

source and release dir.PNG

Set paths of source and building directories

Press ‘Add Entry’ button in the cmake-gui, add ‘ANDROID_NDK’ as a cmake ‘path’ variable and provide the value as <ndk-dir> (in my case path is ‘C:\android-ndk-r10e’).
Add ‘ANDROID_NDK_HOST_X64’ too and check that.

Set ‘CMAKE_TOOLCHAIN_FILE’ as ‘<opencv-source>/platforms/android/android.toolchain.cmake’.

Press ‘Configure’. Choose ‘MinGW Makefile’ as the compiler and press ‘Finish’. See  whether above configurations are properly set as in the below figures. Keep other settings as it is.

Android settings cmake.PNG

Android Variables in CMake

cmake settings cmake toolchain.PNG

CMake Toolchain Variables in CMake

Building From Source

Go to <mingw-dir>/msys/1.0 and run ‘msys’ bash file.

Navigate to ‘<opencv-source>/platforms/android_arm’ path and run ‘mingw32-make’ command. After completing this, run ‘mingw32-make install’.

java_for_android_3.PNG

OpenCV for Android is built using MinGW

Now you have successfully built OpenCV4Android in ‘<opencv-source>/platforms/android_arm/install/sdk’

Then, import built modules as follows (detailed step-by-step explanation is given in the previous blog)

  1. Launch Android Studio and create a new project selecting File -> New -> New Project…
  2. Go to File -> New -> Import Module… and provide  ‘<opencv-source>/platforms/android_arm/install/sdk/java’. Click ‘Next’ and ‘Finish’.
  3. If there is a Gradle synchronizing error, change the ‘compileSdkVersion’ and others as follows in build.gradle file in openCVLibraryXXX (imported module) folder.
  4. Then add the imported library as a dependency to the ‘app’ module in File->’Project Structure’.
  5. Copy libraries of OpenCV from ‘<opencv-source>/platforms/android_arm/install/sdk/native/libs’ into a newly created folder (jniLibs) in side the ‘app\src\main’ folder.

Additionally; in AS; after you import the module you might experience a gradle build error as follows.

unspecified on project app resolves to an APK archive which is not supported as a compilation dependency.

Therefore modify lines in build.gradle file of imported module as follows.

  1. Replace ‘apply plugin: com.android.application’ as, ‘apply plugin: com.android.library’
  2. Remove the line ‘applicationId “org.opencv”‘

 

OpenCV Extra Modules for Android Studio

Below are the steps to build OpenCV’s extra modules for Android Studio.

Go to each of the extra modules you need (say ‘<opencv-contrib-source>/modules/extra_1’) and open ‘CMakeLists.txt’ file. Find the line containing ‘ocv_define_module’ option.

ocv_define_module(extra_1 opencv some other modules)

Add ‘java’ modules at the end of the parenthesis.

ocv_define_module(extra_1 opencv some other modules java)

If there is no ‘WRAP’ found in the list, add ‘WRAP’ before ‘java’

ocv_define_module(extra_1 opencv some other modules WRAP java)

Open ‘cmake-gui’ and select ‘OPENCV_EXTRA_MODULES_PATH’ under ‘OPENCV’ category and insert ‘<opencv-contrib-source>/modules’

And keep the above ‘cmake-gui’ settings as it is. At run, extra module ‘opencv_bioinspired’ might fail and therefore uncheck that before the configuration in cmake-gui.

Again follow the steps given under sub topic ‘Building From Source’ explained earlier in this blog.

Final Word

Even after all, in your OpenCV 3+; though all the settings, modules and dependencies are set and imported; you might feel something missing after seeing applications launch on the Android device stops unexpectedly as follows.

Package not found

OpenCV Manager package was not found! Try to install it?

This is because initial OpenCV module call points to ‘opencv_java’ instead of ‘opencv_java3’.

To change this, go to openCVLibraryXXX (imported module) -> src -> main -> java -> org -> opencv -> android -> StaticHelper.java.

Find the line,

result &= loadLibrary(“opencv_java”);

and change this as,

result &= loadLibrary(“opencv_java3”);

 

This is the end of this blog and hope you found this useful. Why not you comment below if you think some necessary parts are missing or on something I have done wrong. Good day!

 

Advertisements

112 thoughts on “Building OpenCV & OpenCV Extra Modules For Android From Source

  1. Pingback: Build OpenCV extra modules (tracking, text) for Android open_java build error – Android Java Solution

  2. Thanks a lot. I have been struggling for some time to include the extra modules.
    Updating opencv_contrib/modules//CMakeLists.txt i.e replacing WRAP python (as in the github repo) with WRAP java includes the module in jar.

    Once a again, thanks a lot.

  3. hey… nice post.. but I am facing some problem..

    In “Building From Source” section, after executing ‘mingw32-make install’ my ‘sdk/etc’ and ‘sdk/native’ folders are created inside ‘…/android_arm/install/’ but my ‘sdk/java’ folder is not created.

    I have been stuck here from last 2 days, have repeated all the above mentioned steps twice. Kindly help.

    • Sorry for the late reply.
      I guess you have not properly configured CMake especially Java paths and Ant path. I have described it here. Please try to set paths manually using CMake gui itself. If you have done this properly you will see ‘BUILD_opencv_java’ is checked under BUILD category after pressing ‘Configure’.
      Confirm me whether this works.

      • Yes it worked now.. thank you..

        My Java wrappers: was set to NO.

        Setting the ‘ANT_EXECUTABLE’ under ‘Ungroped Entries’ worked.. Thank you very much !!

        Will now try importing it into Android Studio, will let you know how it went. 🙂

      • I had to also set PYTHON_EXECUTABLE in order to compile java wrappers.

        Different question:

        So in the end everything compiled fine and could be imported to Android Studio. The problem is, that I still can’t build my android project, as the Feature2D class, extended by every java class in xfeatures2D module cannot be found. Did I mess something up compiling OpenCV or is there any additional steps i have to take to use xfeatures2D in my project? Cheers!

      • @christian, You likely to encounter an error “Cannot resolve symbol ‘Feature2D'” in many java files in ‘xfeature2d’ including BriefDescriptorExtractor.java, SIFT.java, SURF.java, FAST.java, BRIEF.java.

        This is because you do not find any Feature2D file in java code base. Feature2D class defined in features2d.hpp file has been aliased to FeatureDetector and DescriptorExtractor using typedef. Therefore, you can appropriately replace all the Feature2D keywords with one of the above. I used DescriptorExtractor for Feature2D as most of the definitions are involved in description.

        For an example, in ‘BriefDescriptorExtractor.java’ file add,
        import org.opencv.features2d.DescriptorExtractor;
        and change ‘public class BriefDescriptorExtractor extends Feature2D {‘ line as,
        public class BriefDescriptorExtractor extends DescriptorExtractor {

        Hope this helps.

      • Replacing Feature2D by DescriptorExtractor did the trick. It works like a charm now. Thank you very much!

      • Glad this works fine. BTW, you should not forget the fact why these are not included in the main opencv repo. These are non-free versions of opencv and most of the time patented. Think twice if you are going for a commercialized product. I guess you are allowed to use these in academic and research purposes. Anyway good day!

      • Thanks for the advice, but it’s just for education/research for now. I’m using BRIEF, which opposed to SIFT/SURF, is not patented as far as I know.

        After my application was initially working with BRIEF I get the same error (error: (-5) Specified descriptor extractor type is not supported.) as before adding _contrib again. But I’ll figure it out, I guess.

        Anyways – thanks for your tutorial and your support afterwards. Great work!

      • i am facing the same issue even after Setting ANT_EXECUTABLE and PYTHON_EXECUTABLE doesn’t fix it. After configuring i see “BUILD_opencv_java” is checked. Is there anything else that might be causing the issue?

  4. Heyy… my compilation completed, but whenever I try to add extra modules, in Cmake-gui configuration it gives error:



    Found apache ant 1.9.7: D:/Android/By_Maam/apache-ant-1.9.7-bin/apache-ant-1.9.7/bin/ant.bat
    Caffe: NO
    Protobuf: NO
    Glog: NO
    CMake Error at E:/MyOpenCVFolder/opencv-master/platforms/android/android.toolchain.cmake:451 (message):
    Could not find neither Android NDK nor Android standalone toolchain.

    You should either set an environment variable:
    export ANDROID_NDK=~/my-android-ndk
    or
    export ANDROID_STANDALONE_TOOLCHAIN=~/my-android-toolchain
    or put the toolchain or NDK in the default path:
    sudo ln -s ~/my-android-ndk C:/Program Files/android-ndk
    sudo ln -s ~/my-android-toolchain /opt/android-toolchain
    Call Stack (most recent call first):
    E:/MyOpenCVFolder/opencv-master/platforms/android_arm/CMakeFiles/3.6.0-rc2/CMakeSystem.cmake:6 (include)
    E:/MyOpenCVFolder/opencv-master/platforms/android_arm/modules/hdf/.hdf/CMakeFiles/hdf5/CMakeFiles/CMakeTmp/CMakeLists.txt:3 (project)

    I have already set ANDROID_NDK in both cmake and System variables, but this error is persistent.

    • @Apar, the error you attached is related with ‘hdf’ (hierarchical data format) module which is a newly added module to opencv_contrib. My first question is “do you really need this?”.

      If not I have a resolution. Just remove the added ‘java’ word in ‘opencv_contrib-master/modules/hdf/CMakeLists.txt’. And now you are free to go. Note that, there can be other modules as well which will result in error when you compile after adding ‘java’ as above. Therefore do not specify ‘java’ in modules unless you have a specific reason to add them.

      “if I need that module?” Oh, good question. But, to build these modules, you should have Caffe (a deep learning framework) and its dependencies like protobuf, glog, hdf5, etc. And now, you would probably be able to compile without any problem.

      • Hi Zamrath. Thanks a lot for your explanation to Apar. I did as you suggested before pressing configure button. E.g, add “java or WRAP java into ocv_define_module(…….python)”, uncheck BUILD_opnecv_bioinspired, remove java in CmakeList.txt of hdf module, add entry of android NDK, etc. Still, I got
        CMake Error at C:/Users/user/Downloads/opencv_source/platforms/android/android.toolchain.cmake:447 (message):
        Could not find neither Android NDK nor Android standalone toolchain.

        You should either set an environment variable:
        export ANDROID_NDK=~/my-android-ndk

        or
        export ANDROID_STANDALONE_TOOLCHAIN=~/my-android-toolchain
        or put the toolchain or NDK in the default path:
        sudo ln -s ~/my-android-ndk C:/Program Files/android-ndk
        sudo ln -s ~/my-android-toolchain /opt/android-toolchain
        Call Stack (most recent call first):
        C:/Users/user/Downloads/opencv_source/platforms/android_arm/CMakeFiles/3.8.2/CMakeSystem.cmake:6 (include)
        C:/Users/user/Downloads/opencv_source/platforms/android_arm/modules/hdf/.hdf/CMakeFiles/hdf5/CMakeFiles/CMakeTmp/CMakeLists.txt:3 (project)

        CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
        CMake Error at C:/Program Files/CMake/share/cmake-3.8/Modules/FindHDF5.cmake:186 (try_compile):
        Failed to configure test project build system.
        Call Stack (most recent call first):
        C:/Program Files/CMake/share/cmake-3.8/Modules/FindHDF5.cmake:462 (_HDF5_test_regular_compiler_C)
        C:/Users/user/Downloads/opencv_contrib/modules/hdf/CMakeLists.txt:3 (find_package)

      • Many thanks for your quick reply in such short time. I will try as you suggested again and exclude the potential errors that hidein some unknown place. If succeeded, I will let you know.

      • Hi Zamrath, I soved this problem. Just try another opencv and contrib versio. Also, you can try different cmake version. Thanks.

    • Hi Apar, I am also facing this problem, I did as Zamarath Nizam said, unfortunately doesn’t work. Did you solve this issue?

  5. Thanks for extraordinary tutorial.

    I have few questions I have followed all steps but there is no SDK folder under /install/ dir.

    I have set path correctly to Java, Python and ant.

    My Java says that java wrappers is on(Yes).

    Java:
    ant: …../opencv/ant-dir/bin/ant.bat (ver 1.9.7)
    JNI: …./Java/jdk1.8.0_92/include C:/Program
    Java wrappers: YES
    Java tests: YES

    Now under install folder I have files like.
    /Install
    -/etc
    -/include
    -/java
    -/x86

    Under Android group I have only 2 entries
    1. Androd_NDK=”path”
    2. ANDROID_NDK_HOST_X84=true

    Please help me I want to build contrib module for my project

    • @androidrocksonmobility, I guess you have not correctly set the tool chain file for android at the start. Please follow the following steps.

      1. Open a new Cmake-gui session (I recommend you to create a new directory (say ‘android_arm_1’) for ‘Where to build the binaries:’).
      2. Click ‘Configure’ button.
      3. In the opening window, select ‘MinGW Makefiles’ in ‘Specify the generator for this project’.
      4. *** Choose the ‘Specify toolchain file for cross-compiling’ option from the available 4 options.
      5. Click ‘Next’.
      6. Browse and select the toolchain in the path ‘/platforms/android/android.toolchain.cmake’
      7. Click ‘Finish’

      You would see lot more options under ‘ANDROID’ category now. Now you can proceed with the steps you have followed in this blog. Happy coding!

      • Hi Zamrath Nizam Thanks for your reply, I am able to build it. issue fixed with flag ANDROID_NATIVE_API_LEVEL=12.

        Now when I try to build it with extra modules configuration is failed I only need contrib_world module.
        Added OPENCV_EXTRA_MODULES_PATH=…..\opencv-contrib-source\modules.

      • In short, opencv_world is a custom wrapper module which contains modules specified by the user (default, all modules; I guess) and needs other dependencies (such as MATLAB) which should be available in your system. If any of the dependency is not found, complete compilation is not guaranteed.

        My question is “Why do you need opencv_world? do you have any concrete reason for that?”. I would recommend you to uncheck “BUILD_opencv_world” and “BUILD_opencv_contrib_world” and explicitly select modules you need.

      • I have followed these instructions and now I get an error saying “CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.5/Modules/TestBigEndian.cmake:51 (message):
        no suitable type found”

      • Sorry for the late reply. Hope you have resolved this days back. BTW, normally you encounter this kind of issue when you are trying to build on a previously built area. First remove the ‘CMakeFiles’ folder in the path ‘platform/android_arm/’. Now you can build freshly.

  6. Thanks I am able to compile with extra modules, I made mistake on line “ocv_define_module” now I have dinal opencv sdk, I required opencv_contrib because.
    I am getting No such file or directory #include “opencv2/contrib/contrib.hpp” when compiling my project with opencv4android sdk 3.1

    • Hi Nizam, I have to build it for various platforms.
      armeabi-v7a, armeabi, mips, x86, mips64, x86_64

      I CMake under ANDROID_ABI it has options like (armeabi-v7a,armeabi, armeabi-v7a NEON…etc) there is no x86 and mips.

      When I add it manually in cmake like ANDROID_ABI=x86 configure and generate is successfull.
      But mingw32-make failed with fatal error: machine/cpu-features.h No such file or directory.
      MIPS is also failed I doubt I need to take another opencv-source or toolchain please help thanks in advance.

  7. Hi Nizam, I’m following your tutorial to build module legacy for android (opencv_2.4.9, android-ndk-r10e, cmake 3.6.0) but I stuck at Configuration step with some CMake errors at /platforms/android/android.toolchain.cmake
    1/ line 827: “list index: 8 out of range (-8, 7)”
    2/ line 711: “list sub-command REMOVE_DUPLICATES requires list to be present”
    3/ line 712: “list sub-command SORT requires list to be present”
    4/ line 718: “No one of known Android ABIs is supported by this cmake toolchain”
    You can see full CMake log at this file (https://drive.google.com/file/d/0B0Rrb8XjkC2kSWMyQ0JDYjhQTDQ/view?usp=sharing)
    I tried 7 steps you answered for androidrocksonmobility’s question but nothing chaged. Could you help me fix those errors? Tks in advance 🙂

    • Your opencv version should be compatible with the android-ndk version you are using. I suspect -r10e version of android-ndk supports old opencv 2.4.9. You can check this using ‘platforms/android/android.toolchain.cmake’ in which a list of supported ndk versions should be available under ‘# NDK search paths’.

      If you do not find -r10e (what you currently have) in the list, either upgrade your opencv (latest) or use a supportive old android-ndk version. Then try configuring again. Ping me back if the problem still persists.

      • Sorry for the delayed response. Weekend was bit busy. I hope you have already figured out the problem. If not I have the following suggestions for you.

        Please keep in mind you need appropriate JDK, Ant and Python 2.6+ installed and properly configured. I see you have configured Ant and JDK properly. What about python?

        If the python is okay but problem still persists, downgrade jdk 1.8 to 1.7 and try. Even I have not tested this I suspect a version compatibility issue as there were some problems related to jdk 1.8 with opencv 2.4.9.

        I would strongly suggest you to upgrade opencv to a latest version. I don’t see any specific reason you to stay there. latest versions have more resources in case you are facing with a problem. BTW point me out if the problem does not resolve with these.

      • Dear Nizam, I tried configuring cmake with several combinations: {jdk 1.7 – opencv 2.4.9} , {jdk 1.7 – opencv opencv 2.4.13} , {jdk 1.8 – opencv 2.4.13} but none worked. Upgrading to opencv 3.1 and jdk 1.8 can perfectly do the cmake config.

        However, I want to keep using opencv 2.4.x because in opencv 3 module “legacy” is removed, and it contains the functions calculating GLCM (texture.cpp) used in my project. The problem appears when I port my app from windows to android, OpenCV4Android does not have those functions either so I must build opencv libs for android from source. Do you have any idea to solve this?

      • I prefer you jdk 1.8 + opencv 3.1 combination. And I have two suggestions.

        1. Though legacy is removed, you can still use some of its old codes with little modifications. You can find how GLCM (what your project needs) can be used with the latest versions of opencv in this.

        2. On the other hand, ‘legacy’ is gone for good. There are concerns over GLCM related texture descriptors and suggestions to use alternatives as described here. It is up to you to decide whether these alternatives suit to your project.

  8. I did all steps above but I didn’t see Java Wrapper. All I could see in “Java:” is ant: C:/ant/bin/ant.bat (ver 1.9.7) and Java tests: YES. Did I mess something up or is there any additionals steps I have to take?

  9. Hi Nizam, followed your tutorial and built opencv4Android. Somehow build with extra module was failed but I managed it by copying required modules to opencv-source\modules folders.
    Now I have to build it for various platforms.
    armeabi-v7a
    armeabi
    mips
    x86
    mips64
    x86_64

    I CMake under ANDROID_ABI it has options like (armeabi-v7a,armeabi, armeabi-v7a NEON…etc) there is no x86 and mips.

    When I add it manually in cmake like ANDROID_ABI=x86 configure and generate is successfull.
    But mingw32-make failed with fatal error: machine/cpu-features.h No such file or directory.
    MIPS is also failed I doubt I need to take another opencv-source or toolchain please help thanks in advance.

    • Looks like current toolchain does not support cross compiling to mips through your OS. I have no specific answer for you in this regard as I am not much exposed to this setup. Sorry.

  10. Hi Nizam, thanks for the great set of tutorials! However, I have a problem that I am stuck with for 2 days now, and it’s really frustrating…

    I’m using OpenCV 3.1 and CMake 3.4, alongside MinGW.

    My compilation of extra modules crashes with [javac] errors in all xfeatures2d java files. It states that Feature2D class is undefined, along with some other symbols in those files like nativeObj. I tried adding import org.opencv.features2d.Feature2D line in each java file but the error is still there, class Feature2D is unknown.

    Compilation of only standard modules runs perfectly and I can use them in my android applications. But after I add OPENCV_EXTRA_MODULES_PATH to my CMake configurations and run mingw32-make command I get those errors stated above.

    Please let me know if there is a way around this problem. Thanks in advance!

      • Thanks, I successfully built the whole library now!

        However, a new problem has emerged. My app crashes when I call functions from xfeatures2d, e.g. SIFT sift = SIFT.create(). There apparently is some problem when calling native functions.

        I compared names of declared native functions to their JNI definitions in xfeatures2d.cpp. In java files they’re called create_0 and create_1, while in JNI it’s create_10 and create_11. I tried matching those names but it didn’t work out. I am using Eclipse btw.

        Please let me know if anything comes to mind. Thanks in advance!

      • Hi Predrag, Sorry for the delayed answer. Hope you have resolved this in between. I also had bit of a hard time at finding a break through and have a little clue to your question. Try calling SIFT using ‘detect’ and ‘extract’ functions instead of ‘create’ though this might not well fit into your requirement. Sorry again!

  11. very helpful blog. I’m trying to reproduce the process to build the android sdk on ubuntu. Everything looks fine but the android sdk does not get generated. What am I missing ?

  12. Thanks for the tutorial.
    But can you please make it on youtube? I am new to this and I don’t know how to do the configuration part.

    • Sorry kimof. Still I have not planned to make this youtube. However you can try my previous blogs as well as other internet sources. And if you found any issues first read the comment section and if you are still not satisfied, ask here. Thanks …

  13. Thank you very much for the tutorial!

    I followed the steps but using mac instead. The generator is Unix. The other variables are all the same. I also wrap the library with java wrapper successfully. But I get only a bunch of java files instead of a android module with build.gradle file. May I ask that why did I get this result?

  14. I followed your phenomenal directions (as well as the directions under your blog “Building Java Wrapper For OpenCV”) and I get an error when I run the mingw32-make command. After it builds to about 90% while generating opencv-310.jar, it says “‘java.exe’ is not recognized as an internal or external command, operable program or batch file”. I had looked for a solution online and all I’m finding is that I should set all of the enviroment varaibles correctly, which i did but it still gives me that error

  15. Thank you for the blog post, but I have some trouble installing built OpenCV into Android Studio.

    After I successfully built it, I installed OpenCV into Android Studio (via Add Module), copied jniLibs folder, and tried using it via wrapper. It works. Then, I want to use OpenCV natively. So I created the file Android.mk with the content as below:

    LOCAL_PATH := $(call my-dir)

    include $(CLEAR_VARS)

    LOCAL_MODULE := opencv_test
    LOCAL_SRC_FILES := C:/opencv_test/jni/test.cpp

    include $(BUILD_SHARED_LIBRARY)

    And Application.mk:

    APP_PROJECT_PATH := C:/opencv_test
    APP_STL := gnustl_static

    And built the created module with “Link C++ Project with Gradle” command of the Android Studio. Building operation was OK; the test.cpp file had been imported. Then I just made a reference to Mat by simply wrote the test.cpp as this:

    #include
    #include
    #include “opencv2/core.hpp”

    using namespace cv;
    using namespace std;

    extern “C” JNIEXPORT void JNICALL Java_com_kpastudio_myapplication_MainActivity_test(JNIEnv* env, jobject obj, long imgAddr)
    {
    vector channels;
    }

    Then built the module. The build operation wasn’t successful and showed an error:

    Error:(687) undefined reference to ‘cv::Mat::deallocate()’
    Error:(575) undefined reference to ‘cv::fastFree(void*)’

    I think it occurred because I didn’t tell the linker what OpenCV library I will use, but I don’t know how to do it. How can I solve this trouble?

    Thank you

  16. Everything works OK for me except that I don’t get a “sdk” folder in the “install” directory after “mingw32-make install”. I did follow the steps in Building Java Wrapper for OpenCV and here is my Cmake configure log:

    Python 2:
    Interpreter: D:/Tools/Python27/python.exe (ver 2.7.13)

    Python 3:
    Interpreter: D:/Tools/Python36/python.exe (ver 3.6)

    Python (for build): D:/Tools/Python27/python.exe

    Java:
    ant: D:/Tools/apache-ant-1.9.8/bin/ant.bat (ver 1.9.8)
    JNI: C:/Program Files/Java/jdk1.8.0_111/include C:/Program Files/Java/jdk1.8.0_111/include/win32 C:/Program Files/Java/jdk1.8.0_111/include
    Java wrappers: YES
    Java tests: YES

    Matlab:
    mex: NO

    Documentation:
    Doxygen: NO
    PlantUML: NO

    Tests and samples:
    Tests: YES
    Performance tests: YES
    C/C++ Examples: NO

    Install path: D:/Library/opencv/sources/platforms/android_arm/install

    cvconfig.h is in: D:/Library/opencv/sources/platforms/android_arm
    —————————————————————–

    • I also noticed that, even I manually set the JAVA_JVM_LIBRARY:FILEPATH=C:/Program Files/Java/jdk1.8.0_111/lib/jvm.h, after press “Configure”, it will go back to JAVA_JVM_LIBRARY:FILEPATH=C:/Program Files/Java/jdk1.8.0_111/lib/jvm.lib

      • Please make sure the JAVA_JVM_LIBRARY pointing to ‘jni.h’ file not ‘jvm.h’ file. Check whether ‘BUILD_opencv_java’ is checked after configuration. Please refer this for further reference.

  17. Hi,

    I’ve followed your steps here and those listed in the linked blogs and I’ve gotten to the point where I can load openCV as a module in Android Studio. But I’m confused by which OpenCV I’m supposed to be using. At one point you link to a GitHub repository and call it OpenCV but in another place, and other blog posts, you call it OpenCV4Android. Both of these are link to different places and are different files entirely. So which one should I be using to utilize openCV in Android Studio? Because right now I import /platforms/android_arm/install/sdk/java and I get an error about library dependence or something.

    I’ve previously managed to use OpenCV in Android just fine by using a zip file download called OpenCV-android-sdk and I imported it to Android Studio like how you’ve described. The reason I’m going through the trouble of building OpenCV myself is because the way I initially did it, before reading your blog, doesn’t allow me to use the EigenFaceRecognizer functions. So I found your blog post because it provides a way to add additional modules that aren’t included by default. I’ve been trying to follow it as best as I can for the past few days. I’m inexperienced when it comes to building the software myself so I hope you can help clear this up for me.

    • Hi Skips,
      OpenCV4Android is a pre-built library which is a wrapper around native opencv. We can still build this using cloned opencv from GitHub repo which will eventually be a local-version of OpenCV4Android. What you are loading into AS is sdk either as ‘/platforms/android_arm/install/sdk/java’ (in opencv building from source) or as ‘\OpenCV-android-sdk\sdk\java’ (in pre-built version). In either case, these are java wrappers which point to NDK of opencv but may be at different places as per your steps taken at configuration. I hope this clears your confusion over opencv and OpenCV4Android.

      If you need functions in opencv_main, you do not need building-from-source sdk rather you get this from here. Or if you need it from building-from-source; what you demand here, I believe; do this as per the instruction in this blog.

      What is the type of error you encountered? Is it specific to gradle build error? Then modify lines in build.gradle file of imported module as follows.
      Replace ‘apply plugin: com.android.application’ as, ‘apply plugin: com.android.library’
      Remove the line ‘applicationId “org.opencv”‘
      And I hope that you have correctly configured build.gradle file as described here.
      If this doesn’t answer your query, please let me know.

  18. Pingback: Build OpenCV4Android with Non-free Modules | Code Stuff

  19. Hi, its extra ordinary article, i have read all of this article and yeah thats get some great value.
    but i still have some issues after make install folder using mingw32 for the sdk, when i tried to import module android studio said no module of android studio or eclipse detect. how could i fixed them?

    • Hi calvin, Sorry for the late reply. BTW, I hope you have resolved this by now.
      If not, please let me know the exact warning message you got from android studio when importing modules.

  20. CMake Error: CMake was unable to find a build program corresponding to “MinGW Makefiles”. CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
    CMake Error: CMake was unable to find a build program corresponding to “MinGW Makefiles”. CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
    Configuring incomplete, errors occurred!

    I’m stuck at this point. can you please help me further.

  21. Hi, I’ve been trying to get OpenCV’s extra modules to work for an OCR application, but after running Minw32-make, there’s no Java folder under Android-arm’s sdk folder. When looking at the cmake file, it has Java-wrappers/tests set to “NO”, despite giving it the ANT.bat and python (2.7). I don’t know if this is unrelated, but any help would be greatly appreciated. Thank you

  22. edit: now the right topic, pls delete my other post.

    Hello from Germany!

    First of all, thank you very much for your great tutorial. You made the core steps pretty clear to understand.
    I have the same problem, asked previously by another one. I need to setup my openCV app for multiple architectures. With your tutorial its only possible to chose one architecture. But in the opencv4Android source there are prebuilds for armeabi-v7a, x86, mips and so on.
    I figured out i can use the opencv python cross compile script, to make the buildprocess too. But again there is only one possible architecture to choose.
    Do you know how to produce output for lets say armeabi-v7a AND x86?

    Best regards

    • Hi Andre,
      Glad that you found this blog useful.
      Yes. You can either specify each of the intended architecture in ‘ANDROID_ABI’ option and build opencv for each. Or specify ‘all’ without quotes in ‘ANDROID_ABI’. Of course I have never tried this, but hope this will work. Or you can make use of a script to run only desired builds for different architectures.

      • Thank you for your fast response Nizam!

        so, just for unterstanding: if I do the same build process for each architecture, the only difference in build-output-folder should be the native lib folder which contains the .so file for this arch, right?
        i’m asking, because i already did the long build process, started my app, and ask myself if i have to reimport the whole opencv library or just need to copy the new arch folder with the .so file into my project
        thanks for your work again! Blog subscribed

      • Hi Sanders,
        Yes exactly. Native libraries are specific to each architecture. Using the same imported opencv library module, you can use different architectures (copied from ‘install/sdk/native/libs’ into ‘app/src/main/jniLibs’ folder).

  23. Hi,when I add all those staff and run configure in CMake,it runs into the following errors:
    CMake Deprecation Warning at CMakeLists.txt:81 (cmake_policy):
    The OLD behavior for policy CMP0020 will be removed from a future version
    of CMake.

    The cmake-policies(7) manual explains that the OLD behaviors of all
    policies are deprecated and that a policy should be set to OLD only under
    specific short-term circumstances. Projects should be ported to the NEW
    behavior and not rely on setting a policy to OLD.

    CMake Deprecation Warning at CMakeLists.txt:85 (cmake_policy):
    The OLD behavior for policy CMP0022 will be removed from a future version
    of CMake.

    The cmake-policies(7) manual explains that the OLD behaviors of all
    policies are deprecated and that a policy should be set to OLD only under
    specific short-term circumstances. Projects should be ported to the NEW
    behavior and not rely on setting a policy to OLD.

    CMake Deprecation Warning at CMakeLists.txt:94 (cmake_policy):
    The OLD behavior for policy CMP0026 will be removed from a future version
    of CMake.

    The cmake-policies(7) manual explains that the OLD behaviors of all
    policies are deprecated and that a policy should be set to OLD only under
    specific short-term circumstances. Projects should be ported to the NEW
    behavior and not rely on setting a policy to OLD.

    CMake Error: CMake was unable to find a build program corresponding to “MinGW Makefiles”. CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
    CMake Error: CMake was unable to find a build program corresponding to “MinGW Makefiles”. CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
    CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
    CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage

    Do you have any suggestions?
    Best regards

  24. Hi!

    First, I have to say a big THANK YOU to this great great tutorial which was more than useful for me!!!!! 🙂

    But I have one question that is essential for me.
    I built OpenCV with OpenCV_Contrib because I´m in need of the Random Calibration Pattern functionality of module CCalib which I want to use in my Android application. The whole building process worked fine but unfortunately in my CCalib.java file there are just standard functions to e.g. undistort images. All of the new stuff for creating Random Patterns with corner detection, omnidirectional camera calibration, etc… is missing (see functions of e.g. randpattern.hpp).

    Please, can you tell me which steps I have missed? Is there some modification which I have to do in CMakeLists.txt of the module´s Cmake file?

    Thank you so much in advance and best wishes!

      • Hi!
        No problem! 🙂

        No, unfortunately not…
        I have re-implemented the functions of need (included in ccalib) in Java so I can use for my Android project.

        Nevertheless, do you have an idea how to solve the issue with compliation?

        All the best, M.Noir.

      • Hi Noir, I have no idea on the compilation issues you are currently facing.
        BTW, coding point of view, it is nothing but Java. You can just play around with the backend C++ wrapper using Java as what you might do normally.
        Please refer this for an overview of a simple example.

  25. Hello,
    I tried to follow your manual, but I have got an error during “Building CXX object modules/java/CmakeFiles/opencv_java.dir/gen/reg.cpp.o” after submitting mingw32-make command in MINGW32…
    Error said: Fatal error: opencv2/reg.hpp: No such file or directory
    #include “opencv2/reg.hpp”

    Do you have any idea what could be wrong with z Cmake settings please? I think, the java/reg.cpp is generated during the command, but I have no idea what can be wrong with it and I did not find any ticket about this .hpp file

    Thank you very much

  26. I was able to follow your instructions and was able to import extra modules to android studio. but my question is will all of the imported extra modules work in android automatically? or do i have to setup the .so files etc? i was trying the face recognition module and it gives me errors when i try to instantiate it. i am still new to android and opencv so any help is much appreciated.
    Thanks

      • Yes I was able to follow the steps correctly and the compilation was a success, but when I instantiated the FaceRecognizer class i get the error “FaceRecognizer(long) has protected access in org.opencv.face.FaceRecognizer” i tried making it public but more errors then start to appear.

  27. Hi, I tried to run this.. but I am unable to see any “mingw32-make” command in android-arm folder… shell throws error:-command not found. pls help.

      • Thanks … Now I am stuck at this…

        [ 92%] Generating src/org/opencv/aruco/DetectorParameters.java

        [ 92%] Generating src/org/opencv/aruco/Dictionary.java

        [ 92%] Generating src/org/opencv/aruco/GridBoard.java

        [ 92%] Generating OpenCV Android library project. SDK target: lib_target_sdk_target-NOTFOUND

        **************************************************************************

        The “android” command is deprecated.

        For manual SDK, AVD, and project management, please use Android Studio.

        For command-line tools, use tools\bin\sdkmanager.bat

        and tools\bin\avdmanager.bat

        **************************************************************************

        Invalid or unsupported command “–silent create lib-project –path “D:/ashish/softwares/opencv-master/platforms/android_arm” –target “lib_target_sdk_target-NOTFOUND” –name OpenCV –package org.opencv”

        Supported commands are:

        android list target

        android list avd

        android list device

        android create avd

        android move avd

        android delete avd

        android list sdk

        android update sdk

        modules\java\CMakeFiles\opencv_java.dir\build.make:1337: recipe for target ‘build.xml’ failed

        mingw32-make[2]: *** [build.xml] Error 1

        CMakeFiles\Makefile2:8067: recipe for target ‘modules/java/CMakeFiles/opencv_java.dir/all’ failed

        mingw32-make[1]: *** [modules/java/CMakeFiles/opencv_java.dir/all] Error 2

        Makefile:161: recipe for target ‘all’ failed

        mingw32-make: *** [all] Error 2

  28. Hi Zamrath, thanks for the blog. it seems everything works well, but when I try to build opencv extra contribute modules , i am facing this issue , Mentioned below (Occurs in Cmake GUI LOG)
    Disabled by dependency: ximgproc

    Any idea ????

  29. Hi .. I solved this. Actually the problem was that “android.bat” command is deprecated in latest sdk and only limited options are available for it. So just use a downgraded version of android.bat and make sure it’s path is changed in CMAKE as well.

    Now what I am facing is.. Even after I have manually added extra modules to openCV, I am still unable to use SIFT, SURF feature. Is it not available/patented only for java? Can we use it via JNI/C++ code in android? or all kind of its use are patented? I only want to use for research purpose.. how can I do it?

  30. When I navigate to ‘/platforms/android_arm’ path and run ‘mingw32-make’ command,it show ‘No targets specified and no makefile found,stop.’ Can you help me,thanks

    • Hi Wei,
      This happens normally when you don’t have makefile in the directory where you are running ‘mingw32-make’. Did you properly configure everything before this step? Please let me know your version of OpenCV, cmake and details of OS.

  31. Hello. I am having a problem creating the sdk. The java folder isn’t generated after doing mingw32-make install. I have followed the steps several times, and made sure that my ant and java paths are correctly set. I also have tried adding the PYTHON_EXECUTABLE to cmake, but got the same problem. I also checked my cmake after configuration, and build java wrappers was set to yes and build_opencv_java and build_fat_java_lib were both checked. I’ve been struggling for a couple weeks now and would appreciate any help you can offer

  32. Hi,i want to compile opencv with ffmpeg-supported for Android, but get some trouble during compiling, with different vision,i got different errors.

    Can you clarify the vision you used in the article?Thanks.

    (I used: ndk 10d, cmake 3.4, opencv 3.0.0).

    • Hi Lee,
      As you might have already observed, I have used ndk 10e, opencv 3.0.0. And I actually forgot the version of cmake, I experimented while compiling this blog. However as the recent results stand, it should work well with cmake 3.4 too.

  33. Pingback: Installing Open CV with extra modules of Android Studio | Question

  34. Pingback: Installing Open CV with extra modules of Android Studio – program faq

  35. Pingback: Installing Open CV with extra modules on Android Studio | Question

  36. HI, i have a errors… and i can’t solve it could u help me?

    version info
    opencv : 3.3.0
    opencv_contrib : 3.0.0
    cmake : 3.11.1

    here is my cmake logs
    ———————————————————————————————-
    CMake Deprecation Warning at CMakeLists.txt:81 (cmake_policy):
    The OLD behavior for policy CMP0020 will be removed from a future version
    of CMake.

    The cmake-policies(7) manual explains that the OLD behaviors of all
    policies are deprecated and that a policy should be set to OLD only under
    specific short-term circumstances. Projects should be ported to the NEW
    behavior and not rely on setting a policy to OLD.

    CMake Deprecation Warning at CMakeLists.txt:85 (cmake_policy):
    The OLD behavior for policy CMP0022 will be removed from a future version
    of CMake.

    The cmake-policies(7) manual explains that the OLD behaviors of all
    policies are deprecated and that a policy should be set to OLD only under
    specific short-term circumstances. Projects should be ported to the NEW
    behavior and not rely on setting a policy to OLD.

    CMake Deprecation Warning at CMakeLists.txt:94 (cmake_policy):
    The OLD behavior for policy CMP0026 will be removed from a future version
    of CMake.

    The cmake-policies(7) manual explains that the OLD behaviors of all
    policies are deprecated and that a policy should be set to OLD only under
    specific short-term circumstances. Projects should be ported to the NEW
    behavior and not rely on setting a policy to OLD.

    CMake Deprecation Warning at CMakeLists.txt:102 (cmake_policy):
    The OLD behavior for policy CMP0046 will be removed from a future version
    of CMake.

    The cmake-policies(7) manual explains that the OLD behaviors of all
    policies are deprecated and that a policy should be set to OLD only under
    specific short-term circumstances. Projects should be ported to the NEW
    behavior and not rely on setting a policy to OLD.

    Detected version of GNU GCC: 49 (409)
    Looking for ccache – not found
    Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
    Found apache ant 1.9.11: E:/opencv/apache-ant-1.9.11-bin (1)/apache-ant-1.9.11/bin/ant.bat
    CMake Warning at CMakeLists.txt:626 (message):
    OpenCV requires Android SDK tools revision 14 or newer. Otherwise tests
    and samples will no be compiled.

    Caffe: NO
    Protobuf: NO
    Glog: NO
    freetype2: NO
    harfbuzz: NO
    Module opencv_ovis disabled because OGRE3D was not found
    No preference for use of exported gflags CMake configuration set, and no hints for include/library directories provided. Defaulting to preferring an installed/exported gflags CMake configuration if available.
    Failed to find installed gflags CMake configuration, searching for gflags build directories exported with CMake.
    Failed to find gflags – Failed to find an installed/exported CMake configuration for gflags, will perform search for installed gflags components.
    Failed to find gflags – Could not find gflags include directory, set GFLAGS_INCLUDE_DIR to directory containing gflags/gflags.h
    Failed to find glog – Could not find glog include directory, set GLOG_INCLUDE_DIR to directory containing glog/logging.h
    Module opencv_sfm disabled because the following dependencies are not found: Eigen Glog/Gflags
    Excluding from source files list: C:/Users/sms28/Documents/ssibal/test2/opencv/modules/core/src/convert.avx2.cpp
    Excluding from source files list: C:/Users/sms28/Documents/ssibal/test2/opencv/modules/core/src/convert.fp16.cpp
    Excluding from source files list: C:/Users/sms28/Documents/ssibal/test2/opencv/modules/core/src/convert.sse4_1.cpp
    Excluding from source files list: C:/Users/sms28/Documents/ssibal/test2/opencv/platforms/android_arm/modules/core/mathfuncs_core.sse2.cpp
    Excluding from source files list: C:/Users/sms28/Documents/ssibal/test2/opencv/platforms/android_arm/modules/core/mathfuncs_core.avx.cpp
    Excluding from source files list: C:/Users/sms28/Documents/ssibal/test2/opencv/platforms/android_arm/modules/core/mathfuncs_core.avx2.cpp
    Excluding from source files list: C:/Users/sms28/Documents/ssibal/test2/opencv/platforms/android_arm/modules/core/stat.sse4_2.cpp
    Excluding from source files list: C:/Users/sms28/Documents/ssibal/test2/opencv/platforms/android_arm/modules/core/stat.avx2.cpp
    Excluding from source files list: C:/Users/sms28/Documents/ssibal/test2/opencv/modules/imgproc/src/corner.avx.cpp
    Excluding from source files list: C:/Users/sms28/Documents/ssibal/test2/opencv/modules/imgproc/src/filter.avx2.cpp
    Excluding from source files list: C:/Users/sms28/Documents/ssibal/test2/opencv/modules/imgproc/src/imgwarp.avx2.cpp
    Excluding from source files list: C:/Users/sms28/Documents/ssibal/test2/opencv/modules/imgproc/src/imgwarp.sse4_1.cpp
    Excluding from source files list: C:/Users/sms28/Documents/ssibal/test2/opencv/modules/imgproc/src/undistort.avx2.cpp
    Excluding from source files list: C:/Users/sms28/Documents/ssibal/test2/opencv/platforms/android_arm/modules/imgproc/accum.sse2.cpp
    Excluding from source files list: C:/Users/sms28/Documents/ssibal/test2/opencv/platforms/android_arm/modules/imgproc/accum.avx.cpp
    Excluding from source files list: C:/Users/sms28/Documents/ssibal/test2/opencv/platforms/android_arm/modules/imgproc/accum.neon.cpp
    Excluding from source files list: C:/Users/sms28/Documents/ssibal/test2/opencv/modules/objdetect/src/haar.avx.cpp
    Excluding from source files list: C:/Users/sms28/Documents/ssibal/test2/opencv/platforms/android_arm/modules/dnn/layers/layers_common.avx.cpp
    Excluding from source files list: C:/Users/sms28/Documents/ssibal/test2/opencv/platforms/android_arm/modules/dnn/layers/layers_common.avx2.cpp
    Torch importer has been enabled. To run the tests you have to install Torch (‘th’ executable should be available) and generate testdata using opencv_extra/testdata/dnn/generate_torch_models.py script.
    CMake Warning at cmake/OpenCVDetectAndroidSDK.cmake:205 (message):
    Can not find any SDK target compatible with: 9 11

    The project example-15-puzzle will not be build
    Call Stack (most recent call first):
    samples/android/15-puzzle/CMakeLists.txt:3 (add_android_project)

    CMake Warning at cmake/OpenCVDetectAndroidSDK.cmake:205 (message):
    Can not find any SDK target compatible with: 9 11

    The project example-face-detection will not be build
    Call Stack (most recent call first):
    samples/android/face-detection/CMakeLists.txt:9 (add_android_project)

    CMake Warning at cmake/OpenCVDetectAndroidSDK.cmake:205 (message):
    Can not find any SDK target compatible with: 9 11

    The project example-image-manipulations will not be build
    Call Stack (most recent call first):
    samples/android/image-manipulations/CMakeLists.txt:3 (add_android_project)

    CMake Warning at cmake/OpenCVDetectAndroidSDK.cmake:205 (message):
    Can not find any SDK target compatible with: 9 11

    The project example-camera-calibration will not be build
    Call Stack (most recent call first):
    samples/android/camera-calibration/CMakeLists.txt:3 (add_android_project)

    CMake Warning at cmake/OpenCVDetectAndroidSDK.cmake:205 (message):
    Can not find any SDK target compatible with: 9 11

    The project example-color-blob-detection will not be build
    Call Stack (most recent call first):
    samples/android/color-blob-detection/CMakeLists.txt:3 (add_android_project)

    CMake Warning at cmake/OpenCVDetectAndroidSDK.cmake:205 (message):
    Can not find any SDK target compatible with: 9 11

    The project example-tutorial-1-camerapreview will not be build
    Call Stack (most recent call first):
    samples/android/tutorial-1-camerapreview/CMakeLists.txt:3 (add_android_project)

    CMake Warning at cmake/OpenCVDetectAndroidSDK.cmake:205 (message):
    Can not find any SDK target compatible with: 9 11

    The project example-tutorial-2-mixedprocessing will not be build
    Call Stack (most recent call first):
    samples/android/tutorial-2-mixedprocessing/CMakeLists.txt:9 (add_android_project)

    CMake Warning at cmake/OpenCVDetectAndroidSDK.cmake:205 (message):
    Can not find any SDK target compatible with: 9 11

    The project example-tutorial-3-cameracontrol will not be build
    Call Stack (most recent call first):
    samples/android/tutorial-3-cameracontrol/CMakeLists.txt:3 (add_android_project)

    Sample example-tutorial-4-opencl is disabled, because ANDROID_OPENCL_SDK is not specified

    General configuration for OpenCV 3.3.0 =====================================
    Version control: 3.3.0

    Extra modules:
    Location (extra): C:/Users/sms28/Documents/ssibal/opencv_contrib/modules
    Version control (extra): 3.4.1-97-ga7981278-dirty

    Platform:
    Timestamp: 2018-05-22T04:17:48Z
    Host: Windows 10.0.17134 AMD64
    Target: Android 1 armv7-a
    CMake: 3.11.1
    CMake generator: MinGW Makefiles
    CMake build tool: C:/MinGW/bin/mingw32-make.exe
    Configuration: Release

    CPU/HW features:
    Baseline:
    requested: DETECT
    disabled: VFPV3 NEON

    C/C++:
    Built as dynamic libs?: NO
    C++ Compiler: C:/Users/sms28/Documents/opencv/android-ndk-r14b/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++.exe (ver 4.9.0)
    C++ flags (Release): -fexceptions -frtti -fpic -Wno-psabi –sysroot=C:/Users/sms28/Documents/opencv/android-ndk-r14b/platforms/android-9/arch-arm -funwind-tables -finline-limit=64 -fsigned-char -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fdata-sections -ffunction-sections -Wa,–noexecstack -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -fomit-frame-pointer -mfp16-format=ieee -fvisibility=hidden -fvisibility-inlines-hidden -mthumb -fomit-frame-pointer -fno-strict-aliasing -O3 -DNDEBUG -DNDEBUG
    C++ flags (Debug): -fexceptions -frtti -fpic -Wno-psabi –sysroot=C:/Users/sms28/Documents/opencv/android-ndk-r14b/platforms/android-9/arch-arm -funwind-tables -finline-limit=64 -fsigned-char -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fdata-sections -ffunction-sections -Wa,–noexecstack -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -fomit-frame-pointer -mfp16-format=ieee -fvisibility=hidden -fvisibility-inlines-hidden -marm -fno-omit-frame-pointer -fno-strict-aliasing -O0 -g -DDEBUG -D_DEBUG -DDEBUG -D_DEBUG
    C Compiler: C:/Users/sms28/Documents/opencv/android-ndk-r14b/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-gcc.exe
    C flags (Release): -fexceptions -fpic -Wno-psabi –sysroot=C:/Users/sms28/Documents/opencv/android-ndk-r14b/platforms/android-9/arch-arm -funwind-tables -finline-limit=64 -fsigned-char -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fdata-sections -ffunction-sections -Wa,–noexecstack -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -fomit-frame-pointer -mfp16-format=ieee -fvisibility=hidden -mthumb -fomit-frame-pointer -fno-strict-aliasing -O3 -DNDEBUG -DNDEBUG
    C flags (Debug): -fexceptions -fpic -Wno-psabi –sysroot=C:/Users/sms28/Documents/opencv/android-ndk-r14b/platforms/android-9/arch-arm -funwind-tables -finline-limit=64 -fsigned-char -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fdata-sections -ffunction-sections -Wa,–noexecstack -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -fomit-frame-pointer -mfp16-format=ieee -fvisibility=hidden -marm -fno-omit-frame-pointer -fno-strict-aliasing -O0 -g -DDEBUG -D_DEBUG -DDEBUG -D_DEBUG
    Linker flags (Release): -Wl,–fix-cortex-a8 -Wl,–no-undefined -Wl,-allow-shlib-undefined -Wl,–gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now
    Linker flags (Debug): -Wl,–fix-cortex-a8 -Wl,–no-undefined -Wl,-allow-shlib-undefined -Wl,–gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now
    ccache: NO
    Precompiled headers: NO
    Extra dependencies: z dl m log
    3rdparty dependencies: cpufeatures libprotobuf libjpeg libwebp libpng libtiff libjasper IlmImf tegra_hal

    OpenCV modules:
    To be built: core flann imgproc ml objdetect phase_unwrapping photo plot reg surface_matching video xphoto dnn face fuzzy hfs img_hash imgcodecs shape videoio xobjdetect highgui superres ts bioinspired dnn_objdetect dpm features2d line_descriptor saliency text calib3d ccalib datasets rgbd stereo structured_light tracking videostab xfeatures2d ximgproc aruco bgsegm optflow stitching java
    Disabled: world
    Disabled by dependency: –
    Unavailable: cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev python2 python3 viz cnn_3dobj cvv freetype hdf matlab ovis sfm

    Android:
    Android ABI: armeabi-v7a
    STL type: gnustl_static
    Native API level: android-9
    SDK target: android_sdk_target_status-NOTFOUND
    Android NDK: C:/Users/sms28/Documents/opencv/android-ndk-r14b (toolchain: arm-linux-androideabi-4.9)
    android tool: NO
    Google Play manager: NO
    Android examples: NO

    GUI:
    GTK+: NO
    GThread : NO
    GtkGlExt: NO
    OpenGL support: NO
    VTK support: NO

    Media I/O:
    ZLib: z (ver 1.2.3)
    JPEG: build (ver 90)
    WEBP: build (ver encoder: 0x020e)
    PNG: build (ver 1.6.24)
    TIFF: build (ver 42 – 4.0.2)
    JPEG 2000: build (ver 1.900.1)
    OpenEXR: build (ver 1.7.1)
    GDAL: NO
    GDCM: NO

    Video I/O:

    Parallel framework: pthreads

    Trace: YES ()

    Other third-party libraries:
    Use Intel IPP: NO
    Use Intel IPP IW: NO
    Use Eigen: NO
    Use Cuda: NO
    Use OpenCL: NO
    Use OpenVX: NO
    Use custom HAL: YES (carotene (ver 0.0.1))

    Python 2:
    Interpreter: C:/Python27/python.exe (ver 2.7.14)

    Python 3:
    Interpreter: C:/Users/sms28/AppData/Local/Programs/Python/Python36-32/python.exe (ver 3.6.4)

    Python (for build): C:/Python27/python.exe

    Java:
    ant: E:/opencv/apache-ant-1.9.11-bin (1)/apache-ant-1.9.11/bin/ant.bat (ver 1.9.11)
    Java wrappers: YES
    Java tests: NO

    Matlab: NO

    Documentation:
    Doxygen: NO

    Tests and samples:
    Tests: YES
    Performance tests: YES
    C/C++ Examples: NO

    Install path: C:/Users/sms28/Documents/ssibal/test2/opencv/platforms/android_arm/install

    cvconfig.h is in: C:/Users/sms28/Documents/ssibal/test2/opencv/platforms/android_arm
    —————————————————————–

    Configuring done

    —————————————————————————————————————-

    and here is mingw32 errors..

    [ 32%] Building CXX object modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/src/bitstrm.cpp.o
    [ 32%] Building CXX object modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/src/rgbe.cpp.o
    [ 32%] Building CXX object modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/src/exif.cpp.o
    arm-linux-androideabi-g++.exe: error: CreateProcess: No such file or directory
    modules\photo\CMakeFiles\opencv_photo.dir\build.make:238: recipe for target ‘modules/photo/CMakeFiles/opencv_photo.dir/opencl_kernels_photo.cpp.o’ failed
    mingw32-make[2]: *** [modules/photo/CMakeFiles/opencv_photo.dir/opencl_kernels_photo.cpp.o] Error 1
    CMakeFiles\Makefile2:3317: recipe for target ‘modules/photo/CMakeFiles/opencv_photo.dir/all’ failed
    mingw32-make[1]: *** [modules/photo/CMakeFiles/opencv_photo.dir/all] Error 2
    arm-linux-androideabi-g++.exe: error: CreateProcess: No such file or directory
    modules\imgcodecs\CMakeFiles\opencv_imgcodecs.dir\build.make:269: recipe for target ‘modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/src/bitstrm.cpp.o’ failed
    mingw32-make[2]: *** [modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/src/bitstrm.cpp.o] Error 1
    mingw32-make[2]: *** Waiting for unfinished jobs….
    arm-linux-androideabi-g++.exe: error: CreateProcess: No such file or directory
    modules\imgcodecs\CMakeFiles\opencv_imgcodecs.dir\build.make:282: recipe for target ‘modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/src/rgbe.cpp.o’ failed
    mingw32-make[2]: *** [modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/src/rgbe.cpp.o] Error 1
    arm-linux-androideabi-g++.exe: error: CreateProcess: No such file or directory
    modules\imgcodecs\CMakeFiles\opencv_imgcodecs.dir\build.make:295: recipe for target ‘modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/src/exif.cpp.o’ failed
    mingw32-make[2]: *** [modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/src/exif.cpp.o] Error 1
    CMakeFiles\Makefile2:4659: recipe for target ‘modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/all’ failed
    mingw32-make[1]: *** [modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/all] Error 2
    Makefile:161: recipe for target ‘all’ failed
    mingw32-make: *** [all] Error 2

    how can i fix it..? plz help me….

  37. Thanks for this bloc. i followed every step here, but in the end how could i install the opencv ( result of this steps) on my emulator ?!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s