// // MPTSmileController.m // // Created by Andrew Salamon on 9/25/06. // Copyright (c) 2006 Machine Perception Laboratory, // University of California San Diego. All rights reserved. // #import "MPTSmileController.h" #import #import #import @interface MPTSmileController(PrivateMethods) - (void)adjustViews; - (void)setViewRanges:(MPT_AUView *)aView; @end static const int AU = 101; @implementation MPTSmileController - (id)initWithBundle:(NSBundle *)_bundle { if( self = [super initWithBundle:_bundle] ) { smiles = new MPSmile; smiles->setPixelMax( 1.0 ); rotator = new MP_RotateFace( SMD_FACE_SIZE ); //rotator->setEyeLenRate( 0.48 ); patch = new RImage( SMD_FACE_SIZE, SMD_FACE_SIZE ); [self adjustViews]; } return self; } - (void)dealloc { delete smiles; delete rotator; delete patch; [super dealloc]; } - (id)copyWithZone:(NSZone *)zone { MPTSmileController *cp = [super copyWithZone:zone]; return cp; } - (void)makeThreadsafe { [super makeThreadsafe]; smiles = new MPSmile; smiles->setPixelMax( 1.0 ); rotator = new MP_RotateFace( SMD_FACE_SIZE ); //rotator->setEyeLenRate( 0.48 ); patch = new RImage( SMD_FACE_SIZE, SMD_FACE_SIZE ); } - (NSView *)prefPane { return nil; } - (void)adjustViews { NSEnumerator *viewEnum = [views objectEnumerator]; while( MPT_AUView *aView = [viewEnum nextObject] ) { [self setViewRanges:aView]; } } - (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.SmileDetector2"; } - (NSString *)localizedName { return NSLocalizedStringFromTableInBundle(@"Smile Detector", nil, [NSBundle bundleForClass:[self class]], @""); } - (NSString *)internalName { return @"smiles2"; } - (NSString *)step { return MPT_PluginStep_AfterFaces; } - (void)setView:(MPT_AUView *)newView forLabel:(NSString *)label { [super setView:newView forLabel:label]; [self setViewRanges:newView]; } - (void)setViewRanges:(MPT_AUView *)aView { [aView resetDynamicRange]; [aView setDefaultMin:-0.5]; [aView setDefaultMax:0.5]; } - (id)processFaces:(EyeFaceList &)faces fromEyefinder:(MPTSlidingWindow *)eyefinder withImage:(RImage &)pixels { NSLog( @"Deprecated method called in MPTSmileController." ); return NULL; } - (id)processFace:(ObjectWithFeatures &)face fromFeatureDetector:(FeatureDetector *)fd withImage:(RImage &)pixels { EyeFaceList faces; FDFaceObject tempFace; NSNumber *res = NULL; mp_FDEyes::FaceFromObject( tempFace, face ); faces.push_back( tempFace ); RImage *intImageTmp = fd->getIntegralPtr().get(); // to get intergral image pointer RIntegral *intImage = static_cast *>(intImageTmp); int err = smiles->findSmilesGivenEyes( pixels, faces, 1.0f, intImage ); if( SMD_NO_ERR == err ) { res = [NSNumber numberWithDouble:faces[0].activation]; } return res; } - (id)processFace:(FDFaceObject &)face withImage:(RImage &)pixels { EyeFaceList faces; NSNumber *res = NULL; faces.push_back( face ); int err = smiles->findSmilesGivenEyes( pixels, faces, 1.0f, NULL ); if( SMD_NO_ERR == err ) { res = [NSNumber numberWithDouble:faces[0].activation]; } return res; } - (void)processNoFace { // if( [self doFilters] ) // { // [filters filterValue:0.0 forAU:AU face:false]; // } } @end