// // MPTBlinkController.m // BlinkDetector // // Created by Andrew Salamon on 9/25/06. // Copyright 2006 __MyCompanyName__. All rights reserved. // #import "MPTBlinkController.h" @implementation MPTBlinkController - (id)initWithBundle:(NSBundle *)_bundle { if( self = [super initWithBundle:_bundle] ) { blinks = new MPBlink; blinks->setPixelMax( 1.0 ); } return self; } - (void)dealloc { delete blinks; [super dealloc]; } - (id)copyWithZone:(NSZone *)zone { id cp = [super copyWithZone:zone]; return cp; } - (void)makeThreadsafe { [super makeThreadsafe]; blinks = new MPBlink; blinks->setPixelMax( 1.0 ); } - (BOOL)loadLabels { labels = [[NSArray alloc] initWithObjects:[self localizedName], nil]; return YES; } - (NSString *)pluginID { NSString *ident = [super pluginID]; if( [ident length] > 0 ) return ident; return @"edu.ucsd.mplab.plugins.BlinkDetector"; } - (NSString *)localizedName { return NSLocalizedStringFromTableInBundle(@"(AU 45) Blink", nil, [NSBundle bundleForClass:[self class]], @""); } - (NSString *)internalName { return @"blinks"; } - (NSString *)step { return MPT_PluginStep_AfterFaces; } - (id)processFaces:(EyeFaceList &)faces fromEyefinder:(MPTSlidingWindow *)eyefinder withImage:(RImage &)pixels { RIntegral* pfIntegral = static_cast*>(eyefinder->getIntegralPtr().get()); NSNumber *res = NULL; if( SMD_NO_ERR == blinks->findBlinksGivenEyes( pixels, faces, pfIntegral ) ) { // Try inverting the results so it is a blink detector rather than an eye open detector //faces.begin()->activation = 1 / faces.begin()->activation; //faces.begin()->activation = 1 / faces.begin()->activation * -1; faces.begin()->activation *= -1; res = [NSNumber numberWithDouble:faces.begin()->activation]; } return res; } - (id)processFace:(FaceObject &)face withImage:(RImage &)pixels { return [NSNumber numberWithDouble:blinks->findBlinksFromFace( pixels, face )]; } - (void)processNoFace { } @end