Summary of related questions about using opencv cases on Eclipse

So far, in June 2016, the latest official version of opencv for android is 3.1. The source code of many cases is given above, including the very famous face detection, with good accuracy.

The official cases are all written in Eclipse, so I use Eclipse for the purpose of facilitating learning, but I first imported the SDK according to the Internet, configured the opencv java library, and then a lot of errors occurred when I imported the case. Later, it was verified that it was all problems with the library .

The case is explained in detail below:

The first category, JNI is not used

, That is, only use opencv's java interface to call opencv. When importing, such as the first official case opencv sample -15 puzzled, the following error is often reported:
Error 1

This is because your java library is not imported into the project, select the project, right-click to open properties or shortcut key Alt+Enter, you will find the following error message:
Write picture description here


At this time , just delete the wrong library and add the newly imported library to find that the project has no errors :


Write picture description here


If you get to this point, everyone feels that everything is going well, it is too young too simple, and
then the essence is the essence. If you don’t believe it, you can generate an apk from the project, put it on your phone, and install the corresponding opencv manager. You will find that it keeps prompting you to opencv. The manager is installed incorrectly , and then you will switch to various versions of the opencv manager, until you can’t find it all over again. At this time, you should think about whether it is a code problem. That’s right! !


Very simple, because you didn't add the opencv library, someone wants to ask again, did I add it before? , But I want to say that these are two libraries, there is a libs folder under...\OpenCV-3.0.0-android-sdk\OpenCV-android-sdk\sdk\native, the following is your program needs to be added to the apk first In the library, copy the libs folder as a whole to the root directory of your project, that is, put it together with the src, bin, res and other folders, and then just run it. The official may not have noticed this error. I used their packaged apk and all prompted that opencv manager was not installed correctly! ! ! !


The second type uses jni (java native interface)

This type of part which is the same as the previous one will not be written. Let me give you an example. For example, when importing tutorial 2-mixed processing,

  1. Not only the previous error ,
  2. It will also prompt that the ndk-build command is not found
  3. If you open the jni_part.cpp file under the jni folder, you will also find the vector header file error

The first one is in front, so I won’t say more about it here. The
second error is to find properties.
Write picture description here


There is a section of ${NDKROOT}/ndk-build.cmd in the builder command. Pay
attention to the environment variable NDKROOT. I found on the Internet that many people wrote the NDK_ROOT environment variable when configuring the NDK . This is different in the default environment variable of Eclipse . There is one more "_", which leads to an error. Here, I suggest that you modify the computer environment variable to NDKROOT instead of Eclipse, because Eclipse uses the NDKROOT environment variable name more than this one .


The third error, the error is because the NDK library is not configured properly, then select the include option in C++ general–Paths and symbols, and you will find the following configuration:


Write picture description here


GNU c++ references NDK version 4.6, 4.6 , and 4.6 . The important thing is said three times. At this time, I open the corresponding folder of my ndk (note, the ndk I use is r10e)
Write picture description here


There is no 4.6 here , so I changed it decisively to 4.8, the program runs successfully, and you're done

Guess you like

Origin blog.csdn.net/u014377853/article/details/51673490