My first post in this blog was about building OpenCV for iOS devices (iPhone, iPad, iPod and so on). But the build process that i used is not trivial at all. I received a lot of feedbacks and questions about building OpenCV, setting up XCode build environment. Today i made your life much easier. I have a gift - a build script, which will **build OpenCV **library for your iPhone, iPad, iPod or any other iOS based Apple device right in one click! Update = Now build script supports XCode 4 and iOS 4.3 SDK Sounds cool, yeah? Well, It’s all true. Actually, my script does exactly the same things as i mentioned in original article. But without user interaction.
This post is outdated.
Current version of OpenCV supports iOS toolchain and can be build in much easier way. You are welcome to read this post for educational purposes. It's 99.9% chance that you will not be able to build OpenCV using instructions decribed here.
Let’s build it!
We start, as usual, from getting a fresh source code from OpenCV repository:
svn co http://code.opencv.org/svn/opencv/trunk
Or, if you already have checked out in the past, run svn update command:
svn update
To start build process you should call build script with two required arguments: directory, where OpenCV sources located and directory, where libraries and headers will be places:
sh BuildOpenCV.sh trunk/opencv/ opencv_ios_build
Hit Enter and take a rest - it will take 5-10 minutes. There will be compilation errors. Something like:
The following build commands failed:
opencv_highgui:
CompileC cap_qtkit.o cap_qtkit.mm normal armv7 objective-c++ com.apple.compilers.gcc.4_2
opencv_ts:
CompileC ts_gtest.o ts_gtest.cpp normal armv7 c++ com.apple.compilers.gcc.4_2
(2 failures)
It’s okay. For now, OpenCV has to official iOS support, so some parts of code will cause compilation errors (highgui module). Maybe in future this will change, but ignore them now. If you are getting other errors, it looks like either you doing something wrong, or repository build is broken. When all is done, your build directory should looks like this:
Lib folder contains all necessary static libraries, Include - OpenCV headers.
How it works
Configure OpenCV using CMake. I disabled enabled by default options like SSE, SSE2, support of video input libraries, because they are not actual for iOS
Run batch build process from command line using xcodebuild tool. With their help we build all necessary libs.
Copy libraries to appropriate directories and create universal ones.
Run Install target to get OpenCV headers.
Script source
Here is script listing. Don’t start copy&pasting it, there are download link at the end of the post.