visageSDK
VisageTrackerViewController.m
1 #import "VisageTrackerViewController.h"
2 #import "MobileCoreServices/UTCoreTypes.h"
3 #import "CustomGLView.h"
4 #import "TrackerWrapper.h"
5 
6 @implementation VisageTrackerViewController
7 
8 @synthesize trackImage;
9 @synthesize resultsDisplayTimer;
10 @synthesize glView;
11 @synthesize fpsLabel;
12 @synthesize statusLabel;
13 @synthesize infoLabel;
14 @synthesize trackerToolbar;
15 @synthesize imgPicker;
16 @synthesize popover;
17 @synthesize tracker;
18 
19 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
20 - (void)viewDidLoad {
21 
22  [super viewDidLoad];
23 
24  self.imgPicker = [[UIImagePickerController alloc] init];
25  self.imgPicker.delegate = self;
26  self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
27 
28  self.imgPicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
29 
30  self.tracker = [[TrackerWrapper alloc] init];
31  [self.tracker initTracker:glView withInformer:self.createInformer];
32 }
33 
34 -(IBAction)trackVideoAction:(id)sender {
35 #if TARGET_IPHONE_SIMULATOR
36  [self.tracker startTrackingFromVideo:nil];
37 #else
38  if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
39  self.popover = [[UIPopoverController alloc] initWithContentViewController:self.imgPicker];
40  [self.popover presentPopoverFromRect:CGRectMake(0.0, 0.0, 400.0, 400.0) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
41  } else {
42  [self presentViewController:self.imgPicker animated:YES completion:nil];
43  }
44 #endif
45 }
46 
47 -(IBAction)trackImageAction:(id)sender {
48  [self.tracker startTrackingFromImage];
49 }
50 
51 -(IBAction)trackStopAction:(id)sender {
52  [self.tracker stopTracker];
53 }
54 
55 -(IBAction)trackCameraAction:(id)sender {
56  [self.tracker startTrackingFromCam];
57 }
58 
59 -(IBAction)trackQuitAction:(id)sender {
60  exit(0);
61 }
62 
63 -(void) imagePickerController: (UIImagePickerController *) picker
64 didFinishPickingMediaWithInfo: (NSDictionary *) info
65 {
66  NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
67 
68  NSString *moviePath = nil;
69 
70  if (CFStringCompare ((__bridge CFStringRef) mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo)
71  {
72  moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
73  }
74 
75  NSString* tmpDir = NSTemporaryDirectory();
76  NSString* finalPath = [tmpDir stringByAppendingString:[moviePath lastPathComponent]];
77 
78  NSError* error = nil;
79  if ([[NSFileManager defaultManager] isReadableFileAtPath:moviePath])
80  {
81  [[NSFileManager defaultManager] copyItemAtPath:moviePath toPath:finalPath error:&error];
82  }
83  if (error)
84  {
85  NSLog(@"ERROR. Failed to copy movie file to temporary directory.");
86  }
87 
88  [self dismissViewControllerAnimated:YES completion:nil];
89 
90  if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
91  [popover dismissPopoverAnimated:YES];
92  }
93 
94  if ([[NSFileManager defaultManager] isReadableFileAtPath:finalPath])
95  {
96  // if moviePath is remains nil, a default video bundled with app will play (jam1.mp4)
97  [self.tracker startTrackingFromVideo:finalPath];
98  }
99  else
100  {
101  NSLog(@"ERROR. No file to open.");
102  }
103 }
104 
105 - (void)didReceiveMemoryWarning {
106  // Releases the view if it doesn't have a superview.
107  [super didReceiveMemoryWarning];
108 
109  // Release any cached data, images, etc. that aren't in use.
110 }
111 
112 - (void)viewDidUnload {
113  [super viewDidUnload];
114  // Release any retained subviews of the main view.
115  // e.g. self.myOutlet = nil;
116 }
117 
118 
119 - (void)dealloc {
120  [resultsDisplayTimer invalidate];
121 }
122 
124  Informer* informer = [Informer alloc];
125  informer.fpsLabel = self.fpsLabel;
126  informer.infoLabel = self.infoLabel;
127  informer.statusLabel = self.statusLabel;
128  return informer;
129 }
130 
131 
132 @end
UIPopoverController * popover
Popover for video picker.
Implements default view controller and GUI actions.
IBOutlet UILabel * fpsLabel
Label for FPS display.
Displays tracking information.
Informer * createInformer()
Method used for creating and initializing a new informer.
UILabel * fpsLabel
Label with fps information.
IBOutlet UILabel * statusLabel
Label for tracker status display.
Implements simple high-level Objective-C interface around VisageSDK::VisageTracker functionallity.
CustomGLView * glView
View for displaying tracking results frame and 3D face wireframe.
UIImagePickerController * imgPicker
Image picker for selectiong video file from album.
UILabel * statusLabel
Label with tracking status.
NSTimer * resultsDisplayTimer
Timer for periodically refreshing of the results display.
IBOutlet UILabel * infoLabel
Label for tracker information display.
UILabel * infoLabel
Label with tracking information.
TrackerWrapper * tracker
Wrapper class around C++ calls controlling the tracker.
IBOutlet UIToolbar * trackerToolbar
Toolbar for controlling the app.