"Starter" Androidstudio configuration JAVACV Environment

Source: Internet
Author: User

Androidstudio Configuring the JAVACV environment

Because face recognition was needed for a recent tournament, but the competition restricted the use of API cloud service calls from third-party service providers, and so thought of using JAVACV to implement it, but all of the tutorials were built in eclipse through Baidu, Google search, and for several days, Get up early to rebuild one go today. Writing this blog is mainly for the novice friends as a reference, but also my first blog post.

    • 1. Preparatory work
    • 2. Environment Construction
    • 3. Test procedure
Preparatory work

-First need to download JAVACV required packages on Google website
-Site: https://code.google.com/archive/p/javacv/downloads
-Unable to open friends can download Http://pan.baidu.com/s/1c2BIhmo with my shared network disk

-Download the package: javacv-0.7-bin.zip, Opencv-2.4.3-android-arm.zip
-Unzip Javacv-0.7-bin.zip, Opencv-2.4.3-android-arm.zip to any directory, respectively
-Preparations are over now.

Environment construction

1, use Androidstudio to create the project STUDIOTESTJAVACV, the name can be arbitrary
2. Open Androidstudio Project, cannot see the Libs folder in the project directory under Android view, so clickAndroid, replace itProjectView
WillJavacv-0.7-bin.zipUnzip the folder in theJavacv.jar, Javacpp.jarCopy to the Libs folder


Then right-click Project, selectOpen Module Setting, select the app under modules (this is the name of your module)Dependencies, click the green plus sign (+) on the right, and select2.File Dependency, choose to add the copy that you just copied inJavacv.jar, Javacpp.jar。



3, the next need to copy. So, in eclipse you only need to build the Armeabi folder under the Libs folder, but because Androidstudio uses Gradle compilation, it differs from eclipse, so the method in eclipse will not be able to complete the build. SoFollow me
Or the same project view,App>src>mainDirectory under newJnilibsDirectory, and then jnilibs the newArmeabiDirectory



3, inJavacv-0.7-bin.zipUnzip the folder to findJavacv-android-arm.jarTo extract it.


Copy all the. So files under this folder to the new Armeabi folder in the previous step
And then we willOpencv-2.4.3-android-arm.zipExtracted from the directory under theLibs > ArmeabiCopy all the. So files under the new Armeabi folder to the previous step.

The above environment construction is completed

Test program

Picture rollover:

Note: This code is from the network, if the author requests to stop using, please contact me immediately delete

 PackageCOM.ACT.STUDIOTESTJAVACV;Importandroid.support.v7.app.ActionBarActivity;ImportAndroid.os.Bundle;Import StaticCom.googlecode.javacv.cpp.opencv_core. ipl_depth_8u;Import StaticCom.googlecode.javacv.cpp.opencv_core.cvFlip;ImportAndroid.graphics.Bitmap;Importandroid.graphics.drawable.BitmapDrawable;Importandroid.graphics.drawable.Drawable;ImportAndroid.widget.ImageView;ImportCom.googlecode.javacv.cpp.opencv_core. Iplimage; Public  class mainactivity extends actionbaractivity {    @Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);        Setcontentview (R.layout.activity_main);        ImageView ImageView = (ImageView) Findviewbyid (R.ID.IMG1); Imageview.setimageresource (R.DRAWABLE.P4);//Instantiation ControlImageView img = (ImageView) Findviewbyid (r.id.img);//Create image, P4 is a random image, here you can find a random image instead ofdrawable drawable = idtodrawable (R.DRAWABLE.P4); Bitmap Bitmap = This. Drawabletobitmap (drawable);//Convert bitmap to IplimageIplimage Iplimage = This. Bitmaptoiplimage (bitmap);//processing images, such as rotating imagesCvflip (Iplimage, Iplimage,0);//Convert Iplimage to bitmapBitmap = This.        Iplimagetobitmap (Iplimage);    Img.setimagebitmap (bitmap); }/** * Iplimage converted to bitmap * @param iplimage * @return  * *     PublicBitmapIplimagetobitmap(Iplimage iplimage) {Bitmap Bitmap =NULL;        Bitmap = Bitmap.createbitmap (Iplimage.width (), Iplimage.height (), Bitmap.Config.ARGB_8888); Bitmap.copypixelsfrombuffer (Iplimage.getbytebuffer ());returnBitmap }/** * Bitmap converted to Iplimage * @param bitmap * @return  * *     PublicIplimageBitmaptoiplimage(Bitmap Bitmap)        {Iplimage iplimage; Iplimage = Iplimage.create (Bitmap.getwidth (), Bitmap.getheight (), ipl_depth_8u,4); Bitmap.copypixelstobuffer (Iplimage.getbytebuffer ());returnIplimage; }/** * Convert resource ID to drawable * @param ID * @return  * *     PublicDrawableidtodrawable(intID) {return  This. Getresources (). getdrawable (R.DRAWABLE.P4); }/** * Convert drawable to bitmap * @param drawable * @return  * *     PublicBitmapDrawabletobitmap(drawable drawable) {if(drawable = =NULL)return NULL;return((bitmapdrawable) drawable). Getbitmap (); }}

You can choose a picture to test, the effect is as follows

Here this time the Android Terminal JAVACV environment construction process is over, this is my first blog, the first blog, think too much, afraid too rough missed the focus, but also afraid too complex no primary, in short, is a good start, also considered as a learning note as a post-use, And I want to be able to give the same as I did on the Androidstudio to build JAVACV environment to meet the bottleneck of friends as a reference.

Copyright statement: All the steps are from the network, I just will be a unified collation, can be reproduced at will, for the above mentioned about the test code, if the original code to see and do not agree to use, please leave a message, I will immediately apologize delete.

"Starter" Androidstudio configuration JAVACV Environment

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.