The use of OpenCV, the NDK's simple use

Source: Internet
Author: User

1, download OpenCV,and unzip, copy the SDK under its directory into Eclipse 's working interval directory, rename it to OPENCV-SDK(randomly named);

2, from eclipse file->import->general->exiting project  into project->next->browse ( select path) at this time project explorer opencv library-2.4.10

3, create a new project (to use opencv project->properties->android->library ADD-> select opencv library-2.4.10->ok; will appear in the project. android dependencies->opencv library-2.4.10.jar import succeeded. The next can invoke the corresponding opencv The corresponding features in the java programmed.

4. Next, use the NDK to call opencv( 1,2,3 ) on the basis of;

5. Generation of header files (automatic), using the command line:

First into the project's src directory:javah-classpath Load class path- d output path -jni path to the boot class Enter ! the . h file was successfully generated:

Note Two points: (1)-classpathis that you generate. Classwhere is the ancestral directory of the file? It's the place where the package files happen, like mine.Imageprocof theclassfile path isF:\Android\OpenCV\GreyProcess\bin\classes\com\example\greyprocess\ImageProc.classPackage name isCom.example,then IClasspathbehind isF:\Android\OpenCV\GreyProcess\bin\classes\, (2) and then the-jnithe back, as was in thesrcunder directory.Javahcommand here to write directlyCom.example.ImageProcjust fine. We useJavahnot for the sake of mere generation.. hheader file, otherwise it would be too much for us .Javathe function declarations in the file are converted intoCand theC + +in the form of a function that can be called, to be precise.NDKcall the form, so here the file name we can be arbitrarily changed, but the inside of the function can not move;

6, include header file, write c or C + + code;

7, you will find that the writing of things always error, because also to importNDKNeutralizationOpenCVin the things that also want to configureandroid.mkand theapplation.mk, configureandroid.mkThere's an important place, remember .includeA bitOpenCV. The main point here is to joinNDKof theCLibraries andOpenCVthe library:

(1) First determine that the NDKwas imported correctly:window->preference->android->ndk->ndk Location->browse: Select the correct location ( as above my D:\Java_NDK\Software\android-ndk-r10b)->apply->ok;

(2) Setting up the Build environment variable: Select Project project->properties->c/c++ build->enviroment->add: my name is a Ndkroot , and then value It's you . NDK The path (mine is D:\Java_NDK\Software\android-ndk-r10b ) ->ok->apply

(3) Import the required libraries:project->properties->c/c++ General->path and Symbols->includes->add:repeat the selection and know to join all the libraries you want to use->apply->ok;(This is a few of my imports:D:\Java_NDK\Software\android-ndk-r10b\platforms\android-4\arch-arm\usr\include;D:\Java_NDK\Software\android-ndk-r10b\platforms\android-8\arch-arm\usr\include;D:\java_ndk\software\android-ndk-r10b\sources\cxx-stl\gnu-libstdc++\4.6\include;F:\Android\OpenCV\OpenCV-SDK\native\jni\includeThese vary from person to person ).

(4) Setup is complete, you will find that the original C or C + + file in the Red Fork is not.

8. Then build the build library and right-click Project ->build project;

9, running the project run as android application.

The use of OpenCV, the NDK's simple use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.