gpt4 book ai didi

Trying to Import OpenCV 4.8 in Android Studio Giraffe(尝试在Android Studio Giraffe中导入OpenCV 4.8)

转载 作者:bug小助手 更新时间:2023-10-27 20:45:37 25 4
gpt4 key购买 nike



I have seen this question asked multiple times, but they are for much older versions of OpenCV or Android Studio, and the solutions haven't worked for me.

我已经看到这个问题被问了很多次,但他们是针对旧版本的OpenCV或Android Studio,解决方案对我不起作用。


I'm trying to get the OpenCV SDK installed as a module in my project so I can start using it. Here is what I've done so far:

我正在尝试将OpenCV SDK作为模块安装在我的项目中,这样我就可以开始使用它了。以下是我到目前为止所做的:


First, I created a new Android project. It targets Android 28 and has a blank activity. The app starts in an emulator.

首先,我创建了一个新的Android项目。它的目标是Android 28,并有一个空白活动。该应用程序在模拟器中启动。


I downloaded the latest Android SDK from the OpenCV site and unzipped it.

我从OpenCV网站下载了最新的Android SDK并解压缩。


In Android Studio, I did file->new->import module
I selected the folder C:\dev\opencv\OpenCV-android-sdk\sdk

在Android Studio中,我选择了文件夹C:\Dev\OpenCV\OpenCV-Android-SDK\SDK


Some tutorials say to select the Java folder under sdk, but the latest one I am following said to select just \sdk

一些教程说选择SDK下的Java文件夹,但我关注的最新教程说选择Just\SDK


Once the module is selected and imported, I get a build error

一旦选择并导入了模块,我就会得到一个构建错误


Plugin [id: 'com.android.application', version: '8.1.0', apply: false] was not found in any of the following sources:

I assume it has some problem with the build.gradle that comes with the OpenCV sdk. Here is that file:

我想是OpenCV SDK附带的build.gradle出了点问题。以下是该文件:


apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

def openCVersionName = "4.8.0"
def openCVersionCode = ((4 * 100 + 8) * 100 + 0) * 10 + 0

println "OpenCV: " +openCVersionName + " " + project.buildscript.sourceFile

android {

compileSdkVersion 26

defaultConfig {
minSdkVersion 21
targetSdkVersion 26

versionCode openCVersionCode
versionName openCVersionName

externalNativeBuild {
cmake {
arguments "-DANDROID_STL=c++_shared"
targets "opencv_jni_shared"
}
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}



buildTypes {
debug {
packagingOptions {
doNotStrip '**/*.so' // controlled by OpenCV CMake scripts
}
}
release {
packagingOptions {
doNotStrip '**/*.so' // controlled by OpenCV CMake scripts
}
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}

sourceSets {
main {
jniLibs.srcDirs = ['native/libs']
java.srcDirs = ['java/src']
aidl.srcDirs = ['java/src']
res.srcDirs = ['java/res']
manifest.srcFile 'java/AndroidManifest.xml'
}
}

externalNativeBuild {
cmake {
path (project.projectDir.toString() + '/libcxx_helper/CMakeLists.txt')
}
}
}

dependencies {
}

Any ideas what I should try next? I'm not an Android build expert. I have done OpenCV in Python and have built Android apps using Flutter. So this is my first try with Android native code.

你知道我下一步该试什么吗?我不是Android构建专家。我用Python语言做了OpenCV,用Ffltter构建了Android应用程序。这是我第一次尝试使用Android原生代码。


更多回答
优秀答案推荐

I was finally able to add the OpenCV library to a starter project and have it build correctly. Here is what I had to do:

我终于能够将OpenCV库添加到一个入门项目中,并让它正确构建。以下是我不得不做的事情:



  1. Change the gradle file that comes with OpenCV. Add this code in the android {} section. I made up the namespace name


    namespace "org.opencv.androidsdk"

Added this to my gradle settings file at the very end

在我的Gradle设置文件的末尾添加了这个


include(":opencv")
project(":opencv").projectDir = File("C:\\dev\\opencv\\OpenCV-android-sdk\\sdk")

I did this instead of importing the module as I tried in my original question.

我这样做了,而不是像我在原始问题中尝试的那样导入模块。


I'm beginning to think there is a conspiracy to prevent newbies from doing mobile OpenCV. The information is very hard to find, is old, outdated, and often wrong. I suppose it's because of all the tech layoffs. People need to keep being needed, so the best way to do that is to mislead others trying to do the same job as theirs. :)

我开始认为,这是一个阴谋,目的是阻止新手做移动OpenCV。这些信息很难找到,而且是旧的、过时的,而且经常是错误的。我想这是因为所有科技公司的裁员。人们需要不断地被需要,所以要做到这一点,最好的方法是误导其他试图做与他们相同工作的人。:)


Hope this helps someone. My next hurdle will be to actually call some OpenCV in my sample project.

希望这能帮到什么人。我的下一个障碍是在我的样例项目中实际调用一些OpenCV。


更多回答

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com