我正在研究在Android Studio中使用OpenCV的Android应用。我的应用程序可以编译并执行,但是在启动加载OpenCV的活动时,我收到此警告,提示
“找不到OpenCV管理器软件包。尝试安装它吗?”
我单击“是”,并且Google Play商店应用已打开,但找不到OpenCV管理器。似乎该应用程序在Google Play中不再可用。但是,我希望将OpenCV库与我的应用程序捆绑在一起。 任何帮助表示赞赏。谢谢。
这是我的设置: settings.gradle:
include 'Application', ':libhrdataglasses', ':opencv401'
build.gradle用于应用程序:
apply plugin: 'com.android.application'
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
repositories {
jcenter()
google()
}
dependencies {
implementation 'com.android.support:support-v4:27.0.2'
implementation 'com.android.support:support-v13:27.0.2'
implementation 'com.android.support:cardview-v7:27.0.2'
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation project(':libhrdataglasses')
implementation 'android.arch.lifecycle:extensions:1.1.1'
implementation project(':opencv401')
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
}
// The sample build uses multiple directories to
// keep boilerplate and common code separate from
// the main sample code.
List<String> dirs = [
'main', // main sample code; look here for the interesting stuff.
'common', // components that are reused by multiple samples
'template'] // boilerplate code that is generated by the sample template process
android {
compileSdkVersion 27
buildToolsVersion '28.0.3'
defaultConfig {
minSdkVersion 26
targetSdkVersion 27
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
sourceSets {
main {
dirs.each { dir ->
java.srcDirs "src/${dir}/java"
res.srcDirs "src/${dir}/res"
}
}
androidTest.setRoot('tests')
androidTest.java.srcDirs = ['tests/src']
}
}
opencv401的build.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
//buildToolsVersion "x.y.z" // not needed since com.android.tools.build:gradle:3.0.0
defaultConfig {
minSdkVersion 21
targetSdkVersion 26
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
sourceSets {
main {
jniLibs.srcDirs = ['../../jni']
java.srcDirs = ['src'] // TODO Use original files instead of copied into build directory
aidl.srcDirs = ['src']
res.srcDirs = ['../opencv401/res']
manifest.srcFile 'AndroidManifest.xml'
}
}
}
dependencies {
implementation 'com.android.support:appcompat-v7:26.1.0'
}
在我的活动中:
@Override
protected void onResume() {
super.onResume();
if (!OpenCVLoader.initDebug()) {
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION, this, mOpenCVLoaderCallback);
} else {
mOpenCVLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
}
}
private BaseLoaderCallback mOpenCVLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS: {
Log.i(TAG, "OpenCV loaded successfully");
mProcessButton.setVisibility(View.VISIBLE);
} break;
default: {
super.onManagerConnected(status);
} break;
}
}
};
答案 0 :(得分:0)
1. Include opencv library in your app by downloading opencv sdk and adding this as dependency in your app.
https://docs.opencv.org/2.4/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.html#application-development-with-static-initialization
2. If you want to use opencv manager then do adb install by getting from this link.
https://docs.opencv.org/2.4/platforms/android/service/doc/UseCases.html#how-to-select-the-proper-version-of-opencv-manager
3. Check the sample code
https://github.com/opencv/opencv/tree/master/samples/android