OPEN CV Tutorial
OPEN CV Tutorial
CVPR 2012
Its fun
Its trendy
It can make you rich
Its impressive way to
show some technology
iOS Anatomy
Apps
Cocoa Touch (UIKit etc.)
Media (CoreImage, CoreGraphics, OpenGL ES, AVFoundation)
Core Services (Databases, iCloud, GDC, )
Core OS (Unix, POSIX, )
iOS Development
+
iOS Simulator:
iOS Device:
+ $99
iOS Simulator
iOS Device
Cost
Free*
Prerequisities
+ iOS-5 capable
device
Target CPU
Speed
fast
slower
RAM
lots of
limited
OpenGL
Camera
Accelerometer
Debugging, Logging
Performance
evaluation
Getting started
Objective C = Smalltalk + C
o Apples take: Objective C++ (can use classes, STL etc.)
Since iOS 5 includes ARC (automatic reference
counting)
Dynamic methods are called by name, not by
indices in vtable
Has very rich class library with dedicated root
object NSObject
.h extension for headers, .m & .mm extension for
implementation
Its a superset of C
#import == #include with automatic guards.
[recipient messageWithArg1:A andArg2:B];
Since OSX 10.7 & iOS 5 memory is automatically managed
Display/Hide Areas
Frameworks
used
Navigator
Area
Debug Area
Object
Library
element
For each view component (image view, button,
slider ) we add corresponding IBOutletmarked property in the controller class
For each action we add IBAction-marked
method in the controller
Finally, run it
OpenCV+iOS Anatomy
Apps
Cocoa Touch (UIKit etc.)
Media (CoreImage, CoreGraphics, OpenGL ES, AVFoundation)
Core Services (Databases, iCloud, GDC, )
Core OS (Unix, POSIX, )
2.
3.
4.
!
if( image != nil ) {!
cv::Mat m, gray;!
UIImageToMat(image, m);!
cv::cvtColor(m, gray, CV_RGBA2GRAY);!
cv::GaussianBlur(gray, gray, cv::Size(5, 5), 1.2, 1.2);!
cv::Canny(gray, gray, 0, 50);!
m = cv::Scalar::all(255);!
m.setTo(cv::Scalar(0, 128, 255, 255), gray);!
imageView.contentMode = UIViewContentModeScaleAspectFit;!
imageView.image = MatToUIImage(m);!
}!
}!
- (IBAction)loadButtonPressed:(id)sender {!
UIImagePickerController* picker = [[UIImagePickerController alloc] init];!
picker.delegate = self;!
if (![UIImagePickerController isSourceTypeAvailable:!
UIImagePickerControllerSourceTypePhotoLibrary])!
return;!
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;!
[self presentModalViewController:picker animated:YES];!
}!
Tip: If you run it for the first time, the photo library will be empty. You can
drag image to the simulator, which will display it in Safari. Press mouse/
trackpad for 1-2sec until the menu arrives. Save the image to library.
#import can be used with your own files and save you from writing extra
#ifndef #define #endif.
Protocols and delegates are not exclusive things in standard Cocoa
components; well-designed components may introduce custom protocols
and use delegates. See VideoCameraController.h/.m for details.
ARC works with pointers to your own classes as well (e.g. with
VideoCamera*)
Tip: To make a screenshot of an app, press home button (at the bottom
center) and without releasing it press exit button (right side of the top edg)
for a short time.
Look at FaceDetectSimple app on the USB key and try to add the same
functionality to our HelloWorld sample.
Hints:
Use Accelerate.framework
Use OpenGL and CoreGraphics for rendering,
CoreImage for image processing
Resources
http://code.opencv.org/svn/gsoc2012/ios/trunk
- our GSoC iOS project repository where more
and more interesting stuff is being added