Android Studio中的NDK和OpenCV设置 [英] NDK and OpenCV setup in Android Studio

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

问题描述

我将"OpenCV for Android"模块导入了Android Studio,并尝试用Java代码实现图像处理功能.

I imported the module "OpenCV for Android" into Android Studio and I tried to implement my image processing features in Java code.

大多数OpenCV方法(例如Core.multiply和Core.add)可以正常工作,但是,我发现某些OpenCV方法(例如Mat.put()和Mat.get())效率不高,并且程序运行速度非常慢在我的设备中.

Most of the OpenCV methods like Core.multiply and Core.add work fine, however, I found that some OpenCV methods like Mat.put() and Mat.get() are not quite efficient, and the program run really slow in my device.

所以,我的问题是

  1. 如果我在Android Studio中设置了NDK,这会使我的程序运行得更快吗? (我认为如果我在C ++中使用指针,程序会更高效,我不确定这是否正确)

  1. If I set up NDK in Android Studio, would this make my program run faster? (I think the program would be more efficient if I use pointer in C++, I am not sure if this is correct)

我以这种方式使用OpenCV方法Mat.get()和Mat.put(),

I use the OpenCV methods Mat.get() and Mat.put() in this way,


    Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), R.drawable.testPhoto);
    Mat m1 = new Mat(bitmap.getHeight(), bitmap.getWidth(), CvType.CV_8UC4);
    Mat m2 = m1.clone();
    Utils.bitmapToMat(bitmap, m1);
    byte[] arr = new byte[(int)(m1.total() * m1.channels())];
    m1.get(0,0,arr);
    //some processing here...
    m2.put(0,0,arr);

那么,有没有更有效的方法来使用Mat.get()和Mat.put()?

So, is there any more efficient way to use the Mat.get() and Mat.put()?

  1. 如果使用NDK是更好的方法,如何在Android项目中同时设置OpenCV和NDK?我试图遵循此
  1. If using NDK is a better way, how can I set up both OpenCV and NDK in a Android project? I tried to follow this tutorial to set up NDK in Android Studio, but once I set up NDK, I could not import OpenCV into my project.

推荐答案

要设置OpenCV和NDK,首先将OpenCV库作为模块导入您的android项目中,并将其添加为依赖项.然后,您可以研究如何设置Android NDK.

To setup OpenCV and NDK, first you import OpenCV library as module in your android project and add it as dependencies. Then you can research how to setup the Android NDK.

在通过BitmapFactory获取图像作为输入并将其填充到Mat中之后,您可以在NDK中处理图像,这使程序可以更快,更高效地运行.

After getting image as input through BitmapFactory and conveting into Mat, you can process the image in NDK, that makes program to run faster and efficient.

这篇关于Android Studio中的NDK和OpenCV设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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