Trouble using OpenCV in Android

前端 未结 2 2018
温柔的废话
温柔的废话 2020-12-20 09:45

I used A Beginner’s Guide to Setting up OpenCV Android Library on Android Studio as a guide to setup OpenCV in an Android Studio project. I have got the project to build and

相关标签:
2条回答
  • 2020-12-20 10:30

    I use this method to set opencv 4.1.0. This should work too for 4.1.1.

    1. Download opencv and unzip it
    2. From android studio, file -> new module -> gradle project and select the sdk directory which contain build.gradle file
    3. Add it is as dependency module for our "app" module
    4. On fragment/activity that call opencv api, add
    
    if (!OpenCVLoader.initDebug()) {
        OpenCVLoader.initDebug()
    }
    

    on either onResume or onCreateView lifecycle hook(the sample use onResume but I havent encounter any problem using it on onCreateView)

    Update 1. How to check if opencv installed correctly

    1. After unzip the library, we have two folder, sdk and samples.
    2. Go to samples folder and copy its .java and .xml file from color-blob-detection(This sample implement JavaCameraView) folder to our blank project. I think this faster than fully import the sample.
    3. Dont forget to copy the manifest file too. It add camera permision. The sample dont implement runtime permission so just toggle it manually from settings -> application -> permissions for now.

    note : Read the build.gradle file for more setup config. eg. splitting apk, ndk support etc.

    0 讨论(0)
  • 2020-12-20 10:38

    These are the steps that worked for me.

    1. Go to the OpenCV releases page and click on Android pack link of the current version section (https://opencv.org/releases.html). I used 4.1.1
    2. Unzip the file named opencv--android-sdk
    3. In Android Studio, go to File > New > Import Module... and the choose /sdk and wait for the sync to finish.
    4. Include open-cv as a module dependency. File -> Project Structure.
    5. Select the project module(not the open-cv module we added in step 3)
    6. Add the opencv as a module dependency.
    7. Check in the build.gradle file is it has been added as a dependency.
    8. Clean and build the project.

    NOTEs

    • Do not import /sdk/java like most tutorials suggest.
    • You do not have to copy the native libraries into your project like most tutorials suggest.

    Once you have OpenCV imported, use this tutorial to get the preview to fill the preview window.

    And then use this version of the JavaCamera2View. JavaCamera2View uses the camera2 api.

    These are the steps that worked for me, happy to be corrected if I have done something wrong.

    Good Luck :)

    0 讨论(0)
提交回复
热议问题