gpt4 book ai didi

opencv - 如何在 Android 中只包含必要的 OpenCV 库?

转载 作者:太空宇宙 更新时间:2023-11-03 20:47:13 26 4
gpt4 key购买 nike

我在我的 Android 应用程序中通过 JNI 使用 OpenCV。libopencv_java.so太大了,7M左右。显然,我只需要几个图书馆。我检查了 OpenCV4Android 中的库,发现了一些静态库,例如 libopencv_core.a这是我在 Android.mk 中包含必要的 OpenCV 库的新代码。我包括 libopencv_core.a、libopencv_highgui.a、libopencv_imgproc.a 和一些第 3 方库,它们是:liblibjasper.a、liblibjpeg.a、liblibpng.a、liblibtiff.a

include $(CLEAR_VARS)
LOCAL_MODULE := libopencv_highgui_prebuilt
LOCAL_SRC_FILES := libopencv_highgui.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/OpenCV242AndroidSDKNativeJNI/include
include $(PREBUILT_STATIC_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE := libopencv_imgproc_prebuilt
LOCAL_SRC_FILES := libopencv_imgproc.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/OpenCV242AndroidSDKNativeJNI/include
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libopencv_core_prebuilt
LOCAL_SRC_FILES := libopencv_core.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/OpenCV242AndroidSDKNativeJNI/include
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := liblibjpeg_prebuilt
LOCAL_SRC_FILES := liblibjpeg.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/OpenCV242AndroidSDKNativeJNI/include
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := liblibpng_prebuilt
LOCAL_SRC_FILES := liblibpng.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/OpenCV242AndroidSDKNativeJNI/include
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := liblibtiff_prebuilt
LOCAL_SRC_FILES := liblibtiff.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/OpenCV242AndroidSDKNativeJNI/include
include $(PREBUILT_STATIC_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE := liblibjasper_prebuilt
LOCAL_SRC_FILES := liblibjasper.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/OpenCV242AndroidSDKNativeJNI/include
include $(PREBUILT_STATIC_LIBRARY)



include $(CLEAR_VARS)
LOCAL_MODULE := native_jni
LOCAL_SRC_FILES := jni_part.cpp
LOCAL_CFLAGS += -fpermissive

LOCAL_STATIC_LIBRARIES += libopencv_highgui_prebuilt
LOCAL_STATIC_LIBRARIES += libopencv_imgproc_prebuilt
LOCAL_STATIC_LIBRARIES += libopencv_core_prebuilt
LOCAL_STATIC_LIBRARIES += liblibjpeg_prebuilt
LOCAL_STATIC_LIBRARIES += liblibpng_prebuilt
LOCAL_STATIC_LIBRARIES += liblibtiff_prebuilt
LOCAL_STATIC_LIBRARIES += liblibjasper_prebuilt

LOCAL_LDLIBS += -llog -ldl
LOCAL_LDLIBS += -ljnigraphics
LOCAL_LDLIBS += -lz

include $(BUILD_SHARED_LIBRARY)

但它没有经过编译。一个很长的错误列表,都与断言失败有关:

/usr/src/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6.x-google/../../../../arm-linux-androideabi/bin/ld: BFD (GNU Binutils) 2.21 assertion fail /usr/local/google/home/andrewhsieh/ndk-andrewhsieh/src/build/../binutils/binutils-2.21/bfd/elf32-arm.c:10190
Install : libnative_jni.so => libs/armeabi-v7a/libnative_jni.so
/usr/src/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6.x-google/../../../../arm-linux-androideabi/bin/ld: BFD (GNU Binutils) 2.21 assertion fail /usr/local/google/home/andrewhsieh/ndk-andrewhsieh/src/build/../binutils/binutils-2.21/bfd/elf32-arm.c:10190

我也尝试过改变这些静态库的顺序;但它不起作用。有什么建议吗?

最佳答案

静态库链接只会引入您在代码中实际使用的功能,而不是像 .so 中那样引入整个库。
查看 OpenCV Android 示例项目以了解如何使用静态链接。

关于opencv - 如何在 Android 中只包含必要的 OpenCV 库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22117882/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com