在Kotlin Multiplatform Mobile(KMM)项目中使用OpenCV

发布于 2025-01-22 18:14:34 字数 1406 浏览 3 评论 0原文

设置:

我们当前正在使用iOS和Android上的OPENCV进行图像处理。在Android上,我们将OPENCV导入为.aar,在iOS上,我们通过可可录将其导入,他们称其为相同的基础功能。

问题:

我们想进行一个KMM项目,可以在其中导入OpenCV并共享业务逻辑。我们正在使用期望/实际在平台特定代码中依赖OpenCV。 我们可以通过在Androidmain中导入相同的来使其适用于Android。 我们的问题是iOS。当前,KMM不支持与C ++的互操作性(写入OpenCV) - 请参见 https:/noreferrer“> https:/ /kotlinlang.org/docs/roadmap.html#remaved-items

我们尝试的是:

我们尝试通过gradle链接.framework。文件指向OpenCV中的.hpp文件,但是在尝试同步Gradle时,我们会收到一个错误xxx.hpp标头。

build.gradle.kts

iosX64() {
    compilations.getByName("main") {
        val OpenCV by cinterops.creating {
            // Path to .def file
            defFile("src/iosMain/cinterop/OpenCV.def")

            // Directories for header search (an analogue of the -I<path> compiler option)
            includeDirs("../iosApp/Pods/OpenCV/opencv2.framework/Headers/Core")
        }
    }

    binaries.all {
        // Linker options required to link to the library.
        linkerOpts("-L/../iosApp/Pods/OpenCV/opencv2.framework", "-lopencv2")
    }
}

opencv.def

headers = cvstd.hpp
package = OpenCV

问题:

是否有任何方法可以依赖kmm中的opencv?

Setup:

We are currently using OpenCV on iOS and Android for image processing. On Android we import OpenCV as a .aar and on iOS we import it via Cocoapods, and they call the same underlying functions.

Problem:

We would like to have a KMM project where we can import OpenCV and share the business logic. We are using expect/actual to depend on OpenCV in platform specific code.
We can make it work for Android by importing the same .aar in androidMain.
Our problem is with iOS. Currently KMM doesn't support interoperability with C++ (which OpenCV is written in) - see https://kotlinlang.org/docs/roadmap.html#removed-items

What we have tried:

We tried to link a .framework via Gradle and create .def files to point to the .hpp files in OpenCV but we get an error xxx.hpp header must be compiled as C++ when trying to sync Gradle.

build.gradle.kts

iosX64() {
    compilations.getByName("main") {
        val OpenCV by cinterops.creating {
            // Path to .def file
            defFile("src/iosMain/cinterop/OpenCV.def")

            // Directories for header search (an analogue of the -I<path> compiler option)
            includeDirs("../iosApp/Pods/OpenCV/opencv2.framework/Headers/Core")
        }
    }

    binaries.all {
        // Linker options required to link to the library.
        linkerOpts("-L/../iosApp/Pods/OpenCV/opencv2.framework", "-lopencv2")
    }
}

OpenCV.def

headers = cvstd.hpp
package = OpenCV

Question:

Is there any way to depend on OpenCV in KMM?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文