OpenCV 4.11.0-pre
Open Source Computer Vision
Loading...
Searching...
No Matches
Installation in iOS

Next Tutorial: OpenCV iOS Hello

Original author Artem Myagkov, Eduard Feicho, Steve Nicholson
Compatibility OpenCV >= 3.0
Warning
This tutorial can contain obsolete information.

Required Packages

  • CMake 2.8.8 or higher
  • Xcode 4.2 or higher

Getting the Cutting-edge OpenCV from Git Repository

Launch Git client and clone OpenCV repository from GitHub.

In MacOS it can be done using the following command in Terminal:

cd ~/<my_working _directory>
git clone https://github.com/opencv/opencv.git

If you want to install OpenCV’s extra modules, clone the opencv_contrib repository as well:

cd ~/<my_working _directory>
git clone https://github.com/opencv/opencv_contrib.git

Building OpenCV from Source, using CMake and Command Line

  1. Make sure the xcode command line tools are installed:
    xcode-select --install
  2. Build OpenCV framework:
    cd ~/<my_working_directory>
    python opencv/platforms/ios/build_framework.py ios
  3. To install OpenCV’s extra modules, append --contrib opencv_contrib to the python command above. Note: the extra modules are not included in the iOS Pack download at OpenCV Releases. If you want to use the extra modules (e.g. aruco), you must build OpenCV yourself and include this option:
    cd ~/<my_working_directory>
    python opencv/platforms/ios/build_framework.py ios --contrib opencv_contrib
  4. To exclude a specific module, append --without <module_name>. For example, to exclude the "optflow" module from opencv_contrib:
    cd ~/<my_working_directory>
    python opencv/platforms/ios/build_framework.py ios --contrib opencv_contrib --without optflow
  5. The build process can take a significant amount of time. Currently (OpenCV 3.4 and 4.1), five separate architectures are built: armv7, armv7s, and arm64 for iOS plus i386 and x86_64 for the iPhone simulator. If you want to specify the architectures to include in the framework, use the --iphoneos_archs and/or --iphonesimulator_archs options. For example, to only build arm64 for iOS and x86_64 for the simulator:
    cd ~/<my_working_directory>
    python opencv/platforms/ios/build_framework.py ios --contrib opencv_contrib --iphoneos_archs arm64 --iphonesimulator_archs x86_64

If everything’s fine, the build process will create ~/<my_working_directory>/ios/opencv2.framework. You can add this framework to your Xcode projects.

Further Reading

You can find several OpenCV+iOS tutorials here OpenCV iOS.