Reprint declaration, this article transfer from CSDN:http://blog.csdn.net/qq_22033759/article/details/51156121
PS: Originally posted on someone asked, want to write, but time is limited, at the beginning of their own study of this csdn post-blog configuration, one for the collection, two in order to let more friends to search, reproduced ...
The following is reproduced in the original text:
I am using the OpenCV version of 3.1,android Studio version 2.0
Download the corresponding version of the Android OpenCV SDK from the OPENCV official website to extract the path do not have Chinese
Then create an Android project in Android Studio and create a folder in the root directory named libraries
Then copy the Sdk\java folder in the SDK completion directory to the Libraries folder and rename it to OpenCV
Next, create a build.gradle in the OpenCV directory with the contents of
Apply plugin: ' Com.android.library ' buildscript { repositories { mavencentral () } dependencies { classpath ' com.android.tools.build:gradle:2.0.0 '} } Android { compilesdkversion buildtoolsversion "23.0.3" defaultconfig { minsdkversion Targetsdkversion versioncode 2480 versionname "3.1.0" } sourcesets { main { Manifest.srcfile ' androidmanifest.xml ' java.srcdirs = [' src '] resources.srcdirs = [' src '] Res.srcdirs = [' res '] aidl.srcdirs = [' src ']}} }
The corresponding SDK version needs to be modified according to requirements
Then, after modifying the settings.gradle of the project, add a row
Include ': Libraries:opencv '
To select Sync Now
Then right-click the project name, select Open Module Settings, select app and click Dependencies, then tap the plus sign, choose the third one, add OpenCV
Add good after
Then create a folder under/app/src/main/called Jnilibs
Copy all the folders under the directory to Jnilibs.
This is a complete configuration.
The next step is to use.
Be sure to add static{system.loadlibrary ("Opencv_java3") first;}
I tested the code: (interface has a imageview and a button)
Package Com.example.chengk.opencvexamples;import Android.graphics.bitmap;import Android.graphics.drawable.bitmapdrawable;import Android.support.v7.app.appcompatactivity;import Android.os.bundle;import Android.view.view;import Android.widget.button;import Android.widget.ImageView;import Org.opencv.android.utils;import Org.opencv.core.mat;import Org.opencv.imgproc.imgproc;public class MainActivity Extends Appcompatactivity {static{system.loadlibrary ("Opencv_java3");} int i=0; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); ImageView ImageView = (ImageView) Findviewbyid (R.id.imageview); Final Bitmap Bitmap = ((bitmapdrawable) getresources (). getdrawable (R.DRAWABLE.AA1)). Getbitmap (); Imageview.setimagebitmap (bitmap); Final Button button2 = (Button) Findviewbyid (R.id.button); Button2.settext ("conversion"); Button2.setonclicklistener (New ButtoN.onclicklistener () {@Override public void OnClick (View v) {i++; Mat Rgbmat = new Mat (); Mat Graymat = new Mat (); Gets the pixel data corresponding to the Lena color image Utils.bitmaptomat (bitmap, Rgbmat); Convert color image data to grayscale image data and store it in Graymat Imgproc.cvtcolor (Rgbmat, Graymat, Imgproc.color_rgb2gray); Create a grayscale image Bitmap Graybmp = Bitmap.createbitmap (Bitmap.getwidth (), Bitmap.getheight (), Bitmap.Config.RGB_5 65); Convert matrix Graymat to grayscale image Utils.mattobitmap (Graymat, graybmp); ImageView ImageView = (ImageView) Findviewbyid (R.id.imageview); if (i%2==1) Imageview.setimagebitmap (graybmp); else Imageview.setimagebitmap (bitmap); } }); }}
Run:
Before clicking the button
After clicking the button
This is really feasible, but the space occupied is too large, I this program occupies a space of nearly 50M, still looking for other better ways to find the continuation of the update.
Android Studio configuration and use of opencv3.x, no need for Opencvmanager