如何在 Android 应用程序中集成 OpenCV 管理器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20259309/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 02:32:17  来源:igfitidea点击:

How to integrate OpenCV Manager in Android App

androidopencv

提问by Vijay007

I am using OpenCV2.4.7 Library in my Android app. When app starts its goes to Google Play store for Application called OpenCV Manager. Is there any way to integrate this application in my Android apk because we already using OpenCV library so why app needs OpenCV Engine Again?Is Their any way to integrate this engine?

我在我的 Android 应用程序中使用 OpenCV2.4.7 库。当应用程序启动时,它会转到名为 OpenCV 管理器的应用程序的 Google Play 商店。有什么方法可以将此应用程序集成到我的 Android apk 中,因为我们已经在使用 OpenCV 库,那么为什么应用程序又需要 OpenCV 引擎?他们有什么方法可以集成这个引擎吗?

采纳答案by Chintan Rathod

Yes. To integrate OpenCV inside your application, and avoid explicit installation of OpenCV manager, you need to first read following document provided by OpenCV.

是的。要将 OpenCV 集成到您的应用程序中,并避免显式安装 OpenCV 管理器,您需要先阅读 OpenCV 提供的以下文档。

First Read -> Static Initialization of OpenCV

初读-> OpenCV的静态初始化

After successfully followed steps, you need to write following code to enable OpenCV in your application initialization code before calling OpenCV API. It can be done, for example, in the static section of the Activity class:

成功执行步骤后,您需要编写以下代码以在调用 OpenCV API 之前在应用程序初始化代码中启用 OpenCV。例如,可以在 Activity 类的静态部分中完成:

static {
    if (!OpenCVLoader.initDebug()) {
        // Handle initialization error
    }
}

References:

参考:

  1. http://answers.opencv.org/question/2033/use-opencv-on-android-without-manager/
  2. Static Initialization on OpenCV Android
  1. http://answers.opencv.org/question/2033/use-opencv-on-android-without-manager/
  2. OpenCV Android 上的静态初始化

Edit

编辑

As per new scenario in Document and thanks to @rozhok for providing new information, initDebug()method can't be used for production build

根据文档中的新场景并感谢@rozhok 提供的新信息,initDebug()方法不能用于生产构建

Note This method is deprecated for production code. It is designed for experimental and local development purposes only. If you want to publish your app use approach with async initialization.

注意 对于生产代码,不推荐使用此方法。它仅用于实验和本地开发目的。如果您想发布您的应用程序,请使用异步初始化方法。

You need to use following method for that

您需要为此使用以下方法

Syntax

句法

static boolean initAsync(String Version, Context AppContext, LoaderCallbackInterface Callback)

Example

例子

public class Sample1Java extends Activity implements CvCameraViewListener {

    private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            switch (status) {
                case LoaderCallbackInterface.SUCCESS:
                {
                    Log.i(TAG, "OpenCV loaded successfully");
                    mOpenCvCameraView.enableView();
                } break;
                default:
                {
                    super.onManagerConnected(status);
                } break;
            }
        }
    };

    @Override
    public void onResume()
    {
        super.onResume();
        OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_6, this, mLoaderCallback);
    }

    ...
}

References

参考

  1. http://docs.opencv.org/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.html
  1. http://docs.opencv.org/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.html

回答by MIkka Marmik

  1. Insert this lines after include $ (CLEAR_VARS) in OpenCV.mk file
    OPENCV_CAMERA_MODULES:=on
    OPENCV_INSTALL_MODULES:=on
    include D:/opencv_with/OpenCV-2.4.10-android-sdk/sdk/native/jni/OpenCV.mk
    
  2. In your current project directory libs folder copy all folder inside OpenCV libs.

  3. Add in your Activity

    if (!OpenCVLoader.initDebug()) {
                Log.d("ERROR", "Unable to load OpenCV");
            } else {
                mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
            }
    
    private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
    
            @Override
            public void onManagerConnected(int status) {
                switch (status) {
                case LoaderCallbackInterface.SUCCESS: {
    
                    //Your opencv Operation code
    
                }
                }
            }
        };
    
  1. 在 OpenCV.mk 文件中的 include $ (CLEAR_VARS) 之后插入此行
    OPENCV_CAMERA_MODULES:=on
    OPENCV_INSTALL_MODULES:=on
    include D:/opencv_with/OpenCV-2.4.10-android-sdk/sdk/native/jni/OpenCV.mk
    
  2. 在您当前的项目目录 libs 文件夹中复制 OpenCV libs 中的所有文件夹。

  3. 添加您的活动

    if (!OpenCVLoader.initDebug()) {
                Log.d("ERROR", "Unable to load OpenCV");
            } else {
                mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
            }
    
    private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
    
            @Override
            public void onManagerConnected(int status) {
                switch (status) {
                case LoaderCallbackInterface.SUCCESS: {
    
                    //Your opencv Operation code
    
                }
                }
            }
        };
    

回答by Luis Sandoval

This is what the documentation says about the OpenCV Manager installation:

这是文档关于 OpenCV 管理器安装的说明:

apkfolder contains Android packages that should be installed on the target Android device to enable OpenCV library access via OpenCV Manager API (see details below).

On production devices that have access to Google Play Market (and Internet) these packages will be installed from Market on the first start of an application using OpenCV Manager API.

...

Note:Installation from Internet is the preferable way since OpenCV team may publish updated versions of this packages on the Market.

apk文件夹包含应安装在目标 Android 设备上的 Android 包,以通过 OpenCV Manager API 启用 OpenCV 库访问(请参阅下面的详细信息)。

在可以访问 Google Play Market(和 Internet)的生产设备上,这些软件包将在使用 OpenCV Manager API 的应用程序第一次启动时从 Market 安装。

...

注意:从 Internet 安装是更可取的方式,因为 OpenCV 团队可能会在市场上发布此软件包的更新版本。

You can read more about it here: https://docs.opencv.org/3.0-beta/doc/tutorials/introduction/android_binary_package/O4A_SDK.html#general-info

您可以在此处阅读更多相关信息:https: //docs.opencv.org/3.0-beta/doc/tutorials/introduction/android_binary_package/O4A_SDK.html#general-info

回答by Vijay007

Just commentthe line in following Code

只需注释以下代码中的行

@Override
public void onResume()
{
    super.onResume();
    //OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback);

}