Android OpenCV 端口有什么缺点吗?

发布于 2024-10-06 16:16:53 字数 476 浏览 0 评论 0原文

我之前曾将 OpenCV 与 Android 结合使用,我一直尝试做的是在我的本机代码和 java 代码之间使用尽可能少的调用。当我查看适用于 Android 的 OpenCV port 时,似乎他们只是创建了一个每个本机函数的包装函数并从 java 调用它们。现在,除非我完全误解了 swig 包装器的原理和这个端口的整体思想,否则这不会比在本机代码中进行实际编码慢很多吗?我注意到在本机代码和java代码之间传递数据非常慢,所以我不明白为什么它似乎是这个端口中最正常的事情。

我自己确实使用过它,但我只是决定忽略所有包装器并按原样使用代码,并使用 Android 教程中提供的正常方式创建我自己的包装器。

所以我的问题是,我对缺点的看法是错误的吗?或者它们真的存在吗?在这方面使用 OpenCV 的真正优势是什么?我知道这些问题有些非正式,但我希望你们能帮助我。

I've worked with OpenCV in combination with Android before and what I always tried to do is to use as few calls as possible between my native code and my java code. When I look at the OpenCV port for Android though, it seems like they just create a wrapper function for every native function and call these from java. Now unless I totally misunderstand the principal of swig wrappers and the whole idea of this port, won't this be a lot slower than doing the actual coding in native code? I noticed that passing data between native code and java code is really slow, so I don't get why it seems to be the most normal thing in this port.

I did use it myself, but I just decided to ignore all the wrappers and use the code as it is and create my own wrapper using the normal way presented by Android tutorials.

So my question is, am I just wrong about the disadvantages? Or are they actually there and what is the real advantage of using OpenCV in this was? I know these questions are somewhat informal, but I hope you guys can help me out.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

唠甜嗑 2024-10-13 16:16:53

我无法给你你正在寻找的答案,但这就是我的想法:有很多 JNI 层的例子,它们包装了每个本机函数 - OpenGL、Android 的 Canvas 等。通过 JNI 调用比完全在本机中工作要慢代码,但问题是它对具体应用程序有什么影响吗?我相信在大多数情况下,与本机函数内花费的时间相比,这种时间损失可以忽略不计。然而,我赞成在 Android 应用程序的本机代码中做尽可能多的工作,主要不是因为执行速度更快,而是因为与 C 和 C++ 相比,Java 是一种尴尬的语言。

I can't give you the answer you're looking for, but here's what I think: there are many examples of JNI layers that wrap every native function - OpenGL, Android's Canvas, etc. Calling trough JNI is slower than working entirely in native code, but the question is does it make any difference for a concrete application? I believe in the majority of cases this time penalty is ignorable in comparison with the time spent inside the native functions. However I favor doing as much work as possible in native code for Android apps, not mainly because of the faster execution, but because Java is awkward language compared to C and C++.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文