How to Use OpenCV in Android Studio

本文提供了一套完整的指南,在Android Studio中整合并配置OpenCV库,包括创建目录结构、复制SDK文件、调整build.gradle文件、设置依赖项、创建jniLibs目录并复制.so文件等关键步骤。
How to Use OpenCV in Android Studio

  • Create a libraries folder underneath your project main directory. For example, if your project is OpenCVExamples, you would create a OpenCVExamples/libraries folder.

  • Go to the location where you have SDK "\OpenCV-2.4.8-android-sdk\sdk" here you will find the java folder, rename it to opencv.

  • Now copy the complete opencv directory from the SDK into the libraries folder you just created.

  • Now create a build.gradle file in the opencv directory with the following contents

    apply plugin: 'android-library'
    
    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.9.+'
        }
    }
    
    android {
        compileSdkVersion 19
        buildToolsVersion "19.0.1"
    
        defaultConfig {
            minSdkVersion 8
            targetSdkVersion 19
            versionCode 2480
            versionName "2.4.8"
        }
    
        sourceSets {
            main {
                manifest.srcFile 'AndroidManifest.xml'
                java.srcDirs = ['src']
                resources.srcDirs = ['src']
                res.srcDirs = ['res']
                aidl.srcDirs = ['src']
            }
        }
    }
  • Edit your settings.gradle file in your application’s main directory and add this line:

    include ':libraries:opencv'
  • Sync your project with Gradle and it should looks like this

    screen 1

  • Right click on your project then click on the Open Module Settings then Choose Modules from the left-hand list, click on your application’s module, click on the Dependencies tab, and click on the + button to add a new module dependency.

    enter image description here

  • Choose Module dependency. It will open a dialog with a list of modules to choose from; select “:libraries:opencv”.

    enter image description here

  • Create a jniLibs folder in the /app/src/main/ location and copy the all the folder with *.so files (armeabi, armeabi-v7a, mips, x86) in the jniLibs from the OpenCV SDK.

    enter image description here

  • Click OK. Now everything done, go and enjoy with OpenCV.



  • 链接:http://answers.opencv.org/question/14546/how-to-work-with-opencv4android-in-android-studio/


C:\Users\qusg>appium-doctor --android WARN AppiumDoctor [Deprecated] Please use appium-doctor installed with "npm install @appium/doctor --location=global" info AppiumDoctor Appium Doctor v.1.16.2 info AppiumDoctor ### Diagnostic for necessary dependencies starting ### info AppiumDoctor ✔ The Node.js binary was found at: C:\own\app\Node\node.EXE info AppiumDoctor ✔ Node version is 22.18.0 info AppiumDoctor ✔ ANDROID_HOME is set to: C:\Users\qusg\AppData\Local\Android\Sdk info AppiumDoctor ✔ JAVA_HOME is set to: C:\own\app\JDK info AppiumDoctor Checking adb, android, emulator, apkanalyzer.bat info AppiumDoctor 'adb' is in C:\Users\qusg\AppData\Local\Android\Sdk\platform-tools\adb.exe info AppiumDoctor 'emulator' is in C:\Users\qusg\AppData\Local\Android\Sdk\emulator\emulator.exe WARN AppiumDoctor ✖ android, apkanalyzer.bat could NOT be found in C:\Users\qusg\AppData\Local\Android\Sdk! info AppiumDoctor ✔ 'bin' subfolder exists under 'C:\own\app\JDK' info AppiumDoctor ### Diagnostic for necessary dependencies completed, one fix needed. ### info AppiumDoctor info AppiumDoctor ### Diagnostic for optional dependencies starting ### WARN AppiumDoctor ✖ opencv4nodejs cannot be found. WARN AppiumDoctor ✖ ffmpeg cannot be found WARN AppiumDoctor ✖ mjpeg-consumer cannot be found. WARN AppiumDoctor ✖ bundletool.jar cannot be found WARN AppiumDoctor ✖ gst-launch-1.0.exe and/or gst-inspect-1.0.exe cannot be found info AppiumDoctor ### Diagnostic for optional dependencies completed, 5 fixes possible. ### info AppiumDoctor info AppiumDoctor ### Manual Fixes Needed ### info AppiumDoctor The configuration cannot be automatically fixed, please do the following first: WARN AppiumDoctor ➜ Manually install android, apkanalyzer.bat and add it to PATH. https://developer.android.com/studio#cmdline-tools and https://developer.android.com/studio/intro/update#sdk-manager may help to setup. info AppiumDoctor info AppiumDoctor ### Optional Manual Fixes ### info AppiumDoctor The configuration can install optionally. Please do the following manually: WARN AppiumDoctor ➜ Why opencv4nodejs is needed and how to install it: http://appium.io/docs/en/writing-running-appium/image-comparison/ WARN AppiumDoctor ➜ ffmpeg is needed to record screen features. Please read https://www.ffmpeg.org/ to install it WARN AppiumDoctor ➜ mjpeg-consumer module is required to use MJPEG-over-HTTP features. Please install it with 'npm i -g mjpeg-consumer'. WARN AppiumDoctor ➜ bundletool.jar is used to handle Android App Bundle. Please read http://appium.io/docs/en/writing-running-appium/android/android-appbundle/ to install it. Also consider adding the ".jar" extension into your PATHEXT environment variable in order to fix the problem for Windows WARN AppiumDoctor ➜ gst-launch-1.0.exe and gst-inspect-1.0.exe are used to stream the screen of the device under test. Please read https://appium.io/docs/en/writing-running-appium/android/android-screen-streaming/ to install them and for more details info AppiumDoctor info AppiumDoctor ### info AppiumDoctor info AppiumDoctor Bye! Run appium-doctor again when all manual fixes have been applied! info AppiumDoctor
10-14
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值