当前位置: 首页 > news >正文

ndk 编译opencv(去除libandroid.so mediandk依赖)

简单的bash运行

需要关注的:

  • OPENCV_EXTRA_MODULES_PATH : opencv contrib库
  • BUILD_opencv_XXX :添加contrib库后默认是contrib库全部编译,用这个控制需要关闭的
  • NDK的路径
export ANDROID_NDK=/media/hello/data/3rd_party/25.2.9519653# rm -rf ndk_build# mkdir ndk_build
cd ndk_buildcmake .. -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \-DANDROID_ABI="arm64-v8a" \-DANDROID_NDK=$ANDROID_NDK \-DANDROID_PLATFORM=android-29 \-DANDROID_STL=c++_shared \-DOPENCV_EXTRA_MODULES_PATH=/media/hello/data/3rd_party/opencv4.6.0/opencv_contrib/modules \-DBUILD_JAVA=OFF \-DBUILD_FAT_JAVA_LIB=OFF \-DBUILD_ANDROID_EXAMPLES=OFF \-DWITH_ONNX=ON \-Dfreetype_DIR=/media/hello/data/3rd_party_lib/freetype/2.13.2/arm64-v8a/lib/cmake/freetype/ \-DFREETYPE_INCLUDE_DIRS=/media/hello/data/3rd_party_lib/freetype/2.13.2/arm64-v8a/include/freetype2 \-DFREETYPE_LIBRARIES=/media/hello/data/3rd_party_lib/freetype/2.13.2/arm64-v8a/lib/libfreetype.so \-Dharfbuzz_DIR=/media/hello/data/3rd_party_lib/harfbuzz/9.0.0/arm64-v8a/lib/cmake/harfbuzz/ \-DHARFBUZZ_INCLUDE_DIRS=/media/hello/data/3rd_party_lib/harfbuzz/9.0.0/arm64-v8a/include/harfbuzz \-DHARFBUZZ_LIBRARIES=/media/hello/data/3rd_party_lib/harfbuzz/9.0.0/arm64-v8a/lib/libharfbuzz.so \-DWITH_FREETYPE=ON \-DBUILD_opencv_freetype=ON \-DCMAKE_BUILD_TYPE=Release \-DBUILD_SHARED_LIBS=ON \-DWITH_ARUCO=OFF \-DBUILD_opencv_barcode=OFF \-DBUILD_opencv_bgsegm=OFF \-DBUILD_opencv_datasets=OFF \-DBUILD_opencv_python2=OFF \-DBUILD_opencv_python3=OFF \-DBUILD_TESTS=OFF \-DCMAKE_INSTALL_PREFIX=/media/hello/data/3rd_party_lib/opencv/4.6.0/arm64-v8a \-DCMAKE_CXX_FLAGS="-frtti -Os" \-DCMAKE_C_FLAGS="-Os"make -j$(nproc)make install

在libopencv_videoio.so中会包含

hello@hello:/media/hello/data/3rd_party/opencv4.6.0/opencv-4.6.0$ objdump -x /media/hello/data/3rd_party_lib/opencv/4.6.0/arm64-v8a-src/sdk/native/libs/arm64-v8a/libopencv_videoio.s
o |grep NEEDEDNEEDED               libopencv_imgcodecs.soNEEDED               libdl.soNEEDED               liblog.soNEEDED               libopencv_imgproc.soNEEDED               libopencv_core.soNEEDED               libandroid.soNEEDED               libmediandk.soNEEDED               libcamera2ndk.soNEEDED               libc++_shared.soNEEDED               libc.so

对于简单的应用不需要和android互操作的,想要去除libandroid.so libmediandk.so的依赖:
在modules/videoio/cmake/init.cmake中注释掉下面这两个

# add_backend("android_mediandk" WITH_ANDROID_MEDIANDK)
# add_backend("android_camera" WITH_ANDROID_NATIVE_CAMERA)

去除后

hello@hello:/media/hello/data/3rd_party/opencv4.6.0/opencv-4.6.0$ objdump -x /media/hello/data/3rd_party_lib/opencv/4.6.0/arm64-v8a/sdk/native/libs/arm64-v8a/libopencv_videoio.so |grep NEEDEDNEEDED               libopencv_imgcodecs.soNEEDED               libdl.soNEEDED               libopencv_core.soNEEDED               libc++_shared.soNEEDED               libc.so
http://www.lryc.cn/news/536172.html

相关文章:

  • MySQL索引和其底层数据结构介绍
  • No module named ‘posepile.util‘
  • SQL布尔盲注、时间盲注
  • RocketMQ与kafka如何解决消息丢失问题?
  • Uniapp 获取定位详解:从申请Key到实现定位功能
  • 【Vue3 入门到实战】14. telePort 和 Suspense组件
  • Golang的并发编程案例详解
  • IS-IS 泛洪机制 | LSP 处理流程
  • 原型模式详解(Java)
  • 内存条2R×4 2400和4R×4 2133的性能差异
  • 安装并配置 MySQL
  • 常用的网络安全设备
  • 【蓝桥】线性DP--最快洗车时间
  • Spring Boot比Spring多哪些注解?
  • springboot021校园周边美食探索及分享平台
  • 【网络通信】传输层之UDP协议
  • Python环境搭建与量化交易开发:从基础到实战
  • 软著申请(六)软著返修流程【2025年最新版】
  • SOUI基于Zint生成Code11码
  • sqlilabs第八关
  • 基于HAL库的按钮实验
  • DeepSeek 突然来袭,AI 大模型变革的危机与转机藏在哪?
  • prompt技术结合大模型 生成测试用例
  • 【C++ 真题】P2920 [USACO08NOV] Time Management S
  • pip安装指定版本的包
  • 【pytest】获取所有用例名称并存于数据库
  • Java中原子操作的实现原理
  • 25农村发展研究生复试面试问题汇总 农村发展专业知识问题很全! 农村发展复试全流程攻略 农村发展考研复试真题汇总
  • 一维前缀和与二维前缀和
  • 3×2 MIMO系统和2×2 MIMO系统对比