├── .gitignore
├── Default-568h@2x.png
├── Default-Landscape@2x~ipad.png
├── Default-Landscape~ipad.png
├── Default-Portrait@2x~ipad.png
├── Default-Portrait~ipad.png
├── Default.png
├── Default@2x.png
├── Icon-72.png
├── Icon-72@2x.png
├── Icon-Small-50.png
├── Icon-Small-50@2x.png
├── Icon-Small.png
├── Icon-Small@2x.png
├── Icon.png
├── Icon@2x.png
├── OpenCV Tutorial.xcodeproj
├── project.pbxproj
└── project.xcworkspace
│ └── contents.xcworkspacedata
├── OpenCV Tutorial
├── AppDelegate.h
├── AppDelegate.mm
├── BaseSampleViewController.h
├── BaseSampleViewController.mm
├── BooleanTableViewCell.h
├── BooleanTableViewCell.mm
├── BooleanTableViewCell.xib
├── CameraCalibrationAlgorithm.cpp
├── CameraCalibrationAlgorithm.h
├── CameraCalibrationSample.cpp
├── CameraCalibrationSample.h
├── CartoonFilter.cpp
├── CartoonFilter.h
├── ContourDetectionSample.cpp
├── ContourDetectionSample.h
├── ContourDetectionSampleIcon.png
├── ContourDetectionSampleIcon@2x.png
├── DefaultSampleIcon.png
├── DefaultSampleIcon~ipad.png
├── DetailViewController.h
├── DetailViewController.mm
├── DoubleTableViewCell.h
├── DoubleTableViewCell.mm
├── DoubleTableViewCell.xib
├── DrawingCanvas.cpp
├── DrawingCanvas.h
├── EdgeDetectionSample.cpp
├── EdgeDetectionSample.h
├── EdgeDetectionSampleIcon.png
├── EdgeDetectionSampleIcon~ipad.png
├── EnumTableViewCell.h
├── EnumTableViewCell.mm
├── EnumTableViewCell.xib
├── FPSCalculator.h
├── FPSCalculator.mm
├── FeatureDetectionClass.cpp
├── FeatureDetectionClass.h
├── FeatureDetectionSample.cpp
├── FeatureDetectionSample.h
├── FeatureDetectionSampleIcon.png
├── FloatTableViewCell.h
├── FloatTableViewCell.mm
├── FloatTableViewCell.xib
├── Globals.cpp
├── Globals.h
├── ImageFiltersSample.cpp
├── ImageFiltersSample.h
├── ImageViewController.h
├── ImageViewController.mm
├── Int32TableViewCell.h
├── Int32TableViewCell.mm
├── Int32TableViewCell.xib
├── Mandrill512x512.png
├── MasterViewController.h
├── MasterViewController.mm
├── NSString+StdString.h
├── NSString+StdString.mm
├── ObjectTrackingClass.cpp
├── ObjectTrackingClass.h
├── ObjectTrackingSample.cpp
├── ObjectTrackingSample.h
├── ObjectTrackingSampleIcon.png
├── OpenCV Tutorial-Info.plist
├── OpenCV Tutorial-Prefix.pch
├── OptionCell.h
├── OptionCell.mm
├── OptionsTableView.h
├── OptionsTableView.mm
├── ROFSample.cpp
├── ROFSample.h
├── ROFSampleIcon.png
├── SampleBase.cpp
├── SampleBase.h
├── SampleFacade.h
├── SampleFacade.mm
├── SampleOptions.cpp
├── SampleOptions.h
├── SampleOptionsTableViewDelegate.h
├── SampleOptionsTableViewDelegate.mm
├── UIImage2OpenCV.h
├── UIImage2OpenCV.mm
├── VideoTracking.cpp
├── VideoTracking.hpp
├── VideoTrackingSampleIcon.png
├── VideoViewController.h
├── VideoViewController.mm
├── ViewController.h
├── ViewController.mm
├── cog_01.png
├── cog_01@2x.png
├── cog_02.png
├── cog_02@2x.png
├── cvneon.cpp
├── cvneon.h
├── en.lproj
│ ├── InfoPlist.strings
│ ├── MainStoryboard_iPad.storyboard
│ ├── MainStoryboard_iPhone.storyboard
│ └── switchCamera.png
├── main.m
├── main.mm
├── photos_polaroid.png
├── photos_polaroid@2x.png
├── record.png
├── record@2x.png
├── refresh.png
├── refresh@2x.png
├── refresh_straight_arrows.png
├── refresh_straight_arrows@2x.png
├── repeat.png
├── repeat@2x.png
├── switchCamera.png
├── switchCamera@2x.png
├── totalvariation.cpp
└── totalvariation.h
├── README.md
├── iTunesArtwork.png
├── iTunesArtwork@2x.png
└── opencv2.framework
├── Headers
├── Resources
├── Versions
├── A
│ ├── Headers
│ │ ├── calib3d.hpp
│ │ ├── calib3d
│ │ │ ├── calib3d.hpp
│ │ │ └── calib3d_c.h
│ │ ├── core.hpp
│ │ ├── core
│ │ │ ├── affine.hpp
│ │ │ ├── base.hpp
│ │ │ ├── bufferpool.hpp
│ │ │ ├── core.hpp
│ │ │ ├── core_c.h
│ │ │ ├── cuda.hpp
│ │ │ ├── cuda.inl.hpp
│ │ │ ├── cuda_stream_accessor.hpp
│ │ │ ├── cuda_types.hpp
│ │ │ ├── cvdef.h
│ │ │ ├── cvstd.hpp
│ │ │ ├── cvstd.inl.hpp
│ │ │ ├── directx.hpp
│ │ │ ├── eigen.hpp
│ │ │ ├── ippasync.hpp
│ │ │ ├── mat.hpp
│ │ │ ├── mat.inl.hpp
│ │ │ ├── matx.hpp
│ │ │ ├── ocl.hpp
│ │ │ ├── ocl_genbase.hpp
│ │ │ ├── opengl.hpp
│ │ │ ├── operations.hpp
│ │ │ ├── optim.hpp
│ │ │ ├── persistence.hpp
│ │ │ ├── private.cuda.hpp
│ │ │ ├── private.hpp
│ │ │ ├── ptr.inl.hpp
│ │ │ ├── traits.hpp
│ │ │ ├── types.hpp
│ │ │ ├── types_c.h
│ │ │ ├── utility.hpp
│ │ │ ├── version.hpp
│ │ │ └── wimage.hpp
│ │ ├── features2d.hpp
│ │ ├── features2d
│ │ │ └── features2d.hpp
│ │ ├── flann.hpp
│ │ ├── flann
│ │ │ ├── all_indices.h
│ │ │ ├── allocator.h
│ │ │ ├── any.h
│ │ │ ├── autotuned_index.h
│ │ │ ├── composite_index.h
│ │ │ ├── config.h
│ │ │ ├── defines.h
│ │ │ ├── dist.h
│ │ │ ├── dummy.h
│ │ │ ├── dynamic_bitset.h
│ │ │ ├── flann.hpp
│ │ │ ├── flann_base.hpp
│ │ │ ├── general.h
│ │ │ ├── ground_truth.h
│ │ │ ├── hdf5.h
│ │ │ ├── heap.h
│ │ │ ├── hierarchical_clustering_index.h
│ │ │ ├── index_testing.h
│ │ │ ├── kdtree_index.h
│ │ │ ├── kdtree_single_index.h
│ │ │ ├── kmeans_index.h
│ │ │ ├── linear_index.h
│ │ │ ├── logger.h
│ │ │ ├── lsh_index.h
│ │ │ ├── lsh_table.h
│ │ │ ├── matrix.h
│ │ │ ├── miniflann.hpp
│ │ │ ├── nn_index.h
│ │ │ ├── object_factory.h
│ │ │ ├── params.h
│ │ │ ├── random.h
│ │ │ ├── result_set.h
│ │ │ ├── sampling.h
│ │ │ ├── saving.h
│ │ │ ├── simplex_downhill.h
│ │ │ └── timer.h
│ │ ├── highgui.hpp
│ │ ├── highgui
│ │ │ ├── highgui.hpp
│ │ │ └── highgui_c.h
│ │ ├── imgcodecs.hpp
│ │ ├── imgcodecs
│ │ │ ├── imgcodecs.hpp
│ │ │ ├── imgcodecs_c.h
│ │ │ └── ios.h
│ │ ├── imgproc.hpp
│ │ ├── imgproc
│ │ │ ├── imgproc.hpp
│ │ │ ├── imgproc_c.h
│ │ │ └── types_c.h
│ │ ├── ml.hpp
│ │ ├── ml
│ │ │ └── ml.hpp
│ │ ├── objdetect.hpp
│ │ ├── objdetect
│ │ │ ├── detection_based_tracker.hpp
│ │ │ ├── objdetect.hpp
│ │ │ └── objdetect_c.h
│ │ ├── opencv.hpp
│ │ ├── opencv_modules.hpp
│ │ ├── photo.hpp
│ │ ├── photo
│ │ │ ├── cuda.hpp
│ │ │ ├── photo.hpp
│ │ │ └── photo_c.h
│ │ ├── shape.hpp
│ │ ├── shape
│ │ │ ├── emdL1.hpp
│ │ │ ├── hist_cost.hpp
│ │ │ ├── shape.hpp
│ │ │ ├── shape_distance.hpp
│ │ │ └── shape_transformer.hpp
│ │ ├── stitching.hpp
│ │ ├── stitching
│ │ │ ├── detail
│ │ │ │ ├── autocalib.hpp
│ │ │ │ ├── blenders.hpp
│ │ │ │ ├── camera.hpp
│ │ │ │ ├── exposure_compensate.hpp
│ │ │ │ ├── matchers.hpp
│ │ │ │ ├── motion_estimators.hpp
│ │ │ │ ├── seam_finders.hpp
│ │ │ │ ├── timelapsers.hpp
│ │ │ │ ├── util.hpp
│ │ │ │ ├── util_inl.hpp
│ │ │ │ ├── warpers.hpp
│ │ │ │ └── warpers_inl.hpp
│ │ │ └── warpers.hpp
│ │ ├── video.hpp
│ │ ├── video
│ │ │ ├── background_segm.hpp
│ │ │ ├── tracking.hpp
│ │ │ ├── tracking_c.h
│ │ │ └── video.hpp
│ │ ├── videoio.hpp
│ │ ├── videoio
│ │ │ ├── cap_ios.h
│ │ │ ├── videoio.hpp
│ │ │ └── videoio_c.h
│ │ ├── videostab.hpp
│ │ ├── videostab
│ │ │ ├── deblurring.hpp
│ │ │ ├── fast_marching.hpp
│ │ │ ├── fast_marching_inl.hpp
│ │ │ ├── frame_source.hpp
│ │ │ ├── global_motion.hpp
│ │ │ ├── inpainting.hpp
│ │ │ ├── log.hpp
│ │ │ ├── motion_core.hpp
│ │ │ ├── motion_stabilizing.hpp
│ │ │ ├── optical_flow.hpp
│ │ │ ├── outlier_rejection.hpp
│ │ │ ├── ring_buffer.hpp
│ │ │ ├── stabilizer.hpp
│ │ │ └── wobble_suppression.hpp
│ │ └── world.hpp
│ ├── Resources
│ │ └── Info.plist
│ └── opencv2
└── Current
└── opencv2
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by https://www.gitignore.io/api/osx,xcode,objective-c
2 |
3 | ### OSX ###
4 | .DS_Store
5 | .AppleDouble
6 | .LSOverride
7 |
8 | # Icon must end with two \r
9 | Icon
10 |
11 |
12 | # Thumbnails
13 | ._*
14 |
15 | # Files that might appear in the root of a volume
16 | .DocumentRevisions-V100
17 | .fseventsd
18 | .Spotlight-V100
19 | .TemporaryItems
20 | .Trashes
21 | .VolumeIcon.icns
22 |
23 | # Directories potentially created on remote AFP share
24 | .AppleDB
25 | .AppleDesktop
26 | Network Trash Folder
27 | Temporary Items
28 | .apdisk
29 |
30 |
31 | ### Xcode ###
32 | # Xcode
33 | #
34 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
35 |
36 | ## Build generated
37 | build/
38 | DerivedData
39 |
40 | ## Various settings
41 | *.pbxuser
42 | !default.pbxuser
43 | *.mode1v3
44 | !default.mode1v3
45 | *.mode2v3
46 | !default.mode2v3
47 | *.perspectivev3
48 | !default.perspectivev3
49 | xcuserdata
50 |
51 | ## Other
52 | *.xccheckout
53 | *.moved-aside
54 | *.xcuserstate
55 |
56 |
57 | ### Objective-C ###
58 | # Xcode
59 | #
60 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
61 |
62 | ## Build generated
63 | build/
64 | DerivedData
65 |
66 | ## Various settings
67 | *.pbxuser
68 | !default.pbxuser
69 | *.mode1v3
70 | !default.mode1v3
71 | *.mode2v3
72 | !default.mode2v3
73 | *.perspectivev3
74 | !default.perspectivev3
75 | xcuserdata
76 |
77 | ## Other
78 | *.xccheckout
79 | *.moved-aside
80 | *.xcuserstate
81 | *.xcscmblueprint
82 |
83 | ## Obj-C/Swift specific
84 | *.hmap
85 | *.ipa
86 |
87 | # CocoaPods
88 | #
89 | # We recommend against adding the Pods directory to your .gitignore. However
90 | # you should judge for yourself, the pros and cons are mentioned at:
91 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
92 | #
93 | #Pods/
94 |
95 | # Carthage
96 | #
97 | # Add this line if you want to avoid checking in source code from Carthage dependencies.
98 | # Carthage/Checkouts
99 |
100 | Carthage/Build
101 |
102 | ### Objective-C Patch ###
103 | *.xcscmblueprint
104 |
105 | ### Object UML ###
106 | .ObjcUML
--------------------------------------------------------------------------------
/Default-568h@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BloodAxe/OpenCV-Tutorial/cdf13b2703518b03d24bd8c9971631c226c8b8ce/Default-568h@2x.png
--------------------------------------------------------------------------------
/Default-Landscape@2x~ipad.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BloodAxe/OpenCV-Tutorial/cdf13b2703518b03d24bd8c9971631c226c8b8ce/Default-Landscape@2x~ipad.png
--------------------------------------------------------------------------------
/Default-Landscape~ipad.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BloodAxe/OpenCV-Tutorial/cdf13b2703518b03d24bd8c9971631c226c8b8ce/Default-Landscape~ipad.png
--------------------------------------------------------------------------------
/Default-Portrait@2x~ipad.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BloodAxe/OpenCV-Tutorial/cdf13b2703518b03d24bd8c9971631c226c8b8ce/Default-Portrait@2x~ipad.png
--------------------------------------------------------------------------------
/Default-Portrait~ipad.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BloodAxe/OpenCV-Tutorial/cdf13b2703518b03d24bd8c9971631c226c8b8ce/Default-Portrait~ipad.png
--------------------------------------------------------------------------------
/Default.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BloodAxe/OpenCV-Tutorial/cdf13b2703518b03d24bd8c9971631c226c8b8ce/Default.png
--------------------------------------------------------------------------------
/Default@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BloodAxe/OpenCV-Tutorial/cdf13b2703518b03d24bd8c9971631c226c8b8ce/Default@2x.png
--------------------------------------------------------------------------------
/Icon-72.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BloodAxe/OpenCV-Tutorial/cdf13b2703518b03d24bd8c9971631c226c8b8ce/Icon-72.png
--------------------------------------------------------------------------------
/Icon-72@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BloodAxe/OpenCV-Tutorial/cdf13b2703518b03d24bd8c9971631c226c8b8ce/Icon-72@2x.png
--------------------------------------------------------------------------------
/Icon-Small-50.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BloodAxe/OpenCV-Tutorial/cdf13b2703518b03d24bd8c9971631c226c8b8ce/Icon-Small-50.png
--------------------------------------------------------------------------------
/Icon-Small-50@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BloodAxe/OpenCV-Tutorial/cdf13b2703518b03d24bd8c9971631c226c8b8ce/Icon-Small-50@2x.png
--------------------------------------------------------------------------------
/Icon-Small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BloodAxe/OpenCV-Tutorial/cdf13b2703518b03d24bd8c9971631c226c8b8ce/Icon-Small.png
--------------------------------------------------------------------------------
/Icon-Small@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BloodAxe/OpenCV-Tutorial/cdf13b2703518b03d24bd8c9971631c226c8b8ce/Icon-Small@2x.png
--------------------------------------------------------------------------------
/Icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BloodAxe/OpenCV-Tutorial/cdf13b2703518b03d24bd8c9971631c226c8b8ce/Icon.png
--------------------------------------------------------------------------------
/Icon@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BloodAxe/OpenCV-Tutorial/cdf13b2703518b03d24bd8c9971631c226c8b8ce/Icon@2x.png
--------------------------------------------------------------------------------
/OpenCV Tutorial.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 6/23/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "SampleBase.h"
11 | #import "SampleFacade.h"
12 |
13 | @interface AppDelegate : UIResponder
14 | {
15 | @public
16 | std::vector allSamples;
17 | }
18 | @property (strong, nonatomic) UIWindow *window;
19 |
20 | @end
21 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/BaseSampleViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // BaseSampleViewController.h
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 7/20/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | #import "SampleBase.h"
12 | #import "SampleFacade.h"
13 |
14 | typedef void (^SaveImageCompletionHandler)();
15 |
16 | #define kSaveImageActionTitle @"Save image"
17 |
18 | @interface BaseSampleViewController : UIViewController
19 |
20 | @property (readonly) SampleFacade * currentSample;
21 |
22 | - (void) configureView;
23 | - (void) setSample:(SampleFacade*) sample;
24 | - (void) saveImage:(UIImage*) image withCompletionHandler: (SaveImageCompletionHandler) handler;
25 |
26 | @end
27 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/BaseSampleViewController.mm:
--------------------------------------------------------------------------------
1 | //
2 | // BaseSampleViewController.m
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 7/20/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #import "BaseSampleViewController.h"
10 | #import "NSString+StdString.h"
11 | #import "UIImage2OpenCV.h"
12 |
13 | @interface BaseSampleViewController ()
14 |
15 | @end
16 |
17 | @implementation BaseSampleViewController
18 | @synthesize currentSample = _currentSample;
19 |
20 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
21 | {
22 | self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
23 | if (self)
24 | {
25 | // Custom initialization
26 | }
27 | return self;
28 | }
29 |
30 | - (void)viewDidLoad
31 | {
32 | [super viewDidLoad];
33 | // Do any additional setup after loading the view.
34 | }
35 |
36 | - (void)viewDidUnload
37 | {
38 | [super viewDidUnload];
39 | // Release any retained subviews of the main view.
40 | }
41 |
42 | - (void) setSample:(SampleFacade*) sample
43 | {
44 | _currentSample = sample;
45 |
46 | [self configureView];
47 | }
48 |
49 | - (void) configureView
50 | {
51 | if (self.currentSample)
52 | {
53 | self.title = [self.currentSample title];
54 | }
55 | }
56 |
57 | #pragma mark - Image Saving
58 |
59 | - (void) saveImage:(UIImage *) image withCompletionHandler: (SaveImageCompletionHandler) handler
60 | {
61 | UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
62 | if (handler)
63 | handler();
64 | }
65 |
66 | - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
67 | {
68 | if (error != NULL)
69 | {
70 | NSLog(@"Error during saving image: %@", error);
71 | }
72 | }
73 |
74 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
75 | {
76 | if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
77 | {
78 | return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
79 | }
80 | else
81 | {
82 | return YES;
83 | }
84 | }
85 |
86 |
87 | @end
88 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/BooleanTableViewCell.h:
--------------------------------------------------------------------------------
1 | //
2 | // RangeValueTableViewCell.h
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 7/8/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "SampleOptions.h"
11 | #import "OptionCell.h"
12 |
13 | @interface BooleanTableViewCell : OptionCell
14 |
15 | - (void) configureWithOption: (BooleanOption*) option;
16 | - (IBAction)switchValueChanged:(id)sender;
17 |
18 | @property BooleanOption * option;
19 | @property (weak, nonatomic) IBOutlet UILabel *label;
20 | @property (weak, nonatomic) IBOutlet UISwitch *switchValue;
21 |
22 |
23 | @end
24 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/BooleanTableViewCell.mm:
--------------------------------------------------------------------------------
1 | //
2 | // RangeValueTableViewCell.m
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 7/8/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #import "BooleanTableViewCell.h"
10 | #import "NSString+StdString.h"
11 |
12 | @implementation BooleanTableViewCell
13 | @synthesize option;
14 | @synthesize label;
15 | @synthesize switchValue;
16 |
17 | - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
18 | {
19 | self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
20 | if (self)
21 | {
22 | NSLog(@"Cell height at startup:%f", self.bounds.size.height);
23 | // Initialization code
24 | }
25 | return self;
26 | }
27 |
28 |
29 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated
30 | {
31 | [super setSelected:selected animated:animated];
32 |
33 | // Configure the view for the selected state
34 | }
35 |
36 | - (void) configureWithOption: (BooleanOption*) opt
37 | {
38 | self.option = opt;
39 |
40 | NSLog(@"BooleanTableViewCell::configureWithOption - %d", (int)opt->getValue());
41 |
42 | self.label.text = [NSString stringWithStdString:opt->getName()];
43 | self.switchValue.on = opt->getValue();
44 |
45 | }
46 |
47 | - (IBAction)switchValueChanged:(id)sender
48 | {
49 | NSLog(@"Switch value changed to %d", (int)(self.switchValue.on));
50 | bool changed = option->setValue(self.switchValue.on);
51 |
52 | if (changed && self.delegate)
53 | {
54 | [self.delegate optionDidChanged:option];
55 | }
56 | }
57 |
58 | @end
59 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/CameraCalibrationAlgorithm.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 |
7 |
8 | enum PatternType {
9 | CHESSBOARD = 0,
10 | CIRCLES_GRID = 1,
11 | ACIRCLES_GRID = 2
12 | };
13 |
14 | class CameraCalibrationAlgorithm
15 | {
16 | public:
17 | typedef std::vector VectorOf3DPoints;
18 | typedef std::vector VectorOf2DPoints;
19 | typedef std::vector > VectorOfVectorOf3DPoints;
20 | typedef std::vector > VectorOfVectorOf2DPoints;
21 | typedef std::vector VectorOfMat;
22 |
23 | CameraCalibrationAlgorithm(cv::Size patternSize, PatternType type);
24 |
25 | bool detectCorners(const cv::Mat& frame, VectorOf2DPoints& corners2d) const;
26 |
27 | bool calibrateCamera(
28 | const VectorOfVectorOf2DPoints& gridCorners,
29 | const cv::Size imageSize,
30 | cv::Mat& cameraMatrix,
31 | cv::Mat& distCoeffs
32 | ) const;
33 |
34 | protected:
35 |
36 |
37 | static void calcChessboardCorners
38 | (
39 | cv::Size boardSize,
40 | float squareSize,
41 | VectorOf3DPoints& corners,
42 | PatternType patternType
43 | );
44 |
45 | static bool runCalibration
46 | (
47 | VectorOfVectorOf2DPoints imagePoints,
48 | cv::Size imageSize,
49 | cv::Size boardSize,
50 | PatternType patternType,
51 | float squareSize,
52 | float aspectRatio,
53 | int flags,
54 | cv::Mat& cameraMatrix,
55 | cv::Mat& distCoeffs,
56 | VectorOfMat& rvecs,
57 | VectorOfMat& tvecs,
58 | std::vector& reprojErrs,
59 | double& totalAvgErr
60 | );
61 |
62 | static double computeReprojectionErrors(
63 | const VectorOfVectorOf3DPoints& objectPoints,
64 | const VectorOfVectorOf2DPoints& imagePoints,
65 | const VectorOfMat& rvecs,
66 | const VectorOfMat& tvecs,
67 | const cv::Mat& cameraMatrix,
68 | const cv::Mat& distCoeffs,
69 | std::vector& perViewErrors
70 | );
71 |
72 |
73 | private:
74 | cv::Size m_patternSize;
75 | PatternType m_pattern;
76 | };
77 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/CameraCalibrationSample.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // CameraCalibrationSample.cpp
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 1/29/15.
6 | //
7 | //
8 |
9 | #include "CameraCalibrationSample.h"
10 | #include
11 |
12 | CameraCalibrationSample::CameraCalibrationSample()
13 | : mAlg(cv::Size(4, 11), ACIRCLES_GRID)
14 | , frame(0)
15 | {
16 | }
17 |
18 | std::string CameraCalibrationSample::getDescription() const
19 | {
20 | return "CameraCalibrationSample";
21 | }
22 |
23 | std::string CameraCalibrationSample::getName() const
24 | {
25 | return "Camera Calibration";
26 | }
27 |
28 | bool CameraCalibrationSample::processFrame(const cv::Mat& inputFrame, cv::Mat& outputFrame)
29 | {
30 | frame++;
31 |
32 | if (frame % 50)
33 | return false;
34 |
35 | cv::cvtColor(inputFrame, gray, cv::COLOR_BGR2GRAY);
36 |
37 | CameraCalibrationAlgorithm::VectorOf2DPoints corners2d;
38 | if (mAlg.detectCorners(gray, corners2d))
39 | {
40 | mCorners.push_back(corners2d);
41 | std::cout << "Detected" << std::endl;
42 | }
43 |
44 | if (mCorners.size() > 10)
45 | {
46 | cv::Mat K, D;
47 | mAlg.calibrateCamera(mCorners, inputFrame.size(), K, D);
48 | std::cout << K << std::endl;
49 | std::cout << D << std::endl;
50 |
51 | mAlg = CameraCalibrationAlgorithm(cv::Size(11, 4), ACIRCLES_GRID);
52 | mCorners.clear();
53 | }
54 |
55 | return true;
56 | }
57 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/CameraCalibrationSample.h:
--------------------------------------------------------------------------------
1 | //
2 | // CameraCalibrationSample.h
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 1/29/15.
6 | //
7 | //
8 |
9 | #pragma once
10 |
11 | #include "SampleBase.h"
12 | #include "CameraCalibrationAlgorithm.h"
13 |
14 | class CameraCalibrationSample : public SampleBase
15 | {
16 | public:
17 | CameraCalibrationSample();
18 |
19 | //! Gets a sample name
20 | virtual std::string getName() const;
21 |
22 | //! Returns a detailed sample description
23 | virtual std::string getDescription() const;
24 |
25 | //! Processes a frame and returns output image
26 | virtual bool processFrame(const cv::Mat& inputFrame, cv::Mat& outputFrame);
27 |
28 | private:
29 | int frame;
30 | cv::Mat gray;
31 | CameraCalibrationAlgorithm mAlg;
32 |
33 | CameraCalibrationAlgorithm::VectorOfVectorOf2DPoints mCorners;
34 | };
35 |
36 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/CartoonFilter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // CartoonFilter.cpp
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 7/19/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #include
10 | #include "CartoonFilter.h"
11 |
12 | CartoonFilter::CartoonFilter()
13 | : sp(15)
14 | , sr(40)
15 | {
16 | registerOption("Spatial window radius", "", &sp, 1, 50);
17 | registerOption("Color window radius", "", &sr, 1, 50);
18 | }
19 |
20 | std::string CartoonFilter::getName() const
21 | {
22 | return "Cartoon filter";
23 | }
24 |
25 | std::string CartoonFilter::getDescription() const
26 | {
27 | return "This sample performs cartoon-like effect";
28 | }
29 |
30 | bool CartoonFilter::processFrame(const cv::Mat& inputFrame, cv::Mat& outputFrame)
31 | {
32 | cv::cvtColor(inputFrame, bgr, cv::COLOR_BGRA2BGR);
33 | cv::pyrMeanShiftFiltering(bgr.clone(), bgr, sp, sr);
34 |
35 | getGray(bgr, gray);
36 | cv::Canny(gray, edges, 150, 150);
37 |
38 | cv::cvtColor(edges, edgesBgr, cv::COLOR_GRAY2BGR);
39 |
40 | bgr = bgr - edgesBgr;
41 |
42 | cv::cvtColor(bgr, outputFrame, cv::COLOR_BGR2BGRA);
43 | return true;
44 | }
--------------------------------------------------------------------------------
/OpenCV Tutorial/CartoonFilter.h:
--------------------------------------------------------------------------------
1 | //
2 | // CartoonFilter.h
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 7/19/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #ifndef OpenCV_Tutorial_CartoonFilter_h
10 | #define OpenCV_Tutorial_CartoonFilter_h
11 |
12 | #include "SampleBase.h"
13 |
14 | class CartoonFilter : public SampleBase
15 | {
16 | public:
17 | CartoonFilter();
18 |
19 | //! Gets a sample name
20 | virtual std::string getName() const;
21 |
22 | //! Returns a detailed sample description
23 | virtual std::string getDescription() const;
24 |
25 | //! Processes a frame and returns output image
26 | virtual bool processFrame(const cv::Mat& inputFrame, cv::Mat& outputFrame);
27 |
28 | private:
29 | float sp;
30 | float sr;
31 |
32 | cv::Mat gray, edges;
33 | cv::Mat hsv;
34 |
35 | cv::Mat bgr, img0;
36 | cv::Mat edgesBgr;
37 |
38 | };
39 |
40 |
41 | #endif
42 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/ContourDetectionSample.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // ContourDetectionSample.cpp
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 6/23/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #include
10 | #include "ContourDetectionSample.h"
11 |
12 | //! Gets a sample name
13 | std::string ContourDetectionSample::getName() const
14 | {
15 | return "Contour detection";
16 | }
17 |
18 | //! Returns a detailed sample description
19 | std::string ContourDetectionSample::getDescription() const
20 | {
21 | return "Image contour detection is fundamental to many image analysis applications, including image segmentation, object recognition and classification.";
22 | }
23 |
24 | std::string ContourDetectionSample::getSampleIcon() const
25 | {
26 | return "ContourDetectionSampleIcon.png";
27 | }
28 |
29 | //! Processes a frame and returns output image
30 | bool ContourDetectionSample::processFrame(const cv::Mat& inputFrame, cv::Mat& outputFrame)
31 | {
32 | getGray(inputFrame, gray);
33 |
34 | cv::Mat edges;
35 | cv::Canny(gray, edges, 50, 150);
36 |
37 | std::vector< std::vector > c;
38 |
39 | cv::findContours(edges, c, cv::RETR_LIST, cv::CHAIN_APPROX_NONE);
40 |
41 | inputFrame.copyTo(outputFrame);
42 | cv::drawContours(outputFrame, c, -1, cv::Scalar(0,200,0));
43 |
44 | return true;
45 | }
--------------------------------------------------------------------------------
/OpenCV Tutorial/ContourDetectionSample.h:
--------------------------------------------------------------------------------
1 | //
2 | // ContourDetectionSample.h
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 6/23/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #ifndef OpenCV_Tutorial_ContourDetectionSample_h
10 | #define OpenCV_Tutorial_ContourDetectionSample_h
11 |
12 | #include "SampleBase.h"
13 |
14 | class ContourDetectionSample : public SampleBase
15 | {
16 | //! Gets a sample name
17 | virtual std::string getName() const;
18 |
19 | virtual std::string getSampleIcon() const;
20 |
21 | //! Returns a detailed sample description
22 | virtual std::string getDescription() const;
23 |
24 | //! Processes a frame and returns output image
25 | virtual bool processFrame(const cv::Mat& inputFrame, cv::Mat& outputFrame);
26 |
27 | private:
28 | cv::Mat gray, edges;
29 | };
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/ContourDetectionSampleIcon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BloodAxe/OpenCV-Tutorial/cdf13b2703518b03d24bd8c9971631c226c8b8ce/OpenCV Tutorial/ContourDetectionSampleIcon.png
--------------------------------------------------------------------------------
/OpenCV Tutorial/ContourDetectionSampleIcon@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BloodAxe/OpenCV-Tutorial/cdf13b2703518b03d24bd8c9971631c226c8b8ce/OpenCV Tutorial/ContourDetectionSampleIcon@2x.png
--------------------------------------------------------------------------------
/OpenCV Tutorial/DefaultSampleIcon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BloodAxe/OpenCV-Tutorial/cdf13b2703518b03d24bd8c9971631c226c8b8ce/OpenCV Tutorial/DefaultSampleIcon.png
--------------------------------------------------------------------------------
/OpenCV Tutorial/DefaultSampleIcon~ipad.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BloodAxe/OpenCV-Tutorial/cdf13b2703518b03d24bd8c9971631c226c8b8ce/OpenCV Tutorial/DefaultSampleIcon~ipad.png
--------------------------------------------------------------------------------
/OpenCV Tutorial/DetailViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // DetailViewController.h
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 6/23/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "SampleFacade.h"
11 |
12 | @interface DetailViewController : UIViewController
13 | {
14 | SampleFacade* currentSample;
15 | UIImagePickerController * imagePicker;
16 | }
17 |
18 | @property (weak, nonatomic) IBOutlet UIImageView *sampleIconView;
19 | @property (weak, nonatomic) IBOutlet UITextView *sampleDescriptionTextView;
20 | @property (weak, nonatomic) IBOutlet UIButton *runOnImageButton;
21 | @property (weak, nonatomic) IBOutlet UIButton *runOnVideoButton;
22 |
23 | - (void) setDetailItem:(SampleFacade*) sample;
24 | - (void) configureView;
25 |
26 | @end
27 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/DoubleTableViewCell.h:
--------------------------------------------------------------------------------
1 | //
2 | // DoubleTableViewCell.h
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 7/30/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "SampleOptions.h"
11 | #import "OptionCell.h"
12 |
13 | @interface DoubleTableViewCell : OptionCell
14 |
15 | @property (weak, nonatomic) IBOutlet UILabel *label;
16 | @property (weak, nonatomic) IBOutlet UILabel *currentValue;
17 | @property (weak, nonatomic) IBOutlet UISlider *sliderValue;
18 |
19 | @property DoubleOption * option;
20 |
21 | - (IBAction)sliderValueChanged:(id)sender;
22 |
23 | - (void) configureWithOption: (DoubleOption*) option;
24 |
25 |
26 | @end
27 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/DoubleTableViewCell.mm:
--------------------------------------------------------------------------------
1 | //
2 | // DoubleTableViewCell.m
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 7/30/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #import "DoubleTableViewCell.h"
10 | #import "NSString+StdString.h"
11 |
12 | @implementation DoubleTableViewCell
13 |
14 | @synthesize label;
15 | @synthesize currentValue;
16 | @synthesize sliderValue;
17 | @synthesize option;
18 |
19 | - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
20 | {
21 | self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
22 | if (self) {
23 | // Initialization code
24 | }
25 | return self;
26 | }
27 |
28 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated
29 | {
30 | [super setSelected:selected animated:animated];
31 |
32 | // Configure the view for the selected state
33 | }
34 |
35 | - (void) configureWithOption: (DoubleOption*) opt
36 | {
37 | self.option = opt;
38 |
39 | label.text = [NSString stringWithStdString: option->getName()];
40 |
41 | sliderValue.maximumValue = self.option->getMaxValue();
42 | sliderValue.minimumValue = self.option->getMinValue();
43 | sliderValue.value = self.option->getValue();
44 |
45 | [self sliderValueChanged:self];
46 | }
47 |
48 | - (IBAction)sliderValueChanged:(id)sender
49 | {
50 | currentValue.text = [NSString stringWithFormat:@"%f", sliderValue.value];
51 |
52 | bool changed = option->setValue(sliderValue.value);
53 | if (changed && self.delegate)
54 | {
55 | [self.delegate optionDidChanged:option];
56 | }
57 |
58 | }
59 | @end
60 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/DrawingCanvas.h:
--------------------------------------------------------------------------------
1 | //
2 | // DrawingCanvas.h
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 9/4/12.
6 | //
7 | //
8 |
9 | #ifndef OpenCV_Tutorial_DrawingCanvas_h
10 | #define OpenCV_Tutorial_DrawingCanvas_h
11 |
12 | #include "SampleBase.h"
13 |
14 | class DrawingCanvasSample : public SampleBase
15 | {
16 | public:
17 | DrawingCanvasSample();
18 |
19 | //! Gets a sample name
20 | virtual std::string getName() const;
21 |
22 | //! Returns a detailed sample description
23 | virtual std::string getDescription() const;
24 |
25 | //! Processes a frame and returns output image
26 | virtual bool processFrame(const cv::Mat& inputFrame, cv::Mat& outputFrame);
27 |
28 | private:
29 | std::string m_currentView;
30 |
31 | cv::Mat m_grayImage;
32 | cv::Mat m_filtered;
33 |
34 | cv::Mat bgColor, fgColor;
35 | cv::Mat bgMask3channels;
36 | cv::Mat fgMask3channels;
37 | cv::Mat bgMask;
38 |
39 | float m_bilateralSigmaThreshold;
40 | float m_bilateralColorThreshold;
41 | float m_bilateralD;
42 |
43 | int m_thresholdBlockSize;
44 | float m_thresholdC;
45 | };
46 |
47 |
48 | #endif
49 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/EdgeDetectionSample.h:
--------------------------------------------------------------------------------
1 | //
2 | // EdgeDetectionSample.h
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 6/24/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #ifndef OpenCV_Tutorial_EdgeDetectionSample_h
10 | #define OpenCV_Tutorial_EdgeDetectionSample_h
11 |
12 |
13 | #include "SampleBase.h"
14 |
15 | class EdgeDetectionSample : public SampleBase
16 | {
17 | public:
18 | EdgeDetectionSample();
19 |
20 | //! Gets a sample name
21 | virtual std::string getName() const;
22 |
23 | //virtual std::string getSampleIcon() const;
24 |
25 | //! Returns a detailed sample description
26 | virtual std::string getDescription() const;
27 |
28 | //! Processes a frame and returns output image
29 | virtual bool processFrame(const cv::Mat& inputFrame, cv::Mat& outputFrame);
30 |
31 | private:
32 | cv::Mat grayImage;
33 | cv::Mat edges;
34 |
35 | cv::Mat grad_x, grad_y;
36 | cv::Mat abs_grad_x, abs_grad_y;
37 |
38 | cv::Mat dst;
39 | cv::Mat dst_norm, dst_norm_scaled;
40 |
41 | bool m_showOnlyEdges;
42 | std::string m_algorithmName;
43 |
44 | // Canny detector options:
45 | int m_cannyLoThreshold;
46 | int m_cannyHiThreshold;
47 | int m_cannyAperture;
48 |
49 | // Harris detector options:
50 | int m_harrisBlockSize;
51 | int m_harrisapertureSize;
52 | double m_harrisK;
53 | int m_harrisThreshold;
54 | };
55 |
56 | #endif
57 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/EdgeDetectionSampleIcon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BloodAxe/OpenCV-Tutorial/cdf13b2703518b03d24bd8c9971631c226c8b8ce/OpenCV Tutorial/EdgeDetectionSampleIcon.png
--------------------------------------------------------------------------------
/OpenCV Tutorial/EdgeDetectionSampleIcon~ipad.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BloodAxe/OpenCV-Tutorial/cdf13b2703518b03d24bd8c9971631c226c8b8ce/OpenCV Tutorial/EdgeDetectionSampleIcon~ipad.png
--------------------------------------------------------------------------------
/OpenCV Tutorial/EnumTableViewCell.h:
--------------------------------------------------------------------------------
1 | //
2 | // EnumTableViewCell.h
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 7/9/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "SampleOptions.h"
11 | #import "OptionCell.h"
12 |
13 | @interface EnumTableViewCell : OptionCell
14 |
15 | @property StringEnumOption * option;
16 |
17 | - (void) configureWithOption: (StringEnumOption*) option;
18 |
19 | @property (weak, nonatomic) IBOutlet UILabel *label;
20 | @property (weak, nonatomic) IBOutlet UISegmentedControl *segmentedControl;
21 |
22 | - (IBAction)segmentedControlChanged:(id)sender;
23 |
24 | @end
25 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/EnumTableViewCell.mm:
--------------------------------------------------------------------------------
1 | //
2 | // EnumTableViewCell.m
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 7/9/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #import "EnumTableViewCell.h"
10 | #import "NSString+StdString.h"
11 |
12 | @implementation EnumTableViewCell
13 | @synthesize label;
14 | @synthesize segmentedControl;
15 | @synthesize option;
16 |
17 | - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
18 | {
19 | self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
20 | if (self) {
21 | // Initialization code
22 | }
23 | return self;
24 | }
25 |
26 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated
27 | {
28 | [super setSelected:selected animated:animated];
29 |
30 | // Configure the view for the selected state
31 | }
32 |
33 |
34 |
35 | - (void) configureWithOption: (StringEnumOption*) opt
36 | {
37 | self.option = opt;
38 | self.label.text = [NSString stringWithStdString:self.option->getName()];
39 |
40 | [self.segmentedControl removeAllSegments];
41 |
42 | size_t numberOfItems = self.option->getEnums().size();
43 |
44 | for (size_t i=0; i < numberOfItems; i++)
45 | {
46 | NSString * title = [NSString stringWithStdString:self.option->getEnums()[i]];
47 | [self.segmentedControl insertSegmentWithTitle:title atIndex:i animated:NO];
48 | }
49 |
50 | [self.segmentedControl setSelectedSegmentIndex:self.option->getValueIndex()];
51 | }
52 |
53 | - (IBAction)segmentedControlChanged:(id)sender
54 | {
55 | bool changed = self.option->setValue(self.segmentedControl.selectedSegmentIndex);
56 |
57 | if (changed && self.delegate)
58 | {
59 | [self.delegate optionDidChanged:option];
60 | }
61 |
62 | }
63 | @end
64 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/FPSCalculator.h:
--------------------------------------------------------------------------------
1 | //
2 | // FPSCalculator.h
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 7/4/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface FPSCalculator : NSObject
12 |
13 | - (void) putTimeMark;
14 |
15 | - (float) getFPS;
16 |
17 | - (NSString*) getFPSAsText;
18 |
19 | @end
20 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/FPSCalculator.mm:
--------------------------------------------------------------------------------
1 | //
2 | // FPSCalculator.m
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 7/4/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #import "FPSCalculator.h"
10 |
11 | #include
12 | #include
13 | #include
14 |
15 | @interface FPSCalculator()
16 | {
17 | bool initialized;
18 | uint64_t past;
19 |
20 | uint64_t elapsedNano;
21 | int elapsedMarks;
22 |
23 | float currentFps;
24 |
25 | mach_timebase_info_data_t sTimebaseInfo;
26 | }
27 | @end
28 |
29 | @implementation FPSCalculator
30 |
31 | - (id) init
32 | {
33 | if (self = [super init])
34 | {
35 | mach_timebase_info(&sTimebaseInfo);
36 | }
37 |
38 | return self;
39 | }
40 |
41 | - (void) putTimeMark
42 | {
43 | uint64_t now = mach_absolute_time();
44 | elapsedMarks++;
45 |
46 | if (initialized)
47 | {
48 | uint64_t elapsed = now - past;
49 |
50 | elapsedNano += elapsed * sTimebaseInfo.numer / sTimebaseInfo.denom;
51 | }
52 |
53 | initialized = true;
54 | past = now;
55 | }
56 |
57 | - (float) getFPS
58 | {
59 | if (elapsedNano > 1000000000)
60 | {
61 | currentFps = (float)elapsedMarks / (1.0e-9 * elapsedNano);
62 | elapsedMarks = 0;
63 | elapsedNano = 0;
64 | }
65 |
66 | return currentFps;
67 | }
68 |
69 | - (NSString*) getFPSAsText
70 | {
71 | int fps = static_cast([self getFPS] + 0.5f);
72 |
73 | return [NSString stringWithFormat:@"%d FPS", fps];
74 | }
75 |
76 | @end
77 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/FeatureDetectionSample.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // FeatureDetection.cpp
3 | // OpenCV Tutorial
4 | //
5 | // Created by Anton Belodedenko on 25/07/2012.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #include
10 | #include "FeatureDetectionSample.h"
11 |
12 | #define kDetectorORB "ORB"
13 | #define kDetectorAKAZE "AKAZE"
14 | #define kDetectorFAST "FAST"
15 |
16 | FeatureDetectionSample::FeatureDetectionSample()
17 | : m_maxFeatures(100)
18 | , m_fastThreshold(10)
19 | {
20 | // feature extraction options
21 | m_alorithms.push_back( kDetectorORB );
22 | m_alorithms.push_back( kDetectorFAST );
23 | m_alorithms.push_back( kDetectorAKAZE );
24 |
25 | m_ORB = cv::ORB::create();
26 | m_FAST = cv::FastFeatureDetector::create();
27 | m_AKAZE = cv::AKAZE::create();
28 |
29 | registerOption("Detection algorithm", "", &m_detectorName, m_alorithms);
30 | registerOption("Max features", "", &m_maxFeatures, 1, 100);
31 |
32 |
33 | registerOption("Threshold", "FAST", &m_fastThreshold, 1, 100);
34 | }
35 |
36 | //! Gets a sample name
37 | std::string FeatureDetectionSample::getName() const
38 | {
39 | return "Feature detection";
40 | }
41 |
42 | std::string FeatureDetectionSample::getSampleIcon() const
43 | {
44 | return "FeatureDetectionSampleIcon.png";
45 | }
46 |
47 | //! Returns a detailed sample description
48 | std::string FeatureDetectionSample::getDescription() const
49 | {
50 | return "Feature detection sample.";
51 | }
52 |
53 | static bool keypoint_score_greater(const cv::KeyPoint& kp1, const cv::KeyPoint& kp2)
54 | {
55 | return kp1.response > kp2.response;
56 | }
57 |
58 | //! Processes a frame and returns output image
59 | bool FeatureDetectionSample::processFrame(const cv::Mat& inputFrame, cv::Mat& outputFrame)
60 | {
61 | // convert input frame to gray scale
62 | getGray(inputFrame, grayImage);
63 |
64 |
65 | if (m_detectorName == kDetectorORB)
66 | {
67 | m_ORB->detect(grayImage, objectKeypoints);
68 | }
69 | else if (m_detectorName == kDetectorFAST)
70 | {
71 | m_FAST->detect(grayImage, objectKeypoints);
72 | }
73 | else if (m_detectorName == kDetectorAKAZE)
74 | {
75 | m_AKAZE->detect(grayImage, objectKeypoints);
76 | }
77 |
78 | cv::KeyPointsFilter::retainBest(objectKeypoints, m_maxFeatures);
79 |
80 | if (objectKeypoints.size() > m_maxFeatures)
81 | {
82 | std::sort(objectKeypoints.begin(), objectKeypoints.end(), keypoint_score_greater);
83 | objectKeypoints.resize(m_maxFeatures);
84 | }
85 |
86 | cv::Mat t;
87 | cv::cvtColor(inputFrame, t, cv::COLOR_BGRA2BGR);
88 | cv::drawKeypoints(t, objectKeypoints, t, cv::Scalar::all(-1), cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
89 |
90 | cv::cvtColor(t, outputFrame, cv::COLOR_BGR2BGRA);
91 | return true;
92 | }
--------------------------------------------------------------------------------
/OpenCV Tutorial/FeatureDetectionSample.h:
--------------------------------------------------------------------------------
1 | //
2 | // FeatureDetection.h
3 | // OpenCV Tutorial
4 | //
5 | // Created by Anton Belodedenko on 25/07/2012.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #ifndef OpenCV_Tutorial_FeatureDetection_h
10 | #define OpenCV_Tutorial_FeatureDetection_h
11 |
12 | #include "SampleBase.h"
13 |
14 | class FeatureDetectionSample : public SampleBase
15 | {
16 | public:
17 | FeatureDetectionSample();
18 |
19 | //! Gets a sample name
20 | virtual std::string getName() const;
21 |
22 | virtual std::string getSampleIcon() const;
23 |
24 | //! Returns a detailed sample description
25 | virtual std::string getDescription() const;
26 |
27 | //! Processes a frame and returns output image
28 | virtual bool processFrame(const cv::Mat& inputFrame, cv::Mat& outputFrame);
29 |
30 | private:
31 | cv::Mat grayImage;
32 |
33 | std::vector objectKeypoints;
34 |
35 | std::string m_detectorName;
36 | std::vector m_alorithms;
37 |
38 | cv::Ptr m_ORB;
39 | cv::Ptr m_AKAZE;
40 | cv::Ptr m_FAST;
41 |
42 | int m_maxFeatures;
43 | int m_fastThreshold;
44 | };
45 |
46 | #endif
47 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/FeatureDetectionSampleIcon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BloodAxe/OpenCV-Tutorial/cdf13b2703518b03d24bd8c9971631c226c8b8ce/OpenCV Tutorial/FeatureDetectionSampleIcon.png
--------------------------------------------------------------------------------
/OpenCV Tutorial/FloatTableViewCell.h:
--------------------------------------------------------------------------------
1 | //
2 | // FloatTableViewCell.h
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 7/9/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "SampleOptions.h"
11 | #import "OptionCell.h"
12 |
13 | @interface FloatTableViewCell : OptionCell
14 |
15 | @property (weak, nonatomic) IBOutlet UILabel *label;
16 | @property (weak, nonatomic) IBOutlet UILabel *currentValue;
17 | @property (weak, nonatomic) IBOutlet UISlider *sliderValue;
18 |
19 | @property FloatOption * option;
20 |
21 | - (IBAction)sliderValueChanged:(id)sender;
22 |
23 | - (void) configureWithOption: (FloatOption*) option;
24 |
25 |
26 | @end
27 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/FloatTableViewCell.mm:
--------------------------------------------------------------------------------
1 | //
2 | // FloatTableViewCell.m
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 7/9/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #import "FloatTableViewCell.h"
10 | #import "NSString+StdString.h"
11 |
12 | @implementation FloatTableViewCell
13 | @synthesize label;
14 | @synthesize currentValue;
15 | @synthesize sliderValue;
16 | @synthesize option;
17 |
18 | - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
19 | {
20 | self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
21 | if (self) {
22 | // Initialization code
23 | }
24 | return self;
25 | }
26 |
27 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated
28 | {
29 | [super setSelected:selected animated:animated];
30 |
31 | // Configure the view for the selected state
32 | }
33 |
34 | - (void) configureWithOption: (FloatOption*) opt
35 | {
36 | self.option = opt;
37 |
38 | label.text = [NSString stringWithStdString: option->getName()];
39 |
40 | sliderValue.maximumValue = self.option->getMaxValue();
41 | sliderValue.minimumValue = self.option->getMinValue();
42 | sliderValue.value = self.option->getValue();
43 |
44 | [self sliderValueChanged:self];
45 | }
46 |
47 | - (IBAction)sliderValueChanged:(id)sender
48 | {
49 | currentValue.text = [NSString stringWithFormat:@"%f", sliderValue.value];
50 |
51 | bool changed = option->setValue(sliderValue.value);
52 | if (changed && self.delegate)
53 | {
54 | [self.delegate optionDidChanged:option];
55 | }
56 |
57 | }
58 | @end
59 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/Globals.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Globals.cpp
3 | // OpenCV Tutorial
4 | //
5 | // Created by Anton Belodedenko on 26/07/2012.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #include
10 |
11 | // control flags
12 | bool computeObject = false;
13 | bool detectObject = false;
14 | bool trackObject = false;
15 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/Globals.h:
--------------------------------------------------------------------------------
1 | //
2 | // Globals.h
3 | // OpenCV Tutorial
4 | //
5 | // Created by Anton Belodedenko on 26/07/2012.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #ifndef OpenCV_Tutorial_Globals_h
10 | #define OpenCV_Tutorial_Globals_h
11 |
12 | // control flags
13 | extern bool computeObject;
14 | extern bool detectObject;
15 | extern bool trackObject;
16 |
17 | #endif
18 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/ImageFiltersSample.h:
--------------------------------------------------------------------------------
1 | //
2 | // ImageFiltersSample.h
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 7/8/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #ifndef OpenCV_Tutorial_ImageFiltersSample_h
10 | #define OpenCV_Tutorial_ImageFiltersSample_h
11 |
12 | #include "SampleBase.h"
13 |
14 | class ImageFiltersSample : public SampleBase
15 | {
16 | public:
17 | ImageFiltersSample();
18 |
19 | //! Gets a sample name
20 | virtual std::string getName() const;
21 |
22 | virtual std::string getUserFriendlyName() const;
23 |
24 | //! Returns a detailed sample description
25 | virtual std::string getDescription() const;
26 |
27 | //! Processes a frame and returns output image
28 | virtual bool processFrame(const cv::Mat& inputFrame, cv::Mat& outputFrame);
29 |
30 | private:
31 | void sepia(const cv::Mat& inputFrame, cv::Mat& outputFrame);
32 |
33 | void negative(const cv::Mat& inputFrame, cv::Mat& outputFrame);
34 |
35 | void contrastAndBrightnessAdjust(const cv::Mat& inputFrame, cv::Mat& outputFrame);
36 |
37 | private:
38 | std::string m_currentEffect;
39 |
40 | cv::Mat_ m_sepiaKernel;
41 | cv::Mat_ m_sepiaKernelT;
42 |
43 | float m_alpha;
44 | int m_bias;
45 |
46 | cv::Mat_ m_contrastKernel;
47 | cv::Mat_ m_contrastKernelT;
48 |
49 | bool useNeonOptimized;
50 | };
51 |
52 | #endif
53 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/ImageViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // ImageViewController.h
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 7/4/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "SampleBase.h"
11 | #import "OptionsTableView.h"
12 | #import "OptionCell.h"
13 | #import "BaseSampleViewController.h"
14 |
15 |
16 | @interface ImageViewController : BaseSampleViewController
17 |
18 | - (void) setImage:(UIImage*) image;
19 |
20 | @property (nonatomic, strong) UIImageView *imageView;
21 | @property (nonatomic, strong) OptionsTableView *optionsView;
22 | @property (nonatomic, strong) UIPopoverController * optionsPopover;
23 | @property (nonatomic, strong) UIViewController * optionsViewController;
24 | @property (nonatomic, strong) UIAlertController * actionSheet;
25 |
26 | @property (weak, nonatomic) IBOutlet UIView *containerView;
27 | @property (weak, nonatomic) IBOutlet UIBarButtonItem *takePhotoButton;
28 | @property (weak, nonatomic) IBOutlet UIBarButtonItem *optionsBarButton;
29 | @property (weak, nonatomic) IBOutlet UIBarButtonItem *actionButton;
30 |
31 | - (IBAction) presentOptionsView:(id)sender;
32 | - (IBAction) selectPictureForProcessing:(id) sender;
33 | - (IBAction) selectAction:(id)sender;
34 |
35 |
36 | @end
37 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/Int32TableViewCell.h:
--------------------------------------------------------------------------------
1 | //
2 | // Int32TableViewCell.h
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 7/9/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "SampleOptions.h"
11 | #import "OptionCell.h"
12 |
13 | @interface Int32TableViewCell : OptionCell
14 |
15 | @property (weak, nonatomic) IBOutlet UILabel *label;
16 | @property (weak, nonatomic) IBOutlet UILabel *currentValue;
17 | @property (weak, nonatomic) IBOutlet UISlider *sliderValue;
18 |
19 | @property Int32Option * option;
20 |
21 | - (IBAction)sliderValueChanged:(id)sender;
22 |
23 | - (void) configureWithOption: (Int32Option*) option;
24 |
25 | @end
26 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/Int32TableViewCell.mm:
--------------------------------------------------------------------------------
1 | //
2 | // Int32TableViewCell.m
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 7/9/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #import "Int32TableViewCell.h"
10 | #import "NSString+StdString.h"
11 |
12 | @implementation Int32TableViewCell
13 | @synthesize option;
14 | @synthesize label;
15 | @synthesize sliderValue;
16 | @synthesize currentValue;
17 |
18 | - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
19 | {
20 | self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
21 | if (self) {
22 | // Initialization code
23 | }
24 | return self;
25 | }
26 |
27 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated
28 | {
29 | [super setSelected:selected animated:animated];
30 |
31 | // Configure the view for the selected state
32 | }
33 |
34 | - (void) configureWithOption: (Int32Option*) opt
35 | {
36 | self.option = opt;
37 |
38 | label.text = [NSString stringWithStdString: option->getName()];
39 |
40 | sliderValue.maximumValue = self.option->getMaxValue();
41 | sliderValue.minimumValue = self.option->getMinValue();
42 | sliderValue.value = self.option->getValue();
43 |
44 | [self sliderValueChanged:self];
45 | }
46 |
47 | - (IBAction)sliderValueChanged:(id)sender
48 | {
49 | currentValue.text = [NSString stringWithFormat:@"%d", (int)sliderValue.value];
50 |
51 | bool changed = option->setValue( (int)sliderValue.value);
52 | if (changed && self.delegate)
53 | {
54 | [self.delegate optionDidChanged:option];
55 | }
56 | }
57 |
58 |
59 | @end
60 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/Mandrill512x512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BloodAxe/OpenCV-Tutorial/cdf13b2703518b03d24bd8c9971631c226c8b8ce/OpenCV Tutorial/Mandrill512x512.png
--------------------------------------------------------------------------------
/OpenCV Tutorial/MasterViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // MasterViewController.h
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 6/23/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @class DetailViewController;
12 |
13 | @interface MasterViewController : UITableViewController
14 |
15 | @property (strong, nonatomic) DetailViewController *detailViewController;
16 |
17 | @end
18 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/NSString+StdString.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSString+StdString.h
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 7/9/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface NSString (StdString)
12 |
13 | + (NSString*) stringWithStdString: (const std::string&) str;
14 |
15 | //- (std::string) toStdString;
16 |
17 | @end
18 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/NSString+StdString.mm:
--------------------------------------------------------------------------------
1 | //
2 | // NSString+StdString.m
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 7/9/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #import "NSString+StdString.h"
10 |
11 | @implementation NSString (StdString)
12 |
13 | + (NSString*) stringWithStdString: (const std::string&) str
14 | {
15 | return [[NSString alloc] initWithCString:str.c_str() encoding:NSASCIIStringEncoding];
16 | }
17 |
18 | @end
19 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/ObjectTrackingClass.h:
--------------------------------------------------------------------------------
1 | //
2 | // ObjectTrackingClass.h
3 | // OpenCV Tutorial
4 | //
5 | // Created by Anton Belodedenko on 26/07/2012.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #ifndef OpenCV_Tutorial_ObjectTrackingClass_h
10 | #define OpenCV_Tutorial_ObjectTrackingClass_h
11 |
12 | class ObjectTrackingClass
13 | {
14 | private:
15 | int maxCorners;
16 | double qualityLevel;
17 | double minDistance;
18 | int blockSize;
19 | bool useHarrisDetector;
20 | double k;
21 | cv::Size subPixWinSize, winSize;
22 | cv::TermCriteria termcrit;
23 | int maxLevel;
24 | int flags;
25 | double minEigThreshold;
26 |
27 | public:
28 | ObjectTrackingClass()
29 | : maxCorners(200)
30 | , qualityLevel(0.01)
31 | , minDistance(10)
32 | , blockSize(3)
33 | , useHarrisDetector(false)
34 | , subPixWinSize(10,10)
35 | , winSize(31,31)
36 | , termcrit(cv::TermCriteria::MAX_ITER | cv::TermCriteria::EPS,20,0.03)
37 | , maxLevel(3)
38 | , flags(0)
39 | , minEigThreshold(0.001)
40 |
41 | {
42 | // nothing to do for now
43 | }
44 |
45 | // set maxcorners
46 | void setMaxCorners(int maxCorners);
47 |
48 | // initialise tracker
49 | void init(cv::Mat& image, // output image
50 | cv::Mat& image1, // source image
51 | std::vector& points1); // points array
52 |
53 | // track optical flow
54 | void track(cv::Mat& image, // output image
55 | cv::Mat& image1, // input image 1
56 | cv::Mat& image2, // input image 2
57 | std::vector& points1, // points array 1
58 | std::vector& points2, // points array 2
59 | std::vector& status, // status array
60 | std::vector& err); // error array
61 | };
62 |
63 | #endif
64 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/ObjectTrackingSample.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // ObjectTrackingSample.cpp
3 | // OpenCV Tutorial
4 | //
5 | // Created by Anton Belodedenko on 26/07/2012.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #include
10 | #include "ObjectTrackingClass.h"
11 | #include "ObjectTrackingSample.h"
12 | #include "Globals.h"
13 |
14 | ObjectTrackingSample::ObjectTrackingSample()
15 | : m_algorithmName("LKT")
16 | , m_maxCorners(200)
17 | {
18 | std::vector algos;
19 | algos.push_back("LKT");
20 | registerOption("Algorithm", "", &m_algorithmName, algos);
21 |
22 | // object tracking options
23 | registerOption("m_maxCorners", "Tracking", &m_maxCorners, 0, 1000);
24 | }
25 |
26 | //! Gets a sample name
27 | std::string ObjectTrackingSample::getName() const
28 | {
29 | return "Object tracking";
30 | }
31 |
32 | std::string ObjectTrackingSample::getSampleIcon() const
33 | {
34 | return "ObjectTrackingSampleIcon.png";
35 | }
36 |
37 | //! Returns a detailed sample description
38 | std::string ObjectTrackingSample::getDescription() const
39 | {
40 | return "Object tracking sample.";
41 | }
42 |
43 | //! Returns true if this sample requires setting a reference image for latter use
44 | bool ObjectTrackingSample::isReferenceFrameRequired() const
45 | {
46 | return true;
47 | }
48 |
49 | //! Sets the reference frame for latter processing
50 | void ObjectTrackingSample::setReferenceFrame(const cv::Mat& reference)
51 | {
52 | getGray(reference, imagePrev);
53 | computeObject = true;
54 | }
55 |
56 | // Reset object keypoints and descriptors
57 | void ObjectTrackingSample::resetReferenceFrame() const
58 | {
59 | trackObject = false;
60 | computeObject = false;
61 | }
62 |
63 | //! Processes a frame and returns output image
64 | bool ObjectTrackingSample::processFrame(const cv::Mat& inputFrame, cv::Mat& outputFrame)
65 | {
66 | // display the frame
67 | inputFrame.copyTo(outputFrame);
68 |
69 | // convert input frame to gray scale
70 | getGray(inputFrame, imageNext);
71 |
72 | // prepare the tracking class
73 | ObjectTrackingClass ot;
74 | ot.setMaxCorners(m_maxCorners);
75 |
76 | // begin tracking object
77 | if ( trackObject ) {
78 | ot.track(outputFrame,
79 | imagePrev,
80 | imageNext,
81 | pointsPrev,
82 | pointsNext,
83 | status,
84 | err);
85 |
86 | // check if the next points array isn't empty
87 | if ( pointsNext.empty() )
88 | trackObject = false;
89 | }
90 |
91 | // store the reference frame as the object to track
92 | if ( computeObject ) {
93 | ot.init(outputFrame, imagePrev, pointsNext);
94 | trackObject = true;
95 | computeObject = false;
96 | }
97 |
98 | // backup previous frame
99 | imageNext.copyTo(imagePrev);
100 |
101 | // backup points array
102 | std::swap(pointsNext, pointsPrev);
103 |
104 | return true;
105 | }
106 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/ObjectTrackingSample.h:
--------------------------------------------------------------------------------
1 | //
2 | // ObjectTrackingSample.h
3 | // OpenCV Tutorial
4 | //
5 | // Created by Anton Belodedenko on 26/07/2012.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #ifndef OpenCV_Tutorial_ObjectTrackingSample_h
10 | #define OpenCV_Tutorial_ObjectTrackingSample_h
11 |
12 | #include "SampleBase.h"
13 |
14 | class ObjectTrackingSample : public SampleBase
15 | {
16 | public:
17 | ObjectTrackingSample();
18 |
19 | //! Gets a sample name
20 | virtual std::string getName() const;
21 |
22 | virtual std::string getSampleIcon() const;
23 |
24 | //! Returns a detailed sample description
25 | virtual std::string getDescription() const;
26 |
27 | //! Returns true if this sample requires setting a reference image for latter use
28 | virtual bool isReferenceFrameRequired() const;
29 |
30 | //! Sets the reference frame for latter processing
31 | virtual void setReferenceFrame(const cv::Mat& reference);
32 |
33 | // clears reference frame parameters
34 | virtual void resetReferenceFrame() const;
35 |
36 | //! Processes a frame and returns output image
37 | virtual bool processFrame(const cv::Mat& inputFrame, cv::Mat& outputFrame);
38 |
39 | private:
40 | cv::Mat imageNext, imagePrev;
41 |
42 | std::vector status;
43 |
44 | std::vector err;
45 |
46 | std::string m_algorithmName;
47 |
48 | std::vector pointsPrev, pointsNext;
49 |
50 | // optical flow options
51 | int m_maxCorners;
52 | };
53 |
54 | #endif
55 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/ObjectTrackingSampleIcon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BloodAxe/OpenCV-Tutorial/cdf13b2703518b03d24bd8c9971631c226c8b8ce/OpenCV Tutorial/ObjectTrackingSampleIcon.png
--------------------------------------------------------------------------------
/OpenCV Tutorial/OpenCV Tutorial-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleDisplayName
8 | Machine Eye
9 | CFBundleExecutable
10 | ${EXECUTABLE_NAME}
11 | CFBundleIcons
12 |
13 | CFBundlePrimaryIcon
14 |
15 | CFBundleIconFiles
16 |
17 | Icon.png
18 | Icon@2x.png
19 | Icon-72.png
20 | Icon-72@2x.png
21 | Default.png
22 | Default@2x.png
23 | Default-Portrait~ipad.png
24 | Default-Portrait@2x~ipad.png
25 | Default-Landscape@2x~ipad.png
26 | Default-Landscape~ipad.png
27 |
28 | UIPrerenderedIcon
29 |
30 |
31 |
32 | CFBundleIdentifier
33 | $(PRODUCT_BUNDLE_IDENTIFIER)
34 | CFBundleInfoDictionaryVersion
35 | 6.0
36 | CFBundleName
37 | ${PRODUCT_NAME}
38 | CFBundlePackageType
39 | APPL
40 | CFBundleShortVersionString
41 | 1.0
42 | CFBundleSignature
43 | ????
44 | CFBundleVersion
45 | 1.0
46 | LSRequiresIPhoneOS
47 |
48 | UIMainStoryboardFile
49 | MainStoryboard_iPhone
50 | UIMainStoryboardFile~ipad
51 | MainStoryboard_iPad
52 | UIPrerenderedIcon
53 |
54 | UIRequiredDeviceCapabilities
55 |
56 | armv7
57 |
58 | UISupportedInterfaceOrientations
59 |
60 | UIInterfaceOrientationPortrait
61 | UIInterfaceOrientationLandscapeLeft
62 | UIInterfaceOrientationLandscapeRight
63 |
64 | UISupportedInterfaceOrientations~ipad
65 |
66 | UIInterfaceOrientationPortrait
67 | UIInterfaceOrientationPortraitUpsideDown
68 | UIInterfaceOrientationLandscapeLeft
69 | UIInterfaceOrientationLandscapeRight
70 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/OpenCV Tutorial-Prefix.pch:
--------------------------------------------------------------------------------
1 | //
2 | // Prefix header for all source files of the 'OpenCV Tutorial' target in the 'OpenCV Tutorial' project
3 | //
4 |
5 | #import
6 |
7 | #ifndef __IPHONE_5_0
8 | #warning "This project uses features only available in iOS SDK 5.0 and later."
9 | #endif
10 |
11 | #ifdef __cplusplus
12 | #include
13 | #endif
14 |
15 | #ifdef __OBJC__
16 | #import
17 | #import
18 | #import
19 | #endif
20 |
21 | #include "TargetConditionals.h"
22 |
23 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/OptionCell.h:
--------------------------------------------------------------------------------
1 | //
2 | // OptionCell.h
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 7/11/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "SampleOptions.h"
11 |
12 | @protocol OptionCellDelegate
13 |
14 | - (void) optionDidChanged:(SampleOption*) option;
15 |
16 | @end
17 |
18 |
19 | @interface OptionCell : UITableViewCell
20 |
21 | @property (readonly) float cellHeight;
22 | @property id delegate;
23 |
24 | @end
25 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/OptionCell.mm:
--------------------------------------------------------------------------------
1 | //
2 | // OptionCell.m
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 7/11/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #import "OptionCell.h"
10 |
11 | @implementation OptionCell
12 | @synthesize delegate;
13 | @synthesize cellHeight = _cellHeight;
14 |
15 | - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
16 | {
17 | self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
18 | if (self) {
19 | // Initialization code
20 | }
21 | return self;
22 | }
23 |
24 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated
25 | {
26 | [super setSelected:selected animated:animated];
27 |
28 | // Configure the view for the selected state
29 | }
30 |
31 | - (void) awakeFromNib
32 | {
33 | [super awakeFromNib];
34 | _cellHeight = self.bounds.size.height;
35 | }
36 |
37 |
38 | @end
39 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/OptionsTableView.h:
--------------------------------------------------------------------------------
1 | //
2 | // OptionsTableView.h
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 7/11/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "SampleFacade.h"
11 | #import "OptionCell.h"
12 |
13 | @interface OptionsTableView : UITableView
14 |
15 | - (id) initWithFrame:(CGRect)frame
16 | style:(UITableViewStyle)style
17 | sample:(SampleFacade*) sample
18 | notificationsDelegate:(id) delegate;
19 |
20 | @end
21 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/OptionsTableView.mm:
--------------------------------------------------------------------------------
1 | //
2 | // OptionsTableView.m
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 7/11/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #import "OptionsTableView.h"
10 | #import "SampleOptionsTableViewDelegate.h"
11 |
12 | @interface OptionsTableView ()
13 | @property (nonatomic, strong) SampleOptionsTableViewDelegate * optionsFacade;
14 | @end
15 |
16 | @implementation OptionsTableView
17 | @synthesize optionsFacade;
18 |
19 | - (id) initWithFrame:(CGRect)frame
20 | style:(UITableViewStyle)style
21 | sample:(SampleFacade*) sample
22 | notificationsDelegate:(id) delegate
23 | {
24 | if (self = [super initWithFrame:frame style:style])
25 | {
26 | [self registerNib:[UINib nibWithNibName:@"BooleanTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"BooleanTableViewCell"];
27 | [self registerNib:[UINib nibWithNibName:@"Int32TableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"Int32TableViewCell"];
28 | [self registerNib:[UINib nibWithNibName:@"FloatTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"FloatTableViewCell"];
29 | [self registerNib:[UINib nibWithNibName:@"EnumTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"EnumTableViewCell"];
30 | [self registerNib:[UINib nibWithNibName:@"DoubleTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"DoubleTableViewCell"];
31 |
32 | [self setAutoresizingMask: (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight) ];
33 | self.optionsFacade = [[SampleOptionsTableViewDelegate alloc] initWithSample:sample notificationsDelegate:delegate];
34 | self.delegate = self.optionsFacade;
35 | self.dataSource = self.optionsFacade;
36 | }
37 |
38 | return self;
39 | }
40 |
41 | @end
42 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/ROFSample.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // ROFSample.cpp
3 | // OpenCV Tutorial
4 | //
5 | // Created by Emmanuel d'Angelo on 20.07.12.
6 | // Copyright (c) 2012 EPFL/STI/IEL/LTS2. All rights reserved.
7 | //
8 |
9 | #include
10 | #include
11 | #include "totalvariation.h"
12 | #include "ROFSample.h"
13 |
14 | //! Init and create options
15 | ROFSample::ROFSample() : m_iterations(10), m_lambdaExponent(0), m_lambda(1.0)
16 | {
17 | registerOption("Iterations", "", &m_iterations, 1, 100);
18 | registerOption("Data weight exponent", "", &m_lambdaExponent, -4, 4);
19 | registerOption("Process color", "", &m_processColor);
20 | }
21 |
22 | //! Gets a sample name
23 | std::string ROFSample::getName() const
24 | {
25 | return "Rudin-Osher-Fatemi (TV)";
26 | }
27 |
28 | //! Returns a detailed sample description
29 | std::string ROFSample::getDescription() const
30 | {
31 | return "The Rudin-Osher-Fatemi functional aims at minimizing the Total Variation of an image. It is an anisotropic diffusion algorithm, where (unlike heat diffusion) grey levels hardly diffuse through image edges, hence preserving piecewise flat areas and avoiding undesired blur.\nThe ROF functional is solved here using the FISTA fast algorithm by Beck and Teboulle (2009).";
32 | }
33 |
34 | std::string ROFSample::getSampleIcon() const
35 | {
36 | return "ROFSampleIcon.png";
37 | }
38 |
39 | //! Processes a frame and returns output image
40 | bool ROFSample::processFrame(const cv::Mat& inputFrame, cv::Mat& outputFrame)
41 | {
42 | m_lambda = std::pow(10.0, m_lambdaExponent);
43 |
44 | std::vector inChannels;
45 | if (m_processColor)
46 | cv::split(inputFrame, inChannels);
47 | else {
48 | inChannels.resize(1);
49 | getGray(inputFrame, inChannels[0]);
50 | }
51 |
52 | std::vector outChannels(inChannels.size());
53 | cv::Mat tmp32f_in, tmp32f_out;
54 |
55 | for (int i = 0; i < MIN(3, inChannels.size()); ++i) {
56 | if (inChannels[i].type() != CV_32F)
57 | inChannels[i].convertTo(tmp32f_in, CV_32F, 1.0/255.0);
58 | else
59 | tmp32f_in = inChannels[i];
60 |
61 | tvdn_fista(tmp32f_in, m_lambda, m_iterations, tmp32f_out);
62 | tmp32f_out.convertTo(outChannels[i], CV_8U, 255.0);
63 | }
64 |
65 | if (m_processColor) {
66 | outChannels[3] = inChannels[3];
67 | cv::merge(outChannels, outputFrame);
68 | }
69 | else cv::cvtColor(outChannels[0], outputFrame, cv::COLOR_GRAY2BGRA);
70 |
71 | return true;
72 | }
--------------------------------------------------------------------------------
/OpenCV Tutorial/ROFSample.h:
--------------------------------------------------------------------------------
1 | //
2 | // ROFSample.h
3 | // OpenCV Tutorial
4 | //
5 | // Created by Emmanuel d'Angelo on 20.07.12.
6 | // Copyright (c) 2012 EPFL/STI/IEL/LTS2. All rights reserved.
7 | //
8 |
9 | #ifndef OpenCV_Tutorial_ROFSample_h
10 | #define OpenCV_Tutorial_ROFSample_h
11 |
12 | #include "SampleBase.h"
13 |
14 | class ROFSample : public SampleBase
15 | {
16 | public:
17 | ROFSample();
18 |
19 | //! Gets a sample name
20 | virtual std::string getName() const;
21 |
22 | virtual std::string getSampleIcon() const;
23 |
24 | //! Returns a detailed sample description
25 | virtual std::string getDescription() const;
26 |
27 | //! Processes a frame and returns output image
28 | virtual bool processFrame(const cv::Mat& inputFrame, cv::Mat& outputFrame);
29 |
30 | private:
31 | cv::Mat grayImage;
32 |
33 | // Diffusion options
34 | float m_lambda;
35 | int m_iterations;
36 | int m_lambdaExponent;
37 | bool m_processColor;
38 | };
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/ROFSampleIcon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BloodAxe/OpenCV-Tutorial/cdf13b2703518b03d24bd8c9971631c226c8b8ce/OpenCV Tutorial/ROFSampleIcon.png
--------------------------------------------------------------------------------
/OpenCV Tutorial/SampleBase.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // SampleBase.cpp
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 6/23/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #include "SampleBase.h"
10 | #include
11 | #include "cvneon.h"
12 |
13 | std::string SampleBase::getUserFriendlyName() const
14 | {
15 | return getName();
16 | }
17 |
18 | std::string SampleBase::getSampleIcon() const
19 | {
20 | return "";
21 | }
22 |
23 | const SampleBase::OptionsMap& SampleBase::getOptions() const
24 | {
25 | return m_optionsWithSections;
26 | }
27 |
28 | void SampleBase::registerOption(std::string name, std::string section, bool * value)
29 | {
30 | SampleOption * opt = new BooleanOption(name, section, value);
31 | m_optionsWithSections[section].push_back(opt);
32 | }
33 |
34 | void SampleBase::registerOption(std::string name, std::string section, int * value, int min, int max)
35 | {
36 | SampleOption * opt = new Int32Option(name, section, value, min, max);
37 | m_optionsWithSections[section].push_back(opt);
38 |
39 | *value = std::max(min, std::max(min, *value));
40 | }
41 |
42 | void SampleBase::registerOption(std::string name, std::string section, float * value, float min, float max)
43 | {
44 | SampleOption * opt = new FloatOption(name, section, value, min, max);
45 | m_optionsWithSections[section].push_back(opt);
46 |
47 | *value = std::max(min, std::max(min, *value));
48 | }
49 |
50 | void SampleBase::registerOption(std::string name, std::string section, double * value, double min, double max)
51 | {
52 | SampleOption * opt = new DoubleOption(name, section, value, min, max);
53 | m_optionsWithSections[section].push_back(opt);
54 |
55 | *value = std::max(min, std::max(min, *value));
56 | }
57 |
58 | void SampleBase::registerOption(std::string name, std::string section, std::string* value, std::vector stringEnums, int defaultValue)
59 | {
60 | SampleOption * opt = new StringEnumOption(name, section, value, stringEnums, defaultValue);
61 | m_optionsWithSections[section].push_back(opt);
62 |
63 | *value = stringEnums[defaultValue]; // Assign default value just in case
64 | }
65 |
66 |
67 | bool SampleBase::hasIcon() const
68 | {
69 | return false == getSampleIcon().empty();
70 | }
71 |
72 |
73 |
74 | void SampleBase::getGray(const cv::Mat& input, cv::Mat& gray)
75 | {
76 | const int numChannes = input.channels();
77 |
78 | if (numChannes == 4)
79 | {
80 | #if TARGET_IPHONE_SIMULATOR
81 | cv::cvtColor(input, gray, cv::COLOR_BGRA2GRAY);
82 | #else
83 | cv::neon_cvtColorBGRA2GRAY(input, gray);
84 | #endif
85 |
86 | }
87 | else if (numChannes == 3)
88 | {
89 | cv::cvtColor(input, gray, cv::COLOR_BGR2GRAY);
90 | }
91 | else if (numChannes == 1)
92 | {
93 | gray = input;
94 | }
95 | }
96 |
97 | //! Returns true if this sample requires setting a reference image for latter use
98 | bool SampleBase::isReferenceFrameRequired() const
99 | {
100 | return false;
101 | }
102 |
103 | //! Sets the reference frame for latter processing
104 | void SampleBase::setReferenceFrame(const cv::Mat& reference)
105 | {
106 | // Does nothing. Override this method if you need to
107 | }
108 |
109 | // Resets the reference frame
110 | void SampleBase::resetReferenceFrame() const
111 | {
112 | // Does nothing. Override this method if you need to
113 | }
114 |
--------------------------------------------------------------------------------
/OpenCV Tutorial/SampleBase.h:
--------------------------------------------------------------------------------
1 | //
2 | // SampleBase.h
3 | // OpenCV Tutorial
4 | //
5 | // Created by BloodAxe on 6/23/12.
6 | // Copyright (c) 2012 computer-vision-talks.com. All rights reserved.
7 | //
8 |
9 | #ifndef OpenCV_Tutorial_SampleBase_h
10 | #define OpenCV_Tutorial_SampleBase_h
11 |
12 | #include "SampleOptions.h"
13 | #include
14 | #include