2014-11-27 20:39:05 +08:00
|
|
|
OpenCV iOS Hello {#tutorial_hello}
|
|
|
|
================
|
|
|
|
|
|
|
|
Goal
|
|
|
|
----
|
|
|
|
|
|
|
|
In this tutorial we will learn how to:
|
|
|
|
|
|
|
|
- Link OpenCV framework with Xcode
|
|
|
|
- How to write simple Hello World application using OpenCV and Xcode.
|
|
|
|
|
2014-11-28 21:21:28 +08:00
|
|
|
Linking OpenCV iOS
|
|
|
|
------------------
|
2014-11-27 20:39:05 +08:00
|
|
|
|
|
|
|
Follow this step by step guide to link OpenCV to iOS.
|
|
|
|
|
2014-11-28 21:21:28 +08:00
|
|
|
-# Create a new XCode project.
|
|
|
|
-# Now we need to link *opencv2.framework* with Xcode. Select the project Navigator in the left
|
2014-11-27 20:39:05 +08:00
|
|
|
hand panel and click on project name.
|
2014-11-28 21:21:28 +08:00
|
|
|
-# Under the TARGETS click on Build Phases. Expand Link Binary With Libraries option.
|
|
|
|
-# Click on Add others and go to directory where *opencv2.framework* is located and click open
|
|
|
|
-# Now you can start writing your application.
|
2014-11-27 20:39:05 +08:00
|
|
|
|
2014-11-28 21:21:28 +08:00
|
|
|
![](images/linking_opencv_ios.png)
|
2014-11-27 20:39:05 +08:00
|
|
|
|
2014-11-28 21:21:28 +08:00
|
|
|
Hello OpenCV iOS Application
|
|
|
|
----------------------------
|
2014-11-27 20:39:05 +08:00
|
|
|
|
|
|
|
Now we will learn how to write a simple Hello World Application in Xcode using OpenCV.
|
|
|
|
|
|
|
|
- Link your project with OpenCV as shown in previous section.
|
|
|
|
- Open the file named *NameOfProject-Prefix.pch* ( replace NameOfProject with name of your
|
|
|
|
project) and add the following lines of code.
|
2014-11-28 21:21:28 +08:00
|
|
|
@code{.m}
|
|
|
|
#ifdef __cplusplus
|
|
|
|
#import <opencv2/opencv.hpp>
|
|
|
|
#endif
|
|
|
|
@endcode
|
|
|
|
![](images/header_directive.png)
|
2014-11-27 20:39:05 +08:00
|
|
|
|
|
|
|
- Add the following lines of code to viewDidLoad method in ViewController.m.
|
2014-11-28 21:21:28 +08:00
|
|
|
@code{.m}
|
|
|
|
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Hello!" message:@"Welcome to OpenCV" delegate:self cancelButtonTitle:@"Continue" otherButtonTitles:nil];
|
|
|
|
[alert show];
|
|
|
|
@endcode
|
|
|
|
![](images/view_did_load.png)
|
2014-11-27 20:39:05 +08:00
|
|
|
|
|
|
|
- You are good to run the project.
|
|
|
|
|
2014-11-28 21:21:28 +08:00
|
|
|
Output
|
|
|
|
------
|
2014-11-27 20:39:05 +08:00
|
|
|
|
2014-11-28 21:21:28 +08:00
|
|
|
![](images/output.png)
|
2015-02-20 21:28:03 +08:00
|
|
|
|
|
|
|
Changes for XCode5+ and iOS8+
|
|
|
|
-----------------------------
|
|
|
|
|
|
|
|
With the newer XCode and iOS versions you need to watch out for some specific details
|
|
|
|
|
|
|
|
- The *.m file in your project should be renamed to *.mm.
|
|
|
|
- You have to manually include AssetsLibrary.framework into your project, which is not done anymore by default.
|