mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
Doxygen tutorials: cpp done
This commit is contained in:
@@ -9,46 +9,45 @@ In this tutorial we will learn how to:
|
||||
- Link OpenCV framework with Xcode
|
||||
- How to write simple Hello World application using OpenCV and Xcode.
|
||||
|
||||
*Linking OpenCV iOS*
|
||||
--------------------
|
||||
Linking OpenCV iOS
|
||||
------------------
|
||||
|
||||
Follow this step by step guide to link OpenCV to iOS.
|
||||
|
||||
1. Create a new XCode project.
|
||||
2. Now we need to link *opencv2.framework* with Xcode. Select the project Navigator in the left
|
||||
-# Create a new XCode project.
|
||||
-# Now we need to link *opencv2.framework* with Xcode. Select the project Navigator in the left
|
||||
hand panel and click on project name.
|
||||
3. Under the TARGETS click on Build Phases. Expand Link Binary With Libraries option.
|
||||
4. Click on Add others and go to directory where *opencv2.framework* is located and click open
|
||||
5. Now you can start writing your application.
|
||||
-# 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.
|
||||
|
||||

|
||||

|
||||
|
||||
*Hello OpenCV iOS Application*
|
||||
------------------------------
|
||||
Hello OpenCV iOS Application
|
||||
----------------------------
|
||||
|
||||
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.
|
||||
@code{.cpp}
|
||||
#ifdef __cplusplus
|
||||
#import <opencv2/opencv.hpp>
|
||||
#endif
|
||||
@endcode
|
||||

|
||||
@code{.m}
|
||||
#ifdef __cplusplus
|
||||
#import <opencv2/opencv.hpp>
|
||||
#endif
|
||||
@endcode
|
||||

|
||||
|
||||
- Add the following lines of code to viewDidLoad method in ViewController.m.
|
||||
@code{.cpp}
|
||||
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Hello!" message:@"Welcome to OpenCV" delegate:self cancelButtonTitle:@"Continue" otherButtonTitles:nil];
|
||||
[alert show];
|
||||
@endcode
|
||||

|
||||
@code{.m}
|
||||
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Hello!" message:@"Welcome to OpenCV" delegate:self cancelButtonTitle:@"Continue" otherButtonTitles:nil];
|
||||
[alert show];
|
||||
@endcode
|
||||

|
||||
|
||||
- You are good to run the project.
|
||||
|
||||
*Output*
|
||||
--------
|
||||
|
||||

|
||||
Output
|
||||
------
|
||||
|
||||

|
||||
|
||||
@@ -6,14 +6,14 @@ Goal
|
||||
|
||||
In this tutorial we will learn how to do basic image processing using OpenCV in iOS.
|
||||
|
||||
*Introduction*
|
||||
--------------
|
||||
Introduction
|
||||
------------
|
||||
|
||||
In *OpenCV* all the image processing operations are usually carried out on the *Mat* structure. In
|
||||
iOS however, to render an image on screen it have to be an instance of the *UIImage* class. To
|
||||
convert an *OpenCV Mat* to an *UIImage* we use the *Core Graphics* framework available in iOS. Below
|
||||
is the code needed to covert back and forth between Mat's and UIImage's.
|
||||
@code{.cpp}
|
||||
@code{.m}
|
||||
- (cv::Mat)cvMatFromUIImage:(UIImage *)image
|
||||
{
|
||||
CGColorSpaceRef colorSpace = CGImageGetColorSpace(image.CGImage);
|
||||
@@ -37,7 +37,7 @@ is the code needed to covert back and forth between Mat's and UIImage's.
|
||||
return cvMat;
|
||||
}
|
||||
@endcode
|
||||
@code{.cpp}
|
||||
@code{.m}
|
||||
- (cv::Mat)cvMatGrayFromUIImage:(UIImage *)image
|
||||
{
|
||||
CGColorSpaceRef colorSpace = CGImageGetColorSpace(image.CGImage);
|
||||
@@ -63,12 +63,12 @@ is the code needed to covert back and forth between Mat's and UIImage's.
|
||||
@endcode
|
||||
After the processing we need to convert it back to UIImage. The code below can handle both
|
||||
gray-scale and color image conversions (determined by the number of channels in the *if* statement).
|
||||
@code{.cpp}
|
||||
@code{.m}
|
||||
cv::Mat greyMat;
|
||||
cv::cvtColor(inputMat, greyMat, COLOR_BGR2GRAY);
|
||||
@endcode
|
||||
After the processing we need to convert it back to UIImage.
|
||||
@code{.cpp}
|
||||
@code{.m}
|
||||
-(UIImage *)UIImageFromCVMat:(cv::Mat)cvMat
|
||||
{
|
||||
NSData *data = [NSData dataWithBytes:cvMat.data length:cvMat.elemSize()*cvMat.total()];
|
||||
@@ -106,10 +106,11 @@ After the processing we need to convert it back to UIImage.
|
||||
return finalImage;
|
||||
}
|
||||
@endcode
|
||||
*Output*
|
||||
|
||||
Output
|
||||
--------
|
||||
|
||||

|
||||

|
||||
|
||||
Check out an instance of running code with more Image Effects on
|
||||
[YouTube](http://www.youtube.com/watch?v=Ko3K_xdhJ1I) .
|
||||
@@ -119,4 +120,3 @@ Check out an instance of running code with more Image Effects on
|
||||
<iframe width="560" height="350" src="http://www.youtube.com/embed/Ko3K_xdhJ1I" frameborder="0" allowfullscreen></iframe>
|
||||
</div>
|
||||
\endhtmlonly
|
||||
|
||||
|
||||
@@ -14,11 +14,11 @@ Including OpenCV library in your iOS project
|
||||
|
||||
The OpenCV library comes as a so-called framework, which you can directly drag-and-drop into your
|
||||
XCode project. Download the latest binary from
|
||||
\<<http://sourceforge.net/projects/opencvlibrary/files/opencv-ios/>\>. Alternatively follow this
|
||||
<http://sourceforge.net/projects/opencvlibrary/files/opencv-ios/>. Alternatively follow this
|
||||
guide @ref tutorial_ios_install to compile the framework manually. Once you have the framework, just
|
||||
drag-and-drop into XCode:
|
||||
|
||||

|
||||

|
||||
|
||||
Also you have to locate the prefix header that is used for all header files in the project. The file
|
||||
is typically located at "ProjectName/Supporting Files/ProjectName-Prefix.pch". There, you have add
|
||||
@@ -54,7 +54,7 @@ First, we create a simple iOS project, for example Single View Application. Then
|
||||
an UIImageView and UIButton to start the camera and display the video frames. The storyboard could
|
||||
look like that:
|
||||
|
||||

|
||||

|
||||
|
||||
Make sure to add and connect the IBOutlets and IBActions to the corresponding ViewController:
|
||||
@code{.objc}
|
||||
@@ -127,7 +127,7 @@ should have at least the following frameworks in your project:
|
||||
- UIKit
|
||||
- Foundation
|
||||
|
||||

|
||||

|
||||
|
||||
#### Processing frames
|
||||
|
||||
|
||||
Reference in New Issue
Block a user