Need help with opencv-mobile?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

nihui
542 Stars 90 Forks Apache License 2.0 81 Commits 9 Opened issues

Description

The minimal opencv for Android, iOS, ARM Linux, Windows, Linux, MacOS, WebAssembly

Services available

!
?

Need anything else?

Contributors list

# 223
C++
C
vulkan
Keras
84 commits
# 5,945
C
C++
arm-neo...
vulkan
1 commit

opencv-mobile

License release download

✔️ 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.15 and 4.5.3.

✔️ We also provide prebuild binary package for iOS with bitcode enabled, that the official package lacks.

✔️ All the binaries are compiled from source on github action, no virus, no backdoor, no secret code.

|opencv 4.5.3 android|package size| |---|---| |The official opencv|232MB| |opencv-mobile|16.2MB|

|opencv 4.5.3 ios|package size| |---|---| |The official opencv|179MB| |opencv-mobile|15.4MB|

|opencv 4.5.3 ios with bitcode|package size| |---|---| |The official opencv|missing :(| |opencv-mobile|54MB|

Download

Android

(armeabi-v7a, arm64-v8a, x86, x86_64) build with ndk r21d and android api 24.

iOS

(armv7, arm64, arm64e, i386, x86_64) build with Xcode 12.2.

iOS with bitcode

(armv7, arm64, arm64e, i386, x86_64) build with Xcode 12.2.

ARM Linux

(arm-linux-gnueabi, arm-linux-gnueabihf, aarch64-linux-gnu) build with ubuntu cross compiler.

Windows

(x86, x64) build with VS2015, VS2017 and VS2019.

Linux

(x86_64) build on Ubuntu-16.04, 18.04 and 20.04.

MacOS

(x86_64, arm64) build with Xcode 12.2.

WebAssembly

(basic, simd, threads, simd+threads) build with Emscripten 2.0.8.

Usage Android

  1. Extract archive to
    /app/src/main/jni/
  2. Modify
    /app/src/main/jni/CMakeListst.txt
    to find and link opencv
set(OpenCV_DIR ${CMAKE_SOURCE_DIR}/opencv-mobile-4.5.3-android/sdk/native/jni)
find_package(OpenCV REQUIRED)

target_link_libraries(your_jni_target ${OpenCV_LIBS})

Usage iOS and MacOS

  1. Extract archive, and drag
    opencv2.framework
    into your project

Usage ARM Linux, Windows, Linux, WebAssembly

  1. Extract archive to
    /
  2. Modify
    /CMakeListst.txt
    to find and link opencv
set(OpenCV_DIR ${CMAKE_SOURCE_DIR}/opencv-mobile-4.5.3-armlinux/arm-linux-gnueabihf/lib/cmake/opencv4)
find_package(OpenCV REQUIRED)

target_link_libraries(your_target ${OpenCV_LIBS})

How-to-build your custom package

step 1. download opencv source

shell
  wget -q https://github.com/opencv/opencv/archive/4.5.3.zip -O opencv-4.5.3.zip
  unzip -q opencv-4.5.3.zip
  cd opencv-4.5.3

step 2. strip zlib dependency and use stb-based highgui implementation (optional)

shell
  patch -p1 -i ../opencv-4.5.3-no-zlib.patch
  truncate -s 0 cmake/OpenCVFindLibsGrfmt.cmake
  rm -rf modules/gapi
  rm -rf modules/highgui
  cp -r ../highgui modules/

step 3. patch opencv source for no-rtti build (optional)

shell
  patch -p1 -i ../opencv-4.5.3-no-rtti.patch

step 4. apply your opencv options to opencv4cmakeoptions.txt

step 5. build your opencv package with cmake

shell
  mkdir -p build
  cd build
  cmake -DCMAKE_INSTALL_PREFIX=install \
    -DCMAKE_BUILD_TYPE=Release \
    `cat ../../opencv4_cmake_options.txt` \
    -DBUILD_opencv_world=OFF ..

step 6. make a package

shell
  zip -r -9 opencv-mobile-4.5.3.zip install

Some notes

  • 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 nerual 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

opencv modules included

|module|comment| |---|---| |opencvcore|Mat, matrix operations, etc| |opencvimgproc|resize, cvtColor, warpAffine, etc| |opencvhighgui|imread, imwrite| |opencvfeatures2d|keypoint feature and matcher, etc (not included in opencv 2.x package)| |opencvphoto|inpaint, etc| |opencvvideo|opticalflow, etc|

opencv modules discarded

|module|comment| |---|---| |opencvandroidcamera|use android Camera api instead| |opencvcalib3d|camera calibration, rare uses on mobile| |opencvcontrib|experimental functions, build part of the source externally if you need| |opencvdnn|very slow on mobile, try ncnn for nerual network inference on mobile| |opencvdynamicuda|no cuda on mobile| |opencvflann|feature matching, rare uses on mobile, build the source externally if you need| |opencvgapi|graph based image processing, little gain on mobile| |opencvgpu|no cuda/opencl on mobile| |opencvimgcodecs|link with opencvhighgui instead| |opencvjava|wrap your c++ code with jni| |opencvjs|write native code on mobile| |opencvlagacy|various good-old cv routines, build part of the source externally if you need| |opencvml|train your ML algorithm on powerful pc or server| |opencvnonfree|the SIFT and SURF, use ORB which is faster and better| |opencvobjdetect|HOG, cascade detector, use deep learning detector which is faster and better| |opencvocl|no opencl on mobile| |opencvpython|no python on mobile| |opencvshape|shape matching, rare uses on mobile, build the source externally if you need| |opencvstitching|image stitching, rare uses on mobile, build the source externally if you need| |opencvsuperres|do video super-resolution on powerful pc or server| |opencvts|test modules, useless in production anyway| |opencvvideoio|use android MediaCodec or ios AVFoundation api instead| |opencvvideostab|do video stablization on powerful pc or server| |opencv_viz|vtk is not available on mobile, write your own data visualization routines|

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.