如何在Android中仅包含必要的OpenCV库?

前端之家收集整理的这篇文章主要介绍了如何在Android中仅包含必要的OpenCV库?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在 Android应用程序中通过JNI使用OpenCV.
libopencv_java.so太大了,大约7M.显然,我只需要几个库.
我检查OpenCV4Android中的libs,找出一些静态库,比如libopencv_core.a
这是我在Android.mk中的新代码,包含必要的OpenCV库.我包括libopencv_core.a,libopencv_highgui.a,libopencv_imgproc.a和一些第三方库,它们是: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示例项目,了解如何使用静态链接.
原文链接:https://www.f2er.com/android/314990.html

猜你在找的Android相关文章