java OpenCV Android 上的静态初始化

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12615712/
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-10-31 09:33:59  来源:igfitidea点击:

Static Initialization on OpenCV Android

javaandroidopencvstaticinitialization

提问by Droidkie

i'm trying to run OpenCVTutorial 1 - Add OpenCV with static initialization using this
i don't want a separate OpenCV Manager application installed) but i get an "OpenCV error: Cannot load info library for OpenCV."

我正在尝试运行OpenCV教程 1 - 使用添加带有静态初始化的 OpenCV
我不想安装单独的 OpenCV 管理器应用程序)但我得到了"OpenCV error: Cannot load info library for OpenCV."

I did the following things:

我做了以下几件事:

  1. added a libs folder with armeabi, armeabi-v7a, and x86folders inside of it (from OpenCV-2.4.2-android-sdk/sdk/native/libs/)

  2. added the static {if (!OpenCVLoader.initDebug())}code just below private Sample1View mView;

  3. removed the below code

  1. 添加了一个包含armeabiarmeabi-v7ax86文件夹的 libs 文件夹(来自 OpenCV-2.4.2-android-sdk/sdk/native/libs/)

  2. {if (!OpenCVLoader.initDebug())}在私有 Sample1View mView 正下方添加了静态代码;

  3. 删除了下面的代码

if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_2, this, mOpenCVCallBack))

if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_2, this, mOpenCVCallBack))

what seems to be the problem?

似乎是什么问题?

回答by Qichao Chen

You should add the code:

您应该添加以下代码:

mOpenCVCallBack.onManagerConnected(LoaderCallbackInterface.SUCCESS);

after:

后:

if(!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_2, this, mOpenCVCallBack)) 

If you remove:

如果删除:

if(!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_2, this, mOpenCVCallBack))  

code block then nobody calls.

代码块然后没人调用。

Hope it can help you.

希望它可以帮助你。

回答by user2874769

I have the same problem, I have solved the problem by adding the following code at the first of my Activity class:

我有同样的问题,我通过在我的 Activity 类的第一个添加以下代码解决了这个问题:

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

Also I added

我还加了

mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);

before the line

行前

OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback); 

and commented the line

并评论了这一行

OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback);

Good luck.

祝你好运。

回答by mockfrog

The log message:

日志消息:

"OpenCV error: Cannot load info library for OpenCV."

shuld not worry you. At least in my app it tells me something like OpenCV libs init is OK afterwards.

不应该让你担心。至少在我的应用程序中,它告诉我诸如 OpenCV libs init 之类的东西之后就可以了。

In the sample code the CameraBridgeViewBase object gets enabled when the BaseLoaderCallback gets called. That happens when the async loading of the opencv library has finished. When you load the library statically, try adding a call to mOpenCVCameraView.enableView() in your onResume() method (after loading the lib of coourse).

在示例代码中,当 BaseLoaderCallback 被调用时,CameraBridgeViewBase 对象被启用。当 opencv 库的异步加载完成时会发生这种情况。当您静态加载库时,尝试在您的 onResume() 方法中添加对 mOpenCVCameraView.enableView() 的调用(在加载课程库之后)。

回答by flankechen

initAsync() needs a callback to load opencv libs and your jni libs.

initAsync() 需要回调来加载 opencv 库和 jni 库。

check the callback function and make it right in the if (!OpenCVLoader.initDebug()), not in the callback!

检查回调函数并使其在 if (!OpenCVLoader.initDebug()) 中正确,而不是在回调中!

            if (!OpenCVLoader.initDebug()) {
            // Handle initialization error
              Log.i(TAG, "OpenCV load not successfully");
        } else {
            System.loadLibrary("mixed_sample");
            //System.loadLibrary("my_jni_lib2");

            InitFeature(width,height);

            mOpenCvCameraView.enableView();
        }

it works for the tutorial 2 in OCV4Android2.4.5.

它适用于 OCV4Android2.4.5 中的教程 2。