Opencv(3.3) & ZXing(Modify for scan QR code) for Android environment on Android Studio
From:https://blog.csdn.net/lldbuaa/article/details/80333718
I must be crazy!
when I promise someone that I will finish an app with Opencv&ZXing in 2 weeks ,I didnot know what an activity is!
cause I got a lot from web,many people gave advice for other people and I got something right and something wrong…
So If this blog help you,I will be happy and give me five.
1.OpenCV Environment WITHOUT OPENCV_Manager
this link
Opencv4Android doc
Opencv4Android Environment doc
Cause I use Android Studio so I fellow the steps below
(1).Import Module->”opencv/sdk/java”->then get the model like this
(2).Add depends->
There, I need to say,when I use Opencv in ZXing(Modify),I will add the depends to ZXing Module,and you will read more.
(3).Modify the build.gradle(openCVLibrary330)& (app)->
//build gradle(opencv)apply plugin: 'com.android.library'android { compileSdkVersion 27 //Need to Modify buildToolsVersion "27.0.3" //Need to Modify //The actual version depends on your build.gradle(app) fellowed defaultConfig { minSdkVersion 23 //Need to Modify targetSdkVersion 27 //Need to Modify //Same with the app build.gradle(app) } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } }}
//build.gradle(app)apply plugin: 'com.android.application'android { compileSdkVersion 27 buildToolsVersion "27.0.3" defaultConfig { applicationId "com.example.lld.hellowopencv" minSdkVersion 23 targetSdkVersion 27 versionCode 1 versionName "1.1" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }}dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar') implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'com.android.support.constraint:constraint-layout:1.1.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' implementation project(':openCVLibrary330')}//Add the fellow codetask nativeLibsToJar(type: Jar, description: 'create a jar archive of the native libs') { destinationDir file("$buildDir/native-libs") //native-libs is the neme of jar baseName 'native-libs' //same with the up from fileTree(dir: 'libs', include: '**/*.so') into 'lib/'}tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn(nativeLibsToJar)}
(4).Copy opencv/sdk/native 2 libs(IF you do not have JNI)
(IF you have JNI) read the link as fellow
Opencv4Android Environment doc
(5).Init OpenCV static
static { if (!OpenCVLoader.initDebug()) { // Handle initialization error } else { System.loadLibrary("my_jni_lib1"); System.loadLibrary("my_jni_lib2"); }}
Maybe you will find No Wrong with your code.
When your Module which depends OpenCV is the app,It will work,you will GET the OpenCV Load like this:
But when your Module which depends OpenCV is the other app, it will not work,and you will GET Cannot load Opencv/Opencv Info/…
You need
create the jniLibs folder and copy opencv/sdk/native to the folder
you will get
It means you get the OpenCV environment.
2.ZXing Environment
(1)New Module ->ZXing
(2)Copy files into ZXing/src/main/java/com/
like the fellowing
and modify the res folder
(3)Add depends to App Module
(4)Cover the Mainfiest(app)
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.lld.checkapp"> <uses-permission android:name="android.permission.CAMERA"/> <uses-permission android:name="android.permission.FLASHLIGHT"/> <uses-feature android:name="android.hardware.camera"/> <uses-feature android:name="android.hardware.camera.autofocus"/> <uses-permission android:name="android.permission.VIBRATE"/> <uses-permission android:name="android.permission.WAKE_LOCK"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".main" android:configChanges="orientation|keyboardHidden|screenSize" android:label="@string/app_name" android:theme="@style/Theme.AppCompat.Light.NoActionBar"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> intent-filter> activity> <activity android:name="com.lld.zxing.Activity.CaptureActivity">//register the next Activity activity> application>manifest>
(5).Add core-3.3.0.jar to zxing/libs/
(6).You Get the ZXing environment (Modify for scan QR code)
3.The Test Pic
4.The download link
OpenCV Environment Only密码: uncv
ZXing Environment Only 密码cn5a
Two Environment in One 密码bdhm
5.If the blog helps you,please make something for others
Maybe Give Me Five is a Good Thing.
更多相关文章
- Android实现图片的倒影效果
- checkbox切换选中状态的图片
- 图片加载库Glide的使用
- Androd之在图片右上角显示红色圆圈里面数字提醒
- tabcontent中scaleType的使用 图片Drawable和bitmap显示问题
- Android实现动态显示或隐藏密码输入框的内容