在Android中使用OpenCV遇到问题 [英] Trouble using OpenCV in Android

查看:89
本文介绍了在Android中使用OpenCV遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了

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 install on my phone but I am not getting a video feed from the camera (that is the JavaCameraView is empty).

主要问题似乎是 OpenCV管理器已从Google Play商店中撤出. :,(

The main issues seems to be that the OpenCV Manager has been pulled from the google play store. :,(

我已经尝试过这个SO问题尝试使用opencv而不需要将其从游戏商店中移除,但这也无济于事.

I have tried the solution from the this SO question to try to use opencv without needing to get it off the play store, but that didn't help either.

我拥有在我的应用上使用相机所需要的所有权限.

I have all the required permissions to use use the camera on my app.

我的代码与《初学者指南》教程中的代码非常相似,但是如果您需要查看更多我的代码,请告诉我.

My code is pretty similar to the one from the Beginner’s Guide tutorial, but let me know if you need to see any more of my code.

我的onResume:

My onResume:

public override fun onResume() {
    super.onResume()
    if (!OpenCVLoader.initDebug()) {
        OpenCVLoader.initDebug()
    }
    loaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS)
}

BaseLoadCallback:

BaseLoadCallback:

private val loaderCallback = object : BaseLoaderCallback(this) {
    override fun onManagerConnected(status: Int) {
        when (status) {
            LoaderCallbackInterface.SUCCESS -> {
                Log.i(TAG, "OpenCV loaded successfully")
                opencv_camera_view.enableView()
                opencv_camera_view.setOnTouchListener(this@MainActivity)
            }
            else -> {
                super.onManagerConnected(status)
            }
        }
    }
}

推荐答案

这些是对我有用的步骤.

These are the steps that worked for me.

  1. 转到OpenCV版本页面,然后单击当前版本部分的Android Pack链接( https://opencv .org/releases.html ).我用的是4.1.1
  2. 解压缩名为opencv--android-sdk的文件
  3. 在Android Studio中,转到文件">新建">导入模块...",然后选择/sdk,然后等待同步完成.
  4. 将open-cv包含为模块依赖项.文件->项目结构.
  5. 选择项目模块(而不是我们在步骤3中添加的open-cv模块)
  6. 将opencv添加为模块依赖项.
  7. 检入build.gradle文件是否已将其作为依赖项添加.
  8. 清理并构建项目.
  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.

注意

  • 请勿像大多数教程所建议的那样导入/sdk/java.
  • 您不必像大多数教程所建议的那样将本机库复制到项目中.
  • 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.

一旦导入了OpenCV,请使用教程,以获取预览以填充预览窗口.

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

然后使用版本的JavaCamera2View. JavaCamera2View使用camera2 API.

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.

祝你好运:)

这篇关于在Android中使用OpenCV遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆