This project provides the minimal build of opencv library for the Android, iOS and ARM Linux platforms.
Packages for Windows, Linux, MacOS and WebAssembly are available now.
We provide prebuild binary packages for opencv 2.4.13.7, 3.4.20 and 4.9.0.
We also provide prebuild binary package for iOS/iOS-Simulator with bitcode enabled, that the official package lacks.
We also provide prebuild binary package for Mac-Catalyst and Apple xcframework, that the official package lacks.
All the binaries are compiled from source on github action, no virus, no backdoor, no secret code.
opencv 4.9.0 package size | The official opencv | opencv-mobile |
---|---|---|
source zip | 93.0 MB | 9.91 MB |
android | 242 MB | 17.6 MB |
ios | 202 MB | 9.57 MB |
ios+bitcode | missing :( | 33.7 MB |
https://github.com/nihui/opencv-mobile/releases/latest
Source | ||||
Android (armeabi-v7a, arm64-v8a, x86, x86_64) | ||||
iOS (armv7, arm64, arm64e) | iOS-Simulator (i386, x86_64, arm64) | |||
macOS (x86_64, arm64) | Mac-Catalyst (x86_64, arm64) | |||
Apple xcframework (ios, ios-simulator, ios-maccatalyst, macos) | ||||
Ubuntu-20.04 (x86_64) | Ubuntu-22.04 (x86_64) | |||
ARM-Linux (arm-linux-gnueabi, arm-linux-gnueabihf, aarch64-linux-gnu) | ||||
VS2015 (x86, x64) | VS2017 (x86, x64) | VS2019 (x86, x64) | VS2022 (x86, x64) | |
WebAssembly (basic, simd, threads, simd+threads) | ||||
milkv-duo riscv64-linux-musl ✅ HW JPG decoder ✅ MIPI CSI camera |
licheerv-nano riscv64-linux-musl ✅ HW JPG decoder ✅ MIPI CSI camera |
luckfox-pico arm-linux-uclibcgnueabihf ✅ HW JPG encoder ✅ MIPI CSI camera |
yuzuki-lizard arm-linux-uclibcgnueabihf |
tinyvision arm-linux-uclibcgnueabihf ✅ HW JPG decoder ✅ HW JPG encoder ✅ MIPI CSI camera |
yuzuki-chameleon arm-openwrt-linux-gnueabi ✅ HW JPG decoder ✅ HW JPG encoder |
purple-pi arm-linux-uclibcgnueabihf |
myir-t113i arm-linux-gnueabi ✅ HW JPG decoder ✅ HW JPG encoder |
<project dir>/app/src/main/jni/
<project dir>/app/src/main/jni/CMakeListst.txt
to find and link opencvset(OpenCV_DIR ${CMAKE_SOURCE_DIR}/opencv-mobile-4.9.0-android/sdk/native/jni)
find_package(OpenCV REQUIRED)
target_link_libraries(your_jni_target ${OpenCV_LIBS})
opencv2.framework
or opencv2.xcframework
into your project<project dir>/
<project dir>/CMakeListst.txt
to find and link opencv-DOpenCV_STATIC=ON
to cmake option for windows buildset(OpenCV_DIR ${CMAKE_SOURCE_DIR}/opencv-mobile-4.9.0-armlinux/arm-linux-gnueabihf/lib/cmake/opencv4)
find_package(OpenCV REQUIRED)
target_link_libraries(your_target ${OpenCV_LIBS})
We reduce the binary size of opencv-mobile in 3 ways
Steps 1 and 2 are relatively cumbersome and difficult, and require intrusive changes to the opencv source code. If you want to know the details, please refer to the steps in .github/workflows/release.yml
The opencv-mobile source code package is the result of steps 1 and 2. Based on it, we can adjust the cmake option to compile our own package and further delete and add modules and other functions.
step 1. download opencv-mobile source
wget -q https://github.com/nihui/opencv-mobile/releases/latest/download/opencv-mobile-4.9.0.zip
unzip -q opencv-mobile-4.9.0.zip
cd opencv-mobile-4.9.0
step 2. apply your opencv option changes to options.txt
vim options.txt
step 3. build your opencv package with cmake
mkdir -p build
cd build
cmake -DCMAKE_INSTALL_PREFIX=install \
-DCMAKE_BUILD_TYPE=Release \
`cat ../options.txt` \
-DBUILD_opencv_world=OFF ..
make -j4
make install
step 4. make a package
zip -r -9 opencv-mobile-4.9.0-mypackage.zip install
The minimal opencv build contains most basic opencv operators and common image processing functions, with some handy additions like keypoint feature extraction and matching, image inpainting and opticalflow estimation.
Many computer vision algorithms that reside in dedicated modules are discarded, such as face detection etc. You could try deep-learning based algorithms with neural network inference library optimized for mobile.
Image IO functions in highgui module, like cv::imread
and cv::imwrite
, are re-implemented using stb for smaller code size. GUI functions, like cv::imshow
, are discarded.
cuda and opencl are disabled because there is no cuda on mobile, no opencl on ios, and opencl on android is slow. opencv on gpu is not suitable for real productions. Write metal on ios and opengles/vulkan on android if you need good gpu acceleration.
C++ RTTI and exceptions are disabled for minimal build on mobile platforms and webassembly build. Be careful when you write cv::Mat roi = image(roirect);
:P
module | comment |
---|---|
opencv_core | Mat, matrix operations, etc |
opencv_imgproc | resize, cvtColor, warpAffine, etc |
opencv_highgui | imread, imwrite |
opencv_features2d | keypoint feature and matcher, etc (not included in opencv 2.x package) |
opencv_photo | inpaint, etc |
opencv_video | opticalflow, etc |
module | comment |
---|---|
opencv_androidcamera | use android Camera api instead |
opencv_calib3d | camera calibration, rare uses on mobile |
opencv_contrib | experimental functions, build part of the source externally if you need |
opencv_dnn | very slow on mobile, try ncnn for neural network inference on mobile |
opencv_dynamicuda | no cuda on mobile |
opencv_flann | feature matching, rare uses on mobile, build the source externally if you need |
opencv_gapi | graph based image processing, little gain on mobile |
opencv_gpu | no cuda/opencl on mobile |
opencv_imgcodecs | link with opencv_highgui instead |
opencv_java | wrap your c++ code with jni |
opencv_js | write native code on mobile |
opencv_legacy | various good-old cv routines, build part of the source externally if you need |
opencv_ml | train your ML algorithm on powerful pc or server |
opencv_nonfree | the SIFT and SURF, use ORB which is faster and better |
opencv_objdetect | HOG, cascade detector, use deep learning detector which is faster and better |
opencv_ocl | no opencl on mobile |
opencv_python | no python on mobile |
opencv_shape | shape matching, rare uses on mobile, build the source externally if you need |
opencv_stitching | image stitching, rare uses on mobile, build the source externally if you need |
opencv_superres | do video super-resolution on powerful pc or server |
opencv_ts | test modules, useless in production anyway |
opencv_videoio | use android MediaCodec or ios AVFoundation api instead |
opencv_videostab | do video stablization on powerful pc or server |
opencv_viz | vtk is not available on mobile, write your own data visualization routines |
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。