1
OpenCV iOS Hello {#tutorial_hello}
7
In this tutorial we will learn how to:
9
- Link OpenCV framework with Xcode
10
- How to write simple Hello World application using OpenCV and Xcode.
15
Follow this step by step guide to link OpenCV to iOS.
17
-# Create a new XCode project.
18
-# Now we need to link *opencv2.framework* with Xcode. Select the project Navigator in the left
19
hand panel and click on project name.
20
-# Under the TARGETS click on Build Phases. Expand Link Binary With Libraries option.
21
-# Click on Add others and go to directory where *opencv2.framework* is located and click open
22
-# Now you can start writing your application.
24
![](images/linking_opencv_ios.png)
26
Hello OpenCV iOS Application
27
----------------------------
29
Now we will learn how to write a simple Hello World Application in Xcode using OpenCV.
31
- Link your project with OpenCV as shown in previous section.
32
- Open the file named *NameOfProject-Prefix.pch* ( replace NameOfProject with name of your
33
project) and add the following lines of code.
36
#import <opencv2/opencv.hpp>
39
![](images/header_directive.png)
41
- Add the following lines of code to viewDidLoad method in ViewController.m.
43
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Hello!" message:@"Welcome to OpenCV" delegate:self cancelButtonTitle:@"Continue" otherButtonTitles:nil];
46
![](images/view_did_load.png)
48
- You are good to run the project.
53
![](images/output.png)
55
Changes for XCode5+ and iOS8+
56
-----------------------------
58
With the newer XCode and iOS versions you need to watch out for some specific details
60
- The *.m file in your project should be renamed to *.mm.
61
- You have to manually include AssetsLibrary.framework into your project, which is not done anymore by default.