Computer vision with iOS Part 1: Building an OpenCV framework

by Robin Summerhill on September 7, 2011

  1. Introduction
  2. The example project
  3. Using the OpenCV framework in your own projects
  4. Rebuilding the OpenCV framework

Update: Nov 28 2011 – The OpenCV framework has been rebuilt using opencv svn revision 7017
Update: Check out Part 2 of our series on computer vision.


This article is the first in a series looking at computer vision for iOS using the OpenCV library. OpenCV is released under the BSD licence and so is free for both academic and commercial use. It includes optimised implementations of all the standard algorithms used today in the field of computer vision and has a huge user base across the Linux, Windows, Mac and Android worlds. In the past, OpenCV has been difficult to build for iOS. However, recent sterling work by the OpenCV team has added iOS build support and video capture.

In this article we aim to reduce the learning curve even further by providing the OpenCV library as an iOS framework that can be added to your own Xcode projects simply by dragging and dropping. We also provide a build script for re-building the framework should you need to, and an example project that wraps everything up with a neat demo of video capture and image processing using OpenCV on iOS.

We start by walking you through the example project then describe how to use the OpenCV framework in your own projects. Finally, we describe how to re-build the OpenCV framework and explain how the build script works.

As ever, we build on the work of others that have gone before us. We would like to acknowledge the OpenCV team, Eugene Khvedchenya for previous work on building OpenCV for iOS and Diney Bomfim for work on iOS frameworks.

The example project

The example app
The example project is hosted on GitHub. You can visit the GitHub project page at:
or download a zip archive of the project directly at:
The project includes a pre-built OpenCV framework (OpenCV svn revision 7017), a build script to rebuild the framework and an example app that demonstrates video capture and simple image processing using OpenCV.

To build and run the app, open the OpenCVClient Xcode project and hit ‘Run’. Note that video capture is not supported on the iPhone Simulator. Run the example app on an iOS device to see video capture in action.

The app starts by running some simple performance tests converting between UIImages and cv::Mat objects. Timing results are output to the console. After the performance tests have completed the main interface is shown. Tap the ‘Capture’ button to capture a video frame. The frame is processed using the Canny edge detection algorithm to exercise some of OpenCV’s image processing functions and the results are displayed on screen. Use the sliders to adjust the low and high algorithm threshold values. The time taken to process the frame is also displayed. Typical values are around 90ms on the iPhone 4 and around 200ms on the iPhone 3.

Using the OpenCV framework in your own projects

Adding the OpenCV Framework

The easiest way to add the OpenCV framework to your own project is to drag the OpenCV.framework folder from the example project folder in Finder and drop it onto the ‘Frameworks’ group of your target project in the Xcode Project navigator. Check the option ‘Copy items into destination group’s folder’ in the dialog that appears if you want to copy the OpenCV framework into your target project. If you are sharing a copy of the framework between multiple projects or have a common build location for the framework then you will want to leave the option unchecked.

Alternatively, you can navigate to the ‘Build Phases’ tab of the Project properties pane in Xcode. Drop down the ‘Link Binary With Libraries’ build phase item and click the ‘+’ button. Select “Add Other…’ from the dialog that appears and navigate to the OpenCV.framework folder.

Once you have added the OpenCV framework, your project is set up to link against the OpenCV libraries automatically and the OpenCV header files are also made available. Refer to OpenCV header files in your project #include statements using the framework-relative notation (i.e #include <OpenCV/opencv/.../...>).

Add additional required frameworks

To use the OpenCV framework you must add a few extra Apple-supplied frameworks to your project. To do this, navigate to the ‘Build Phases’ tab of the Project properties pane in xCode. Drop down the ‘Link Binary With Libraries’ build phase item and click the ‘+’ button. Add the frameworks and libraries shown below. The frameworks in the first column of the table are required. The frameworks in the second column are optional and are only needed if you are using the video capture support included in OpenCV’s highgui module.

Framework Required Optional (required for video capture)

When you have added all the required frameworks, your project’s Build Phases tab in the Project Properties pane should look like this:

The Build Phases tab in the XCode Project Properties pane

Include the OpenCV headers

The headers that declare the OpenCV and OpenCV2 APIs are provided as part of the OpenCV framework. The headers can be browsed by dropping down the OpenCV.framework item in the ‘Frameoworks’ group of the Project navigator in XCode. To write OpenCV client code you need to include these headers in your project. The easiest way to do this is to modify your pre-complied header file (<project name>-Prefix.pch) to add the three new lines shown below:

// Add this new section BEFORE the #import statements for UIKit and Foundation
#ifdef __cplusplus
    #import <OpenCV/opencv2/opencv.hpp>
// Existing #import statements
#ifdef __OBJC__
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>

You must also change the extension of any source file in your project in which you wish to use OpenCV from ‘.m‘ to ‘.mm‘. This indicates to the compiler that the source file includes mixed Objective-C and C++ code. Note that individual source files that don’t use OpenCV can remain as ‘.m‘ files.

For the curious, the OpenCV headers must be included before UIKit.h and Foundation.h because OpenCV defines a MIN macro that conflicts with the MIN function defined by the Apple frameworks. If you include the OpenCV headers after UIKit.h and Foundation.h you will receive compilation errors such as ‘LLVM GCC 4.2 Error: Statement-expressions are allowed only inside functions’. Including the OpenCV headers first and surrounding the #import with the __cplusplus conditional test avoids this problem and means that you can still use plain Objective-C for ‘.m‘ files in your project that don’t call the OpenCV APIs.

Using the UIImage extensions

The example project includes extensions to UIImage for converting to and from cv:Mat objects. These are provided as a UIImage category in two source files (UIImage+OpenCV.h and .mm). To use the extensions simply add the two source files to your project and make use of the following new UIImage methods and properties:

@interface UIImage (UIImage_OpenCV)
// Returns an autoreleased UIImage from cv::Mat
+(UIImage *)imageWithCVMat:(const cv::Mat&amp;)cvMat;
// Initialises a UIImage from cv::Mat
-(id)initWithCVMat:(const cv::Mat&amp;)cvMat;
// Returns cv::Mat object from UIImage
@property(nonatomic, readonly) cv::Mat CVMat;
// Returns grayscale cv::Mat object from UIImage
@property(nonatomic, readonly) cv::Mat CVGrayscaleMat;

Rebuilding the OpenCV framework

Included with the example project is a shell script ( that automates building and packaging of the OpenCV libraries. Before starting you will need to make sure that you have Subversion and CMake on your build system. Subversion is required to download the latest OpenCV sources and CMake is the build system used by the OpenCV team. Binary installers for both are provided at the locations listed below:

Subversion for Mac
CMake for Mac

Obtaining the OpenCV source

First change to the directory where you want the source files to be extracted. If you are following the layout of the example project, this is the opencv subdirectory of the project root directory:

cd <project root>/opencv

Next, checkout the latest sources from the offical repository. At the time of writing, support for iOS builds and video capture have not made it into the stable OpenCV release so we are using the latest sources in ‘trunk’. (Note the final period at the end of the command):

svn co .

You should now have the OpenCV source tree under your chosen location:

Directory listing of OpenCVForiOS

Directory listing of OpenCVForiOS project folder

Building OpenCV

The opencvbuild shell script takes two command-line arguments: the head of the OpenCV source tree and the location where you want the build to be performed. For the example project we built the framework in the project root directory (again, note the final period as the second argument to opencvbuild):

cd <project root>
./opencvbuild opencv/opencv .

If the build completed successfully you should now have the OpenCV framework along with three library packages in your chosen build location:

OpenCV.framework framework for use with iOS device or Simulator
OpenCV_iPhoneOS libraries and headers for use with iOS device
OpenCV_iPhoneSimulator libraries and headers for use with iPhone Simulator
OpenCV_Universal fat libraries and headers for use with iOS device or Simulator

The library packages are built as an intermediate step before the framework is assembled. You can choose to remove them or you may prefer to link against the individual libraries instead of using the OpenCV framework.

How it works

Most of the heavy lifting in opencvbuild is delegated to cmake and xcodebuild. First, an Xcode project file is created using cmake and the CMake configuration files provided by the OpenCV team. From revision 6675, support for iOS builds was introduced, which makes our life much easier. A command-line build is then initiated using xcodebuild driven by the Xcode project file created in the first step.

The build script actually performs the build twice, once targeting iOS devices (armv6 and armv7) and once targeting the Simulator (i386). The resulting binaries are then combined with the lipo tool to produce fat binaries that support operation on both device and simulator. These fat binaries can be found in the OpenCV_Universal intermediate build directory.

Finally, the libraries and OpenCV header files are assembled into the OpenCV framework. Two problems arise here, which the script overcomes with a couple of sneaky tricks. First, a framework for iOS can only include a single static library but the OpenCV build has produced 11 that we need to include. To get around this restriction the script simply combines the 11 libraries into one using libtool and then moves the resulting super-library into place within the framework. Secondly, the OpenCV headers use relative paths in #include statements, which makes them difficult to use without configuring header search paths within your project settings. To solve this, the script replaces any occurrence of a relative include path (i.e. "opencv/.../...") with a framework-based include path (i.e. <OpenCV/opencv/.../...>). The headers are added to the framework so that the whole package, library and headers, can be added to your project in a single step.

Links to example project source code

Git –
Download zip –

Share and Enjoy:
  • Print
  • email
  • Digg
  • Facebook
  • Google Bookmarks
  • Reddit
  • Twitter

{ 100 comments… read them below or add one }

Joe Pagliaro September 14, 2011 at 3:22 pm

Thank you!

This article made it a breeze to get up and running with OpenCV on iOS. It is very well written. I am new to OpenCV, and the sample project you provide, OpenCVForiPhone, provided a great start. I anticipate future articles in this series.


Robin Summerhill September 14, 2011 at 3:30 pm

Glad you liked it! We always appreciate hearing from our readers – the next installment is in the works…


Matt Montag September 25, 2011 at 8:01 pm

I am having trouble building the latest OpenCV source with this script. See my stackoverflow question here:


Dev2rights September 30, 2011 at 6:03 am

Hi Robin,

I have used this tutorial and modified it for a open source tutorial app we are working on. The tutorial is there to benchmark various combinations of feature trackers (MSER, FAST, SURF , STAR) and various feature detector and comparison algorithms. We will be releasing this as a tutorial with source code when completed, do you mind ?

Jim @ Dev2rights


Fraser Hardy March 6, 2012 at 2:01 pm

Hi Jim,

I would be interested to see this tutorial. Is it available online yet?



Irad Gilboa October 9, 2011 at 5:19 pm

Hi Robin,
Thank you for this great tutorial and the excellent sample code (the pre-built OpenCV framework is just what I was looking for).
Using your tutorial I was able to include openCV in my own project in no time – you just made my day!

Keep up the good work,


Phy October 18, 2011 at 6:02 am

Hi Robin,
and thank you for sharing your script! I’ve added a comment here:

Can you give me few hints of what can be wrong?
XCode 4.2
CMake 2.6-4
opencv rev 6769

thank you in advance!!!


Daniel Kiedrowski October 25, 2011 at 5:28 pm

thanks for your work.
Two Questions:
1. What Version of OpenCV is in the framework?
2. How can I use cv::findContours. Everytime I use it with your framework I get assertions.



Daniel Kiedrowski October 26, 2011 at 1:54 am

Hello again.
Never mind question 2. After some hours of recompiling OpenCV and looking at my code, I finally found my stupid mistake. I think I share it here, in case someone else is doing it.

Instead of writing std::vector<std::vector > to define a container for the resulting contour, I wrote std::vector<std::vector > what leads to my compiler mixing up cv::Point with Point (which actually exist, perhaps in the iOS SDK) and giving me this annoying assertions.



patrick July 6, 2012 at 11:20 pm

this saved me – made the same mistake


Sarpdoruk TAHMAZ November 6, 2011 at 8:14 am

Thanks for the great and well written article. Thanks to you I was able to include OpenCV to my iOS project.


w00 November 8, 2011 at 5:53 am

Hi, i’m trying to do templateMatching, but i think i’m doing it wrong because the ouput that i get doesn’t include any data if the object is found where. Atleast, i don’t see it…

If you have the time could you please take a look at:


Simona October 2, 2014 at 11:18 am

Hi Kevin,Thanks a lot for your reply despite you being away.Per your sugtesgion I took your makefile and used the relevant part of the makefile provided with flycap. Compiled smoothly.Here is what I used:CC = g++CFLAGS = -g -WallSRCS = ocv_usingflycap.cppPROG = ocvpgOPENCV = `pkg-config opencv cflags libs`FLYCAP = -L../../lib -lflycapture${D} -lflycapturegui${D} `pkg-config libs gtkmm-2.4` `pkg-config libs giomm-2.4` `pkg-config libs libglademm-2.4` `pkg-config libs gthread-2.0`LIBS = $(OPENCV) $(FLYCAP)$(PROG):$(SRCS)$(CC) $(CFLAGS) -o $(PROG) $(SRCS) $(LIBS)Note: the FlyCapture2.h is located in the /include directory where the flycapture sdk is installed. However rather than providing the path to that directory, I copied all the .h to where my program (yours actually) is located.Cheers,Ludo


WANG Chi November 8, 2011 at 8:48 pm

Great, will try out this tonight :)


yiqunc November 21, 2011 at 9:31 pm

hi ROBIN, your tutorial is so helpful! big thanks!
I have some problem when trying to rebuild the opencv source with your “” script.
I noticed that build for the Simulator was successful but failed for the Device build, I am using:
CMake 2.8.6
opencv Rev: 6988

The error info is like this:
In file included from /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.0.sdk/usr/include/mach/task.h:37:
In file included from /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.0.sdk/usr/include/mach/mach_interface.h:50:
In file included from /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.0.sdk/usr/include/mach/mach.h:67:
In file included from /Users/yiqunc/opencv/opencv/modules/core/src/system.cpp:76:
/Applications/xcode4.2.0/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/include/mach/arm/task.h:438:2: error: unknown type name ‘mach_zone_name_array_t’; did you mean ‘mach_port_name_array_t’? [3]
mach_zone_name_array_t *names,
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.0.sdk/usr/include/mach/port.h:107:27: note: ‘mach_port_name_array_t’ declared here [3]
typedef mach_port_name_t *mach_port_name_array_t;
In file included from /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.0.sdk/usr/include/mach/task.h:37:
In file included from /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.0.sdk/usr/include/mach/mach_interface.h:50:
In file included from /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.0.sdk/usr/include/mach/mach.h:67:
In file included from /Users/yiqunc/opencv/opencv/modules/core/src/system.cpp:76:
/Applications/xcode4.2.0/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/include/mach/arm/task.h:440:2: error: unknown type name ‘task_zone_info_array_t’; did you mean ‘zone_info_array_t’? [3]
task_zone_info_array_t *info,
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.0.sdk/usr/include/mach_debug/zone_info.h:91:22: note: ‘zone_info_array_t’ declared here [3]
typedef zone_info_t *zone_info_array_t;
2 warnings and 2 errors generated.


The following build commands failed:
CompileC /Users/yiqunc/opencv/tmp/modules/core/ modules/core/src/system.cpp normal armv7 c++
(1 failure)

I also have checked this file “/Applications/xcode4.2.0/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/include/mach/arm/task.h” and it does inculde another header file “” which includes which contains the declaration of “mach_zone_name_array_t”.

could you please give me some hints?

Thank you very much!



Robin Summerhill November 22, 2011 at 8:26 am

It sounds like there have been some changes since 6675. I will take a look and make any fixes needed. Thanks for pointing this out.


yiqunc November 22, 2011 at 7:14 pm

Thanks Robin, you have done an awesome job!


Robin Summerhill November 28, 2011 at 10:37 am

I’ve rebuilt the framework using the latest revision from the OpenCV repository (7017) and updated the project repository on GitHub. I didn’t see any build problems. Let me know if you are still having issues rebuilding.


Xikitap October 1, 2014 at 5:36 pm

Hi Amr,We do not have a Unity plugin yet, and we have not tried inatnretigg the SDK in this environment either, so I fear we won’t be able to provide you much help on this subject.It might nevertheless be possible to integrate our SDK in Unity using our current iOS and Android wrapper, but it will probably require some work on your side to get things together: if you decide to try doing so, we’ll be happy to provide you some support via our help center (


certain fungal October 6, 2014 at 2:41 pm

Now I’m like, well duh! Truly thankful for your help.


sarah December 9, 2011 at 2:25 am

Hi thanks for your written
I have problem with running the script in command line. because it says that the line 80 (cmake -GXcode) in not found. could you please help me what i can do to make framework now?

thanks a lot


Robin Summerhill December 15, 2011 at 1:21 pm

It sounds like a problem with you CMake installation. The cmake executable must be on your path for the script to work. Type ‘which cmake’ in Terminal to find where cmake has been installed and then type ‘cmake –version’ to see if it is on your path and to see which version is installed.

Don’t forget that you can always use the pre-built OpenCV framework provided with the example. You only need to rebuild using the script if you have a specific need to.


Gustavo December 15, 2011 at 9:38 am

It is giving me problems with the library highgui on the revision 7054.


The following build commands failed:
CompileC /Users/opencv/trunk/tmp/modules/highgui/ /Users/opencv/trunk/opencv/modules/highgui/src/ normal i386 objective-c++
(1 failure)



Robin Summerhill December 15, 2011 at 1:51 pm

Hi Gustavo,

I’ve just tried building 7054 and am getting a different set of errors to you. The bleeding-edge trunk is not always stable and some check-ins may break the build on certain platforms. Unless you have a specific need to use the very latest OpenCV source from trunk it is best to use the pre-built framework included with the example project for this article. I periodically rebuild the framework and test it on a range of iOS devices so you can be sure that the pre-built framework will work and is fairly up-to-date.



Gustavo December 16, 2011 at 5:16 am

Hi Robin,
Thanks for the answer, I don´t need the last version but I want to build the whole project because I want to try with some compiler options, to see if the framework improve the performance, because my application is slow and I need to increase the FPS.
The parameters wich I want to compile the libraries are thease:

On the script is only used “-O3″.
Also now, I have the same problem with the highgui in the revision 7017, besides it is not giving problems when I try to compile the libraries directly in XCode, I don´t know why.


Gustavo December 20, 2011 at 5:19 am

Solved, I just need to erase some code from the source code.
But It’s not worth it to use the compile parameters the application is slower than the original compilation.

Good Luck


Ben December 20, 2011 at 10:43 am

Hi Robin,
i got a conflict with the iOS Mapkit framework:
/Frameworks/MapKit.framework/Headers/MKGeometry.h:135: error: ‘isinf’ was not declared in this scope
If i delete the reference to the Mapkit framework, it’s working… any ideas? what can I do?
Thanks, Ben


Robin Summerhill December 20, 2011 at 6:17 pm

This appears to be a known problem when using MapKit in an Objective-C++ project. Note that it is nothing to do with OpenCV.

isinf is declared as a macro in math.h but in an Objective-C++ project, which #includes <cmath> , isinf is #undef’d and std::isinf is declared instead as a wrapper.

A workaround is to add this line before you #import MKGeometry.h or any of the other MapKit headers:

using namespace std;


wingnet December 22, 2011 at 4:21 am

this is a great demo. thank you.
I just ported an opencv demo from windows to ios smoothly.

however, there is a minor issue that cv::polylines can’t be compiled correctly. It seems that the 5th parameter(int isClosed) is the reason. I had to use cv::line to work around. wish u could take a look at this problem.

waiting for your 3rd post about opencv on ios.


Yasons October 1, 2014 at 10:20 pm

Man made fiber scarves and also tsrthis undoubtedly are a basic style design. For guys, cotton connections with an elegant clothing tend to be more luxurious and it can also put in a casquette for an additional great feel. This season cotton scarves for your man gender associated dressy hats would be the development. Intentionally manufactured to balance with men’s accessories the actual pochette assortment continues to be. Go through Write-up I started to utilise products seem to assist my own girl find aside from cloning which in turn begun to take the time her not too long ago any time a few young man by your ex program taunted the woman’s. He / she referred to as Designer in addition to Michele, attire twins! The actual proposition created a horrible effect that the Amber is so anxious to visit college or university in their own casual closet. Just what exactly perform can be all of us generated her clothing obtain a 1 of your variety and trendy look. I’m a novice seamstress but I test my personal best in fitting. In case your girl loves blings you possibly can make hard work to match many factors like treasure iron-ons and also material lace about the group department retailer. These kinds of smaller accessories adjust very very well to dense material just like denims as well as trousers. Furnished border along with wallets can also be very amazing and also cute that produced my own girl closet the particular jealousy involving the woman’s buddies.VA:F [1.9.13_1145](from 0 votes)


about state October 6, 2014 at 2:48 pm

Your post has moved the debate forward. Thanks for sharing!


online pharmecy for levitra November 17, 2014 at 7:18 pm

I might be beating a dead horse, but thank you for posting this!


Phairut February 18, 2015 at 1:39 pm

has presented at the SIGGRAPH 2009, a new telhoocngy called OptiX. OptiX is a real time and programmable ray tracer optimized for GPUs. Now the first demos based on


gis December 29, 2011 at 3:36 am

Hi. I followed your instructions. I am using opencv for descriptor extraction and homography. Everything works fine on simulator, but on device it has this error:
Ld /Users/attila/Library/Developer/Xcode/DerivedData/PushPop-elmkmflbmdvkqvaeocterigucivq/Build/Products/Debug-iphoneos/ normal armv7
cd /Users/attila/GAOYAN/PushPop
setenv PATH “/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin”
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/g++-4.2 -arch armv7 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk -L/Users/attila/Library/Developer/Xcode/DerivedData/PushPop-elmkmflbmdvkqvaeocterigucivq/Build/Products/Debug-iphoneos -F/Users/attila/Library/Developer/Xcode/DerivedData/PushPop-elmkmflbmdvkqvaeocterigucivq/Build/Products/Debug-iphoneos -F/Users/attila/GAOYAN/PushPop/../../Downloads/aptogo-OpenCVForiPhone-717a18c -filelist /Users/attila/Library/Developer/Xcode/DerivedData/PushPop-elmkmflbmdvkqvaeocterigucivq/Build/Intermediates/ -dead_strip -miphoneos-version-min=4.3 -lz -framework ImageIO -framework AVFoundation -framework OpenCV -framework QuartzCore -framework Accelerate -framework MobileCoreServices -framework UIKit -framework Foundation -framework CoreGraphics -o /Users/attila/Library/Developer/Xcode/DerivedData/PushPop-elmkmflbmdvkqvaeocterigucivq/Build/Products/Debug-iphoneos/

Undefined symbols for architecture armv7:
“___divmodsi4″, referenced from:
void cv::pyrDown_<cv::FixPtCast, cv::NoVec >(cv::Mat const&, cv::Mat&)in OpenCV(pyramids.o)
void cv::pyrDown_<cv::FixPtCast, cv::NoVec >(cv::Mat const&, cv::Mat&)in OpenCV(pyramids.o)
void cv::pyrDown_<cv::FixPtCast, cv::NoVec >(cv::Mat const&, cv::Mat&)in OpenCV(pyramids.o)
void cv::pyrDown_<cv::FltCast, cv::NoVec >(cv::Mat const&, cv::Mat&)in OpenCV(pyramids.o)
void cv::pyrDown_<cv::FltCast, cv::NoVec >(cv::Mat const&, cv::Mat&)in OpenCV(pyramids.o)
ld: symbol(s) not found for architecture armv7
collect2: ld returned 1 exit status

Do you have any advice? Thanks a lot!!


gis December 29, 2011 at 4:11 am

I traced that it is caused by this line:

cvPyrDown(iplImage, small_image, CV_GAUSSIAN_5x5);

I replaced it with cvResize to solve the link error problem. So it must be some issue with pyramids.o on device.



Ivan January 14, 2012 at 3:53 pm

I have the problem with opencv
i did everything mentioned above, however, every time i try to include some header file (eg. #include ) i receive “no such file or directory” error. Can anyone help me with thia please?


gary January 31, 2012 at 11:28 pm

@gis: i had the same problem – make sure you have added all the required ios frameworks (libz, imageIO, etc) after i added those, the build errors went away! thanks so much for putting this together, robin!


Hari February 3, 2012 at 6:31 am

I followed all your steps and it MOSTLY works fine, but there is a problem! Now I am able to use mat objects in my ‘.mm’ files but when I declare it in a header file like this…

@interface TestViewController : UIViewController
cv::Mat myMat;

I get a compiler error: ‘Type name requires a specifier or qualifier’

However the same error does not come in your openCVClient where you go
cv::Mat _lastFrame;

Why does this happen?


Robin Summerhill February 3, 2012 at 7:11 am

If you use OpenCV types in a header file then you need to make sure that every source file that includes that header (directly or indirectly) is a ‘mm’ file. If you look back at the compiler messages output during the build you will see which compilation unit triggered the error you are seeing.


hari February 5, 2012 at 11:28 pm

Wow! I changed my app delegate to .mm and it worked. It’s such a sucky issue, would’ve never known if u hadn’t told. Thanks a lot!


allan February 23, 2012 at 5:16 pm

I have to write a comment to thank you for that post!

That will help me a LOT to start using OpenCV on IOS. Thank you very much! The sample project is very well organized and the post is very well written. Thanks a lot from Brazil!


Lukas February 24, 2012 at 12:08 pm

Hi, somebody how saved image with cv:imwrite() in OpenCVClientViewController? I have image totaly rabish.

Is it my bad or is it some serious problem?


Brian February 28, 2012 at 8:41 pm

Badass! This rocks, I have one question, how does OpenCV from your framework use the AVFoundation & Core Video and the other apple frameworks when you open the video capture? Did you create your own subclass of VideoCapture or something and where can I see this code, just curious. Thanks!


Robin Summerhill February 29, 2012 at 4:50 am

Later builds of OpenCV include support for video capture using AVFoundation. You can look at the OpenCV source to see how it is done. Take a look at the next article in the series to see a more flexible way of doing it by using AVFoundation directly.


Apurva March 3, 2012 at 11:33 pm

Fantastic job Robin! Thanks for sharing.


sam March 8, 2012 at 9:45 pm

thanks very much. What’s the best build option when Compile it ?


minghong.long March 11, 2012 at 3:02 am

I try to use some function about opencv
such like this cvLine(tempMat, cvPoint(10, 130), cvPoint(300, 130), cvScalar(255, 255, 255, 0));
but I got an error
“No matching function for call to cvLine”
why is that happen?
I have cpoy the frameWork into my project.
Did I miss something ?


Fraser Hardy March 14, 2012 at 10:43 am

The the first argument requires a pointer to CvArr.

If you CMD click on the offending function this is shown here:
cvLine( CvArr* img, CvPoint pt1, CvPoint pt2,
CvScalar color, int thickness CV_DEFAULT(1),
int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0) );

So your code should read:
cvLine(&tempMat, cvPoint(10, 130), cvPoint(300, 130), cvScalar(255, 255, 255, 0));

Hope that helps,



longminghong March 30, 2012 at 12:42 pm

Thank you !!
It’s work well !
I haven’t use C For a Long time !!
Thank you again


minghong.long March 11, 2012 at 3:04 am

And I write it in your demo
God !
I have no idea How to fix it…..


Suhail October 2, 2014 at 5:12 pm

Hi jack!Looks like the command is not cotlmepe WordPress automatically hidden part of the command because I used . Here is the cotlmepe command, you have to substitute my_example with output filename and my_example.cpp with example source filenameg++ -o my_example my_example.cpp -lopencv_core -lopencv_imgproc -lopencv_calib3d -lopencv_video -lopencv_features2d -lopencv_ml -lopencv_highgui -lopencv_objdetect -lopencv_contrib -lopencv_legacyHope this helps!L.


Jasmine February 18, 2015 at 1:45 pm

NVIDIA has updated its ray tranicg engine called OptiX. OptiX is a real time and programmable ray tracer optimized for GPUs. More information about OptiX can be found HERE.


Fraser Hardy March 14, 2012 at 10:39 am


I have a problem compiling when using certain functions in the openCV library.

Please see my question on stack overflow:

Any help would be greatly appreciated.



Fenton Stone March 15, 2012 at 3:42 am

Hi Robin,

I invoke the method cvCreateFGDStatModel in my project, it works fine on simulator, but crash on the devices, iPhone3GS and iPad2. However, if invoke cvCreateGaussianBGModel instead, it works fine on both simulator and devices , but it comes out not what i want.

Any help is appreciated.


Fraser Hardy March 15, 2012 at 6:20 am

I found a solution to my problem…. Someone has fixed the issue in this fork of the aptogo code:


Robin Summerhill March 15, 2012 at 6:39 am

Hi Fraser,

This fix has now been merged into the aptogo GitHub repository.


mark March 17, 2012 at 1:02 am

tried the sample code, it compiles ok & runs on the simulator. when i try to run it on my device, i get this error:

error: failed to launch ‘/Users/mark/Library/Developer/Xcode/DerivedData/OpenCVClient-gjpbrvzbxqrhugaqfmixoikidouk/Build/Products/Debug-iphoneos/’ — No such file or directory (/Users/mark/Library/Developer/Xcode/DerivedData/OpenCVClient-gjpbrvzbxqrhugaqfmixoikidouk/Build/Products/Debug-iphoneos/

why is it looking for OpenCVClient? why doesn’t it run the .app file?

i’m using Xcode 4.3.1 and SDK 5.1


caleb September 13, 2012 at 5:18 pm

For me, the trouble was with the file OpenCVClient-Info.plist. If you look in there, you’ll find that the Icon File setting is blank. Deleting that line allows you to run the app from Xcode on the device. (If you don’t delete that line, you should be able to launch the app directly on the device, but not from Xcode.)


Chris Jukes March 28, 2012 at 12:08 pm

Hi Robin, I’ve been using the OpenCV frameworks but need some guidance, have you done anything with Eigenfaces for recognition on iOS ?

I’m trying to do face recognition but struggling with the PCA bit and especially projecting my sample vectors and then matching to the training set to match the person.

any help appreciated.


longminghong March 30, 2012 at 12:38 pm

Thank you !!
It’s work well !
I haven’t use C For a Long time !!
Thank you again


Andrew April 2, 2012 at 3:49 pm

Wouldn’t dynamic framework get the app rejected from iOS AppStore?


Robin Summerhill April 2, 2012 at 5:47 pm

Hi Andrew,

It’s not a dynamic framework. It’s a static library wrapped up as a framework to make it easy to add to your Xcode project. iOS has no provision for custom dynamic frameworks so you couldn’t use one even if you wanted to.


Jason April 9, 2012 at 7:20 am

Thanks a lot for the tutorial! The example project works great.

However, I have created my own project and copied the framework for opencv. When I type cv:: I don’t get the list of functions and such for cv as I can in your project. This only happens when attempting in a .h file but works fine in a .mm file. In the example project this works in both files. I believe I am missing something very obvious but really can’t see what that is. Any help is appreciated. Thanks!


Jason April 9, 2012 at 7:39 am

I was able to solve this by changing the .h to .hpp


Joshua Noble April 25, 2012 at 12:13 am

When I try to run this script, I get an error:

Build settings from command line:
SDKROOT = iphonesimulator5.1

xcodebuild: error: Unable to read project ‘OpenCV.xcode’.
Reason: Project file ‘OpenCV’ was written by an unsupported Xcode version (39)

Curious if anyone else has seen it?


Tiago Reis May 6, 2012 at 1:23 pm


I having the same problem. Did you managed to solve it?



Tiago Reis May 6, 2012 at 1:54 pm


a bit after asking if you had solved the problem, I managed to solve it myself.

For me the problem was the version of cmake that I had installed, I had to update it to the latest version (2.8.8)


BMeyer May 11, 2012 at 5:34 am

HI, I have the same problem, but cmake has version 2.8.8. Anybody else who gets this error and/or has solved it?


Silver_205 June 3, 2012 at 5:37 pm

I’m dying to know how you overcame the following exception in image transformations

Cast of objective-c pointer type ‘NSData *’ to C pointer type ‘CFDataRef’ (aka ‘const_CFData *’) requires a bridged cast.

during this line:
CGDataProviderRef provider = CGDataProviderCreateWithCFData((CFDataRef)data);

without using the “__bridge” identifier.
in your project it works fine, but when i have created numerous projects and I just can’t override it.. I’m using LLVM GCC 4.2.


Brent T Nashville July 6, 2012 at 12:32 pm

Excellent tutorial!
I am fairly experienced on opencv & surf, however, most of that effort has been in the EMGU VB wrapper. So my Objective C, C or CPP is all new to me. Everything has gone well until I tried to add my firs “find contours” call and now find myself with the imfamous “no matching function”. I’ve tried a host of things including both CVfindcontours and CV::FindContours call attempts but end up at the same place. I’m sure there is something obvious to most but this one seems to have me stumped. Any pointer in a direction would be most appreciated.
Regards, and thanks again for a terrific tutorial.


Seungoh Ryu February 10, 2013 at 10:33 pm

I am trying to make cvFindContours work on iOS,
and managed to work in the simulator, but the same code running on the device (iPad) does not work…
(i,e, fails to find any contours)..
Did you make any progress since your comment here?


Matt Eaton July 29, 2012 at 4:16 pm

Thanks for the great article and the framework. I pretty new to IOS development and am looking at using opencv. When I look at the OpenCV.framework directory it’s around 45 MB. Is this what gets installed onto the device as part of the app? That seems very large.



Arvind December 28, 2012 at 4:32 am

Hi Matt, did you find the answer to your question? I also want to know. Thanks


Fuli August 8, 2012 at 4:41 am

Hi, I used the framework in the sample project, it works very well in ipod touch 5.01, but it is very slow in iphone 4 5.01, it took about 6 times time. any idea?


Fuli August 8, 2012 at 5:40 am

I think I have found the reason, the picture taken by iphone is much larger than taken on ipod touch.


bill September 21, 2012 at 2:11 pm

Thanks for the great work on this framework doctor. Any chance of getting a new one built including an armv7s slice for iphone 5?


hana October 21, 2012 at 11:19 am

i cant checkout from the terminal it says
svn: OPTIONS of ‘’: authorization failed: Could not authenticate to server: rejected Basic challenge (

is there alternate link ?


Jian December 13, 2012 at 10:23 pm

Hi Robin.

I have some problem.. you work looks awesome.
I imported your openCV framework to my project. But I want use stitching function in the openCV framework.
If I try to import stitching.hpp, then I have bugs. I don’t know well about openCV. I’m new.
Can you lead me to achieve my purpose.
I really hope your help.



Arvind December 31, 2012 at 2:43 am

Hi Robin, very useful and helped us a lot. Could you say whether IMRead and IMWrite work with iOS, and if yes, how? I find conflicting info on the Internet. Someone in the thread above has asked this but didn’t get an answer. Thanks again.

Reply January 20, 2013 at 1:24 pm

Just where did you obtain the recommendations
to create ““Computer vision with iOS Part 1: Building an OpenCV framework — Aptogo”?
Thanks for the post -Dolores


Waleed Ahmed March 31, 2013 at 3:32 am

Thank for your tutorial its really help full i want to detct the line and then extract it i have used your tutorial to detect the line now i want to extract that line can you please help me on that ?


Leigh Chen June 9, 2013 at 2:32 am

I ran into the below issue while compiling iOS – Video Processing application ( ). I have added all frameworks mentioned in the example although running into the linking issue. I have no clue what might be the cause of failure ?

Reply June 30, 2013 at 4:11 am

I do not even know the way I finished up here, but I believed this submit used to be great.
I don’t realize who you’re but certainly you are going to a well-known blogger should you are not already.


Minecraft Free Download July 4, 2013 at 2:18 pm

I was curious if you ever considered changing the structure of your blog?
Its very well written; I love what youve got to say.
But maybe you could a little more in the way of content so people could connect with it better.
Youve got an awful lot of text for only having 1 or 2 images.
Maybe you could space it out better?


Tobias July 6, 2013 at 8:51 am

Hi there just wanted to give you a quick heads up. The words in your content seem to be running off the screen in
Internet explorer. I’m not sure if this is a format issue or something to do with browser compatibility but I figured I’d
post to let you know. The design and style look great though!
Hope you get the issue resolved soon. Thanks


Kenneth Lewis July 10, 2013 at 7:56 am

I am having a problem doing the following and I have registered my account with but still not working.
svn co .
I entered my username and pwd for but still it’s not pulling down the source for the opencv.
A little help please.
I checked the svn version by using which svn and svn –version
snv, version 1.7.10 (r1485443)
compiled Jun 27 2013



совкомбанк кредиты July 11, 2013 at 6:19 pm

I do not create a leave a response, however I browsed a few
responses here Computer vision with iOS Part 1:
Building an OpenCV framework — Aptogo.

I do have some questions for you if it’s okay. Could it be just me or do a few of the comments come across as if they are left by brain dead folks? :-P And, if you are writing at other places, I’d like to keep up with you.
Could you post a list of the complete urls of your social community sites like your twitter
feed, Facebook page or linkedin profile?


10 Methods For Reservation Hotels July 17, 2013 at 8:33 pm

These are in fact great ideas in on the topic of blogging. You have touched some fastidious things here.
Any way keep up wrinting.

Reply July 23, 2013 at 6:11 pm

It’s an awesome paragraph for all the internet people; they will obtain benefit from it I am sure.


download minecraft free July 24, 2013 at 8:43 pm

I’m really enjoying the theme/design of your site. Do you ever run into any web browser compatibility issues? A couple of my blog readers have complained about my site not operating correctly in Explorer but looks great in Safari. Do you have any advice to help fix this issue?


Anonymous July 28, 2013 at 7:25 pm

Howdy! I simply want to give a huge thumbs up for the great
data you


Lidia October 2, 2014 at 11:44 am

Hats off to whevoer wrote this up and posted it.


Fatima February 19, 2015 at 12:04 pm

Ben, What do you have for light setup? Is any diffuser being used? I’m have a hard time geinttg my table kick started. I have a similar setup to yours. However I am geinttg large hot spots from my lights. Thanks


Michael Lev August 22, 2013 at 4:14 pm

I cloned today from gitHub, but compile failed –
in file boost/config.hpp, paragraph:
// if we have a compiler config, include it now:
it says file ‘boost/config/compiler/clang.hpp’ does not exist, but it exists…

I’ll appreciate your help.


PhilipSn March 24, 2014 at 5:20 am

[url=][b]nike australia[/b][/url]He must be the case sunny. He is the fact probably the most picking on this page i always think. And that i am some form of for example your readers thanks enchanting your sharing everything.[url=][b]nike australia[/b][/url]What a number of us want are intelligent, creative, smart, knowledgeable and progressive starting a new college Having attending college who are one of the more studious is usually that undesirable as they cannot become familiar with the demands like our cutting-edge economy and society.[url=][b]nike shoes[/b][/url]The maize plot bordering our backyard urgently needs weeding and detaching the tillers back and forth from going to be the stems such as the crops. As a multi function are considered like too much of the rainfall,busy vines are flourishing and twining fight going to be the corn stems tightly. But the planter failed to educate yourself regarding show his nose here despite going to be the problem[url=][b]nike free run womens[/b][/url]


Bryan Mitchell March 29, 2014 at 4:20 pm

Anyone have an update version that works with XCode 5?

I am getting “unsupported compiler” errors, and the code won’t compile after changing the compile to Apple LLVM 5.


dfqgfcdq87 May 17, 2014 at 5:17 pm

[url=][b]cheap michael kors outlet[/b][/url][url=][b]cheap michael kors purses[/b][/url][url=][b]cheap michael kors outlet[/b][/url]Here would be the fact an all in one list concerning going to be the Russian officials and companies targeted:OLEG BELAVANTSEVBelavantsev, 64, was an all in one political unknown so much that Putin appointed kale to ensure they are his envoy for more information about Crimea last month,throughout the going to be the same day that Russia formally annexed the Ukrainian peninsula[url=][b]michael kors handbags cheap[/b][/url][url=][b]michael kors outlet[/b][/url][url=][b]michael kors outlet store[/b][/url],[url=][b]michael kors factory outlet[/b][/url][url=][b]michael kors factory outlet[/b][/url][url=][b]cheap michael kors purses[/b][/url]” DIA analysts,but bear in mind said about whether or not al-Qaida engineers were able to educate yourself regarding”overcome many of these substantial brand enjoy challenges,a number of us believe one of these a gps device probably should be highly rated disruptive too US operations all over the Afghanistan and Pakistan[/b][/url][url=][b]michael kors factory outlet[/b][/url][url=][b]michael kors outlet online[/b][/url], [url=][b]michael kors outlet online[/b][/url][url=][b]michael kors outlet store[/b][/url][url=][b]michael kors outlet[/b][/url]Politicians which of you had defended Bundy immediately issued statements condemning going to be the remarks[url=][b]michael kors outlet[/b][/url][url=][b]michael kors handbags outlet[/b][/url][url=][b]cheap michael kors outlet[/b][/url], [url=][b]michael kors outlet online[/b][/url][url=][b]cheap michael kors outlet[/b][/url][url=][b]cheap michael kors purses[/b][/url]NEW DELHI: The US law enforcement agencies are increasingly networking allowing an individual communities for more information about identify and tackle religious radicalization as part of your country side,for example as community policing throughout the India remains largely limited for additional details on checking local and neighbourhood crimes[url=][b]cheap michael kors[/b][/url][url=][b]cheap michael kors outlet[/b][/url][url=][b]michael kors outlet online[/b][/url]


Edwin October 2, 2014 at 7:04 pm

g++ -o -lopencv_core -lopencv_imgproc -lopencv_calib3d -lopencv_video -lopencv_features2d -lopencv_ml -lopencv_highgui -lopencv_objdetect -lopencv_contrib -lopencv_legacy/usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../x86_64-linux-gnu/crt1.o: In function `_start’:(.text+0 20): uneeifndd reference to `main’collect2: ld returned 1 exit statuspls tell me what to do?


closeout custom youth soccer jerseys June 29, 2014 at 5:19 am

closeout custom youth soccer jerseys top world world cup soccer jerseys 2014


ajax soccer jersey June 29, 2014 at 5:19 am

personalized notre dame youth football jerseys personalized notre dame youth football jerseys


Leave a Comment

{ 9 trackbacks }

Previous post:

Next post: