1 #import "TrackerWrapper.h" 2 #import "UIDeviceHardware.h" 3 #import "visageVision.h" 4 #import "VideoGrabber.h" 5 #import "DemoFrameGrabber.h" 7 #import <mach/mach_time.h> 11 #include "Stopwatch.h" 18 @synthesize earsActivated;
22 @synthesize tapPositionx;
23 @synthesize tapPositiony;
24 @synthesize instructionsMessage;
26 const bool REALTIME_VIDEO =
true;
27 static CameraGrabber *cameraGrabber = 0;
29 static int *trackerStatus = TRACK_STAT_OFF;
30 const int MAX_FACES = 4;
31 bool isTracking=
false;
33 int currentChosenFace = -1;
34 int numTrackedFaces = 0;
35 int currentNumFaces = 0;
37 bool numFacesChanged =
false;
38 int analyserInitialized = 0;
39 static bool threadRunning =
false;
40 static NSCondition *waitHandle;
45 const NSString *preset;
55 BOOL fileExists =
false;
62 long startTrackTime = 0;
63 long endTrackTime = 0;
64 long elapsedTrackTime = 0;
65 mach_timebase_info_data_t timebaseInfo;
70 const int NUM_EMOTIONS = 7;
71 float emotion_prob_estimates[NUM_EMOTIONS] = {0.0f};
75 long durationTimeAnim = 1500;
79 bool animationEnabled[MAX_FACES] = {
false};
81 bool reverseAnim =
false;
83 - (long) getElapsedTimeInMs:(uint64_t)startTime :(uint64_t)endTime
85 uint64_t elapsedTime = endTime - startTime;
86 uint64_t elapsedTimeMilli = elapsedTime * timebaseInfo.numer / (timebaseInfo.denom * 1e6);
88 return elapsedTimeMilli;
91 void YUV_TO_RGB(
unsigned char* yuv,
unsigned char* buff,
int width,
int height);
92 void FaceAnalyserFilter(
FaceData& faceData,
int index);
94 NSString* resourcePath = 0;
99 return !(y=x>>8) ? x : (0xff ^ (y>>24));
103 int firstTrackerStatusOK()
106 for(
int i = 0; i<MAX_FACES; ++i)
108 if(trackerStatus[i] == TRACK_STAT_OK)
123 static int results[2];
125 for(
int i = 0; i<MAX_FACES; ++i)
127 if(trackerStatus[i] == TRACK_STAT_OK)
137 results[0] = trackIndex;
144 static bool getFeaturePoint(VsPoint &point,
FaceData* trackingData,
int group,
int index,
int width,
int height,
bool flipY =
false)
147 point.x = vsRound(fp.
pos[0] * width);
148 point.y = vsRound((flipY ? 1 - fp.
pos[1] : fp.
pos[1]) * height);
152 static float fpDistance(
const VsPoint* fp1,
const VsPoint* fp2)
154 return sqrt( pow((
float)(fp1->x - fp2->x), 2) + pow((
float)(fp1->y - fp2->y), 2) );
157 bool calculateBoundingBox(
int width,
int height,
FaceData* trackingData, VsRect* boundingBox,
bool flipY)
160 VsPoint leye1, leye2, reye1, reye2, nose1, nose2, mouth;
162 if(!(getFeaturePoint(leye1, trackingData, 3, 11, width, height, flipY) &&
163 getFeaturePoint(leye2, trackingData, 3, 7, width, height, flipY) &&
164 getFeaturePoint(reye1, trackingData, 3, 12, width, height, flipY) &&
165 getFeaturePoint(reye2, trackingData, 3, 8, width, height, flipY) &&
166 getFeaturePoint(nose1, trackingData, 9, 5, width, height, flipY) &&
167 getFeaturePoint(nose2, trackingData, 9, 4, width, height, flipY) &&
168 getFeaturePoint(mouth, trackingData, 8, 1, width, height, flipY)))
172 VsPoint leye = vsPoint(vsRound((leye1.x + leye2.x)/2.0f), vsRound((leye1.y + leye2.y)/2.0f));
173 VsPoint reye = vsPoint(vsRound((reye1.x + reye2.x)/2.0f), vsRound((reye1.y + reye2.y)/2.0f));
174 VsPoint nose = vsPoint(vsRound((nose1.x + nose2.x)/2.0f), vsRound((nose1.y + nose2.y)/2.0f));
175 VsPoint centerEyes = vsPoint(vsRound((leye.x + reye.x)/2.0f), vsRound((leye.y + reye.y)/2.0f));
177 if (centerEyes.y >= nose.y)
183 float distance = MAX(fpDistance(&leye, &mouth), MAX(fpDistance(&reye, &mouth), fpDistance(&leye, &reye)));
186 boundingBox->width = vsRound(distance * 1.8f);
187 boundingBox->height = vsRound(distance * 2.3f);
188 boundingBox->x = vsRound(nose.x * 0.8f + centerEyes.x * 0.2f - boundingBox->width / 2.0f);
189 boundingBox->y = vsRound(nose.y * 0.8f + centerEyes.y * 0.2f - boundingBox->height / 2.0f);
195 VsImage *CreateVsImageFromUIImage(UIImage *image,
int nChannels);
202 opQ = [[NSOperationQueue alloc] init];
203 mach_timebase_info(&timebaseInfo);
205 waitHandle = [NSCondition new];
206 threadRunning =
false;
212 if(self->m_informer == NULL)
213 self->m_informer = informer;
215 if(self->analyserInformer == NULL)
220 delete[] trackingData;
221 trackingData =
new FaceData[MAX_FACES];
228 if ([deviceType hasPrefix:
@"iPhone5"])
236 face =
new VsRect[MAX_FACES];
238 resourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/vfa"];
240 delete[] analysisData;
244 glWidth = glView.bounds.size.width;
245 glHeight = glView.bounds.size.height;
247 inGetTrackingResults =
false;
249 self->instructionsMessage =
false;
252 - (void)doAnalysis:(
int)faceIndex
262 analyser->analyseStream(frameRGB, trackingData[faceIndex], options, analysisData[faceIndex]);
265 - (void)resetAnalyserFilters:(
int)index
268 analyser->resetStreamAnalysis(index);
276 setDimensions(_rotated);
285 cameraGrabber = [[CameraGrabber alloc] initWithSessionPreset:preset UseFPS:cam_fps withDevice:_device];
286 [cameraGrabber startCapture: nil withCamera:_camera];
288 int pixelFormat = [cameraGrabber getPixelFormat];
289 int format = VISAGE_FRAMEGRABBER_FMT_LUMINANCE;
291 if (pixelFormat == 1)
292 format = VISAGE_FRAMEGRABBER_FMT_LUMINANCE;
294 format = VISAGE_FRAMEGRABBER_FMT_BGRA;
296 frameRGB = vsCreateImageHeader(vsSize(cam_width/2, cam_height/2), VS_DEPTH_8U, 3);
297 if (pixelFormat == 1)
298 frameDisplay = vsCreateImageHeader(vsSize(cam_width, cam_height), VS_DEPTH_8U, 3);
300 frameDisplay = vsCreateImageHeader(vsSize(cam_width, cam_height), VS_DEPTH_8U, 4);
303 for(
int fi=0; fi<MAX_FACES; fi++)
305 [
self resetAnalyserFilters:fi];
308 while(!currentTrackOperation.isCancelled)
311 uint64_t loopStart = mach_absolute_time();
314 setDimensions(_rotated);
315 CGImageRef displayImage;
316 CGImageRef trackImage;
317 CGImageRef analysisImage;
319 [cameraGrabber getTrackImage:&trackImage withDisplayImage:&displayImage isBGRA:NO withAnalyserImage:&analysisImage isDownscaled:YES];
321 if (trackImage == nil || displayImage == nil || analysisImage == nil)
324 CFDataRef trackImageDataProvider = CGDataProviderCopyData(CGImageGetDataProvider(trackImage));
325 UInt8* pixels = (UInt8*) CFDataGetBytePtr(trackImageDataProvider);
327 int width = (int)CGImageGetWidth(trackImage);
328 int height = (int)CGImageGetHeight(trackImage);
329 int widthStep = (int)CGImageGetBytesPerRow(trackImage);
331 uint64_t trackStart = mach_absolute_time();
333 trackerStatus = tracker->track(width, height, (const char *)pixels, trackingData, format, VISAGE_FRAMEGRABBER_ORIGIN_TL, widthStep, -1, MAX_FACES);
335 uint64_t trackEnd = mach_absolute_time();
339 CFDataRef analysisImageDataProvider = CGDataProviderCopyData(CGImageGetDataProvider(analysisImage));
340 UInt8* rgbPixels = (UInt8*) CFDataGetBytePtr(analysisImageDataProvider);
341 vsSetImageData(frameRGB, rgbPixels, (int)CGImageGetBytesPerRow(analysisImage));
343 videoAspect = frameRGB->width / (float)frameRGB->height;
346 winHeight = glWidth / videoAspect;
348 if(ageActivated || genderActivated || emotionsActivated)
350 facesInfo = getCount();
353 currentChosenFace = facesInfo[0];
354 currentNumFaces = facesInfo[1];
357 if(currentNumFaces > 1)
360 currentChosenFace = faceIndex;
363 if(currentNumFaces != numTrackedFaces)
365 numTrackedFaces = currentNumFaces;
368 currentChosenFace = firstTrackerStatusOK();
373 numFacesChanged = true;
374 self->instructionsMessage = true;
380 for(int i=0; i<MAX_FACES; i++)
383 if(trackerStatus[i] == TRACK_STAT_OK)
385 calculateBoundingBox(winWidth, winHeight, &trackingData[i], &face[i], false);
387 if(self->tapPositionx > (face[i].x) && self->tapPositionx < (face[i].x + face[i].width) &&
388 self->tapPositiony > (face[i].y) && self->tapPositiony < (face[i].y + face[i].height))
391 currentChosenFace = i;
394 self->instructionsMessage = false;
397 self->tapPositionx = -1;
398 self->tapPositiony = -1;
404 if(currentChosenFace != faceIndex)
406 faceIndex = currentChosenFace;
409 for(int fi=0; fi<MAX_FACES; fi++)
411 ResetWireframeAnimation(fi);
415 [self resetAnalyserFilters:fi];
421 if(currentNumFaces >= 1)
423 [self doAnalysis:faceIndex];
426 [self->analyserInformer updateAnalyserInformer:analysisData[faceIndex].emotionProbabilities.data() withAge:analysisData[faceIndex].age andGender:analysisData[faceIndex].gender andEmoState:emotionsActivated andAgeState:ageActivated andGenderState:genderActivated andMessage:instructionsMessage];
431 for(int fi=0; fi<MAX_FACES; fi++)
433 [self resetAnalyserFilters:fi];
436 [self->analyserInformer updateAnalyserInformer:NULL withAge:-1.0f andGender:-1 andEmoState:false andAgeState:false andGenderState:false andMessage:instructionsMessage];
440 CFDataRef displayImageDataProvider = CGDataProviderCopyData(CGImageGetDataProvider(displayImage));
441 UInt8* displayPixels = (UInt8*) CFDataGetBytePtr(displayImageDataProvider);
442 vsSetImageData(frameDisplay, displayPixels, (int)CGImageGetBytesPerRow(displayImage));
443 [self displayTrackingResults:trackerStatus Frame:frameDisplay Face:face];
445 CFRelease(displayImageDataProvider);
446 CGImageRelease(displayImage);
447 CFRelease(trackImageDataProvider);
448 CGImageRelease(trackImage);
449 CFRelease(analysisImageDataProvider);
450 CGImageRelease(analysisImage);
452 uint64_t loopEnd = mach_absolute_time();
456 if(trackerStatus[0] == TRACK_STAT_OFF)
463 vsReleaseImageHeader(&frameRGB);
464 vsReleaseImageHeader(&frameDisplay);
467 threadRunning =
false;
468 [waitHandle broadcast];
474 #if TARGET_IPHONE_SIMULATOR 475 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
476 message:@"No camera available on simulator."
478 cancelButtonTitle:@"OK"
479 otherButtonTitles:nil];
482 [opQ cancelAllOperations];
483 [opQ waitUntilAllOperationsAreFinished];
486 NSBlockOperation* trackOperation = [[NSBlockOperation alloc] init];
487 currentTrackOperation = trackOperation;
489 [trackOperation addExecutionBlock:^{
493 [opQ addOperation:trackOperation];
499 return ([[NSDate date] timeIntervalSince1970] * 1000);;
502 - (void)toggleEarsTracking:(
bool)enableEars
504 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
506 const std::string newCfg = (enableEars) ?
"vft/fm/jk_300_wEars.cfg" :
"vft/fm/jk_300.cfg";
507 const unsigned int newValue = (enableEars) ? 1 : 0;
512 sf[7] = (enableEars) ? 1.5f : -1.0f;
525 - (void)toggleRefineLandmarks:(
bool)enableRefineLandmarks
527 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
541 if (!analyserInitialized)
542 analyserInitialized = analyser->
init([resourcePath UTF8String]);
544 if (!analyserInitialized)
546 NSLog(
@"Analyser not initialized");
555 - (void)toggleIrisTracking:(
bool)enableIris
557 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
559 const unsigned int newValue = (enableIris) ? 3 : 0;
572 unsigned char* pixels = demoFrameGrabber->
GrabFrame(fg_pts);
578 frameBGRA = vsCreateImage(vsSize(demoFrameGrabber->width, demoFrameGrabber->height), VS_DEPTH_8U, 4);
579 frameRGB = vsCreateImage(vsSize(demoFrameGrabber->width, demoFrameGrabber->height), VS_DEPTH_8U, 3);
582 for(
int fi=0; fi<MAX_FACES; fi++)
584 [
self resetAnalyserFilters:fi];
587 while(!currentTrackOperation.isCancelled)
589 startTrackTime = [self getCurrentTimeMs];
590 trackerStatus = tracker->track(demoFrameGrabber->width, demoFrameGrabber->height, (const char*)pixels, trackingData, VISAGE_FRAMEGRABBER_FMT_RGBA, VISAGE_FRAMEGRABBER_ORIGIN_TL, 0, -1, MAX_FACES);
591 endTrackTime = [self getCurrentTimeMs];
592 elapsedTrackTime = endTrackTime - startTrackTime;
594 memcpy(frameBGRA->imageData, (char*) pixels, frameBGRA->imageSize);
595 vsCvtColor(frameBGRA, frameRGB, VS_BGRA2RGB);
597 if(ageActivated || genderActivated || emotionsActivated)
599 facesInfo = getCount();
602 currentChosenFace = facesInfo[0];
603 currentNumFaces = facesInfo[1];
606 if(currentNumFaces > 1)
609 currentChosenFace = faceIndex;
612 if(currentNumFaces != numTrackedFaces)
614 numTrackedFaces = currentNumFaces;
617 currentChosenFace = firstTrackerStatusOK();
622 numFacesChanged = true;
623 self->instructionsMessage = true;
629 for(int i=0; i<MAX_FACES; i++)
632 if(trackerStatus[i] == TRACK_STAT_OK)
634 calculateBoundingBox(winWidth, winHeight, &trackingData[i], &face[i], false);
636 if(self->tapPositionx > (face[i].x) && self->tapPositionx < (face[i].x + face[i].width) &&
637 self->tapPositiony > (face[i].y) && self->tapPositiony < (face[i].y + face[i].height))
640 currentChosenFace = i;
643 self->instructionsMessage = false;
646 self->tapPositionx = -1;
647 self->tapPositiony = -1;
653 if(currentChosenFace != faceIndex)
655 faceIndex = currentChosenFace;
658 for(int fi=0; fi<MAX_FACES; fi++)
660 ResetWireframeAnimation(fi);
664 [self resetAnalyserFilters:fi];
670 if(currentNumFaces >= 1)
672 [self doAnalysis:faceIndex];
675 [self->analyserInformer updateAnalyserInformer:analysisData[faceIndex].emotionProbabilities.data() withAge:analysisData[faceIndex].age andGender:analysisData[faceIndex].gender andEmoState:emotionsActivated andAgeState:ageActivated andGenderState:genderActivated andMessage:instructionsMessage];
681 for(int fi=0; fi<MAX_FACES; fi++)
683 [self resetAnalyserFilters:fi];
686 [self->analyserInformer updateAnalyserInformer:NULL withAge:-1.0f andGender:-1 andEmoState:false andAgeState:false andGenderState:false andMessage:instructionsMessage];
690 [
self displayTrackingResults:trackerStatus Frame:frameRGB Face:face];
693 if(trackerStatus[0] == TRACK_STAT_OFF)
699 delete demoFrameGrabber;
700 demoFrameGrabber = 0;
701 if (frameBGRA) vsReleaseImage(&frameBGRA);
702 if (frameRGB) vsReleaseImage(&frameRGB);
705 threadRunning =
false;
706 [waitHandle broadcast];
710 - (void) trackingVideoOperation:(NSString*) videoURL
712 if ([videoURL isEqual:nil] || [videoURL length] == 0)
718 videoGrabber = [[VideoGrabber alloc] init];
719 if (videoGrabber == NULL)
721 NSLog(
@"Could not initialize videoGrabber");
725 [videoGrabber startGrabbing:videoURL];
728 float fps = [videoGrabber framerate];
729 frameTime = 1000/fps;
732 for(
int fi=0; fi<MAX_FACES; fi++)
734 [
self resetAnalyserFilters:fi];
739 double currentTime = sw.getTime();
741 while(!currentTrackOperation.isCancelled)
743 frameBGRA = [videoGrabber getNextMovieFrame:NO];
744 if (frameBGRA == NULL)
749 frameRGB = vsCreateImage(vsSize(frameBGRA->
width, frameBGRA->
height), VS_DEPTH_8U, 3);
750 vsCvtColor(frameBGRA, frameRGB, VS_BGRA2RGB);
752 startTrackTime = [
self getCurrentTimeMs];
753 trackerStatus = tracker->
track(frameBGRA->
width, frameBGRA->
height, frameBGRA->
imageData, trackingData, VISAGE_FRAMEGRABBER_FMT_BGRA, VISAGE_FRAMEGRABBER_ORIGIN_TL, frameBGRA->
widthStep, -1, MAX_FACES);
754 endTrackTime = [
self getCurrentTimeMs];
755 elapsedTrackTime = endTrackTime - startTrackTime;
759 facesInfo = getCount();
762 currentChosenFace = facesInfo[0];
763 currentNumFaces = facesInfo[1];
766 if(currentNumFaces > 1)
769 currentChosenFace = faceIndex;
772 if(currentNumFaces != numTrackedFaces)
774 numTrackedFaces = currentNumFaces;
777 currentChosenFace = firstTrackerStatusOK();
782 numFacesChanged =
true;
783 self->instructionsMessage =
true;
789 for(
int i=0; i<MAX_FACES; i++)
792 if(trackerStatus[i] == TRACK_STAT_OK)
794 calculateBoundingBox(winWidth, winHeight, &trackingData[i], &face[i],
false);
796 if(self->tapPositionx > (face[i].x) && self->tapPositionx < (face[i].x + face[i].width) &&
797 self->tapPositiony > (face[i].y) && self->tapPositiony < (face[i].y + face[i].height))
800 currentChosenFace = i;
803 self->instructionsMessage =
false;
806 self->tapPositionx = -1;
807 self->tapPositiony = -1;
813 if(currentChosenFace != faceIndex)
815 faceIndex = currentChosenFace;
818 for(
int fi=0; fi<MAX_FACES; fi++)
820 ResetWireframeAnimation(fi);
824 [
self resetAnalyserFilters:fi];
830 if(currentNumFaces >= 1)
832 [
self doAnalysis:faceIndex];
835 [
self->analyserInformer updateAnalyserInformer:analysisData[faceIndex].emotionProbabilities.data() withAge:analysisData[faceIndex].age andGender:analysisData[faceIndex].gender andEmoState:emotionsActivated andAgeState:ageActivated andGenderState:genderActivated andMessage:instructionsMessage];
841 for(
int fi=0; fi<MAX_FACES; fi++)
843 [
self resetAnalyserFilters:fi];
846 [
self->analyserInformer updateAnalyserInformer:NULL withAge:-1.0f andGender:-1 andEmoState:false andAgeState:false andGenderState:false andMessage:instructionsMessage];
850 [
self displayTrackingResults:trackerStatus Frame:frameRGB Face:face];
852 if (frameRGB) vsReleaseImage(&frameRGB);
855 if(trackerStatus[0] == TRACK_STAT_OFF)
860 while (REALTIME_VIDEO && currentTime > frameTime * (frameCount + 1))
863 currentTime = sw.getTime();
864 [videoGrabber getNextMovieFrame:YES];
867 while (REALTIME_VIDEO && currentTime < frameTime * (frameCount - 5))
869 NSTimeInterval waitTime = (double)1/1000;
870 [NSThread sleepForTimeInterval:waitTime];
871 currentTime = sw.getTime();
876 if (frameRGB) vsReleaseImage(&frameRGB);
877 if (demoFrameGrabber)
delete demoFrameGrabber;
878 demoFrameGrabber = 0;
881 threadRunning =
false;
882 [waitHandle broadcast];
888 [opQ cancelAllOperations];
889 [opQ waitUntilAllOperationsAreFinished];
891 NSBlockOperation* trackOperation = [[NSBlockOperation alloc] init];
892 currentTrackOperation = trackOperation;
894 [trackOperation addExecutionBlock:^{
895 [
self trackingImageOperation:image];
898 [opQ addOperation:trackOperation];
901 - (void)startTrackingFromVideo:(NSString *) video
903 [opQ cancelAllOperations];
904 [opQ waitUntilAllOperationsAreFinished];
906 NSBlockOperation* trackOperation = [[NSBlockOperation alloc] init];
907 currentTrackOperation = trackOperation;
909 [trackOperation addExecutionBlock:^{
910 [
self trackingVideoOperation:video];
913 [opQ addOperation:trackOperation];
918 [currentTrackOperation cancel];
921 - (void)dummyThread:(
id)object
927 - (BOOL)startMultithread
929 [NSThread detachNewThreadSelector:@selector(dummyThread:) toTarget:self withObject: nil];
930 return [NSThread isMultiThreaded];
933 #include <mach/mach_time.h> 935 #define MEASURE_FRAMES 10 936 uint64_t last_times[MEASURE_FRAMES];
941 - (void)displayTrackingResults:(
int*)trackerStatus Frame:(
VsImage*)frame Face:(VsRect*)rect
943 inGetTrackingResults =
true;
945 int pts = (int)trackingData[0].timeStamp;
947 if (last_pts == pts) {
948 inGetTrackingResults =
false;
954 mach_timebase_info_data_t timeBaseInfo;
955 mach_timebase_info(&timeBaseInfo);
958 uint64_t currentTime = mach_absolute_time() * timeBaseInfo.numer / (timeBaseInfo.denom * 1e6);
962 for(
int i=0;i<10;i++)
966 if(framecount == MEASURE_FRAMES) framecount = 0;
967 last_times[framecount] = currentTime;
975 winHeight =
glWidth / videoAspect;
978 VisageRendering::DisplayResults(&trackingData[0], trackerStatus[0], winWidth, winHeight, frame ,
activeDisplay + DISPLAY_FRAME + DISPLAY_POINT_QUALITY);
980 for (
int i = 1; i < MAX_FACES; i++)
981 VisageRendering::DisplayResults(&trackingData[i], trackerStatus[i], winWidth, winHeight, frame,
activeDisplay + DISPLAY_POINT_QUALITY);
985 AnimateWireframe(trackingData, faceIndex, 0.2f, 0.6f);
989 const char *trackingStatusString;
990 switch (trackerStatus [0]) {
992 trackingStatusString =
"OFF";
995 trackingStatusString =
"OK";
997 case TRACK_STAT_RECOVERING:
998 trackingStatusString =
"RECOVERING";
1000 case TRACK_STAT_INIT:
1001 trackingStatusString =
"INITIALIZING";
1004 trackingStatusString =
"N/A";
1012 if (trackerStatus[0] == TRACK_STAT_OK)
1014 for(
int i=0;i<3;i++) {
1015 r[i] = trackingData[0].
faceRotation[i] * 180.0f / 3.14159f;
1020 NSString* fps = [NSString stringWithFormat:@"%4.1f FPS (track %ld ms) \n", trackingData[0].frameRate, elapsedTrackTime];
1021 NSString* info = [NSString stringWithFormat:@"Head position %+5.1f %+5.1f %+5.1f | Rotation (deg) %+5.1f %+5.1f %+5.1f",t[0],t[1],t[2],r[0],r[1],r[2]];
1022 NSString* status = [NSString stringWithFormat:@"Status: %s", trackingStatusString];
1024 [
self->m_informer showTrackingFps:fps Info:info andStatus:status];
1026 inGetTrackingResults =
false;
1029 void YUV_TO_RGB(
unsigned char* yuv,
unsigned char* buff,
int width,
int height)
1031 const int frameSize = width * height;
1038 unsigned char* rgb = buff;
1040 for (
int i = 0, ci = ii; i < height; ++i, ci += di)
1042 for (
int j = 0, cj = ij; j < width; ++j, cj += dj)
1044 int y = (0xff & ((int) yuv[ci * width + cj]));
1045 int u = (0xff & ((int) yuv[frameSize + (ci >> 1) * width + (cj & ~1) + 0]));
1046 int v = (0xff & ((int) yuv[frameSize + (ci >> 1) * width + (cj & ~1) + 1]));
1048 y = y < 16 ? 16 : y;
1050 int a0 = 1192 * (y - 16);
1051 int a1 = 1634 * (v - 128);
1052 int a2 = 832 * (v - 128);
1053 int a3 = 400 * (u - 128);
1054 int a4 = 2066 * (u - 128);
1056 int r = (a0 + a1) >> 10;
1057 int g = (a0 - a2 - a3) >> 10;
1058 int b = (a0 + a4) >> 10;
1067 void getOrientation()
1069 UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
1070 if (orientation == UIInterfaceOrientationPortrait)
1072 else if (orientation == UIInterfaceOrientationLandscapeLeft)
1074 else if (orientation == UIInterfaceOrientationLandscapeRight)
1080 void setDimensions(
int orientation)
1084 if (orientation == 0 || orientation == 2)
1089 preset = AVCaptureSessionPreset640x480;
1096 preset = AVCaptureSessionPreset640x480;
1100 if ([deviceType hasPrefix:
@"iPhone3"])
1102 if (orientation == 0 || orientation == 2)
1107 preset = AVCaptureSessionPresetLow;
1114 preset = AVCaptureSessionPresetLow;
1119 bool withinConstraints(
FaceData *faceData)
1125 double headPitchCompensatedRad = faceRotAppX;
1126 double headYawCompensatedRad = faceRotAppY;
1127 double headRollRad = faceRotAppZ;
1129 double headPitchCompensatedDeg = V_RAD2DEG(headPitchCompensatedRad);
1130 double headYawCompensatedDeg = V_RAD2DEG(headYawCompensatedRad);
1131 double headRollDeg = V_RAD2DEG(headRollRad);
1133 const double CONSTRAINT_ANGLE = 40;
1135 if (abs(headPitchCompensatedDeg) > CONSTRAINT_ANGLE ||
1136 abs(headYawCompensatedDeg) > CONSTRAINT_ANGLE ||
1137 abs(headRollDeg) > CONSTRAINT_ANGLE ||
1146 float DeltaStep(
int ageFilterFramesReached)
1148 if (ageFilterFramesReached == 0)
1156 void AnimateWireframe(
FaceData *faceData,
int index,
float alphaMin,
float alphaMax)
1158 if(!animationEnabled[index])
1161 startTimeAnim = timer.getTime();
1162 animationEnabled[index] =
true;
1165 if(animationEnabled[index])
1167 currTimeAnim = timer.getTime();
1168 weight = (float)(currTimeAnim - startTimeAnim)/ (float)durationTimeAnim;
1170 float alpha = (alphaMax - alphaMin)/2 * sin(2*M_PI * weight - M_PI/2) + (alphaMax + alphaMin)/2;
1171 VisageRendering::DisplayWireFrame(&faceData[index], winWidth, winHeight, alpha);
1175 animationEnabled[index] =
false;
1180 void ResetWireframeAnimation(
int index)
1182 animationEnabled[index] =
false;
int height
Image height in pixels.
VisageTracker is a face tracker capable of tracking the head pose, facial features and gaze for multi...
VisageFaceAnalyser contains face analysis algorithms capable of estimating age, gender and emotion fr...
int glHeight
Size of the OpenGL view.
void setTrackerConfiguration(const char *trackerConfigFile, bool au_fitting_disabled=false, bool mesh_fitting_disabled=false)
Sets tracking configuration.
NSString * platform()
Returns exact device name.
const FeaturePoint & getFP(int group, int n) const
Get a feature point by its group and index.
bool setSmoothingFactors(const VsCfgArr< float > &smoothing_factors)
Sets the values of the smoothing_factors parameter.
Analysis data structure, used as a container for all face analysis results.
VisageConfiguration is a class used to change, apply, load and save configuration parameters used by ...
void startTrackingFromImage()
Method for starting tracking from an image.
int faceScale
Scale of facial bounding box expressed in pixels.
void setOpenGLContext()
Method for setting the OpenGL context.
enable age estimation or check whether age data files have been properly initialized
bool setRefineEars(unsigned int refine_ears)
Sets the value of the refine_ears parameter.
char * imageData
Pointer to aligned image data.
Implements simple high-level Objective-C interface around VisageSDK::VisageTracker functionallity.
void startTrackingFromCam()
Method for starting tracking from a camera.
bool setRefineLandmarks(unsigned int refine_landmarks)
Sets the value of the refine_landmarks parameter.
void swapOpenGLBuffers()
Method for swapping OpenGL buffers.
void trackingImageOperation()
Method for loading picture and performing face tracking on the given frame.
enable emotion estimation or check whether emotion data files have been properly initialized
void stopTracker()
Method for stoping the tracker.
Controls OpenGL view used for tracking output.
This is a templated structure that can store an array of values of varying types, including:
bool ageActivated
Boolean variable that states if age analyser is turned on or off.
void trackingCamOperation()
Method for initializing the camera and performing face tracking on the given frame.
VsCfgArr< float > getSmoothingFactors() const
Returns the value of the smoothing_factors parameter.
int width
Image width in pixels.
virtual int * track(int frameWidth, int frameHeight, const char *p_imageData, FaceData *facedata, int format=VISAGE_FRAMEGRABBER_FMT_RGB, int origin=VISAGE_FRAMEGRABBER_ORIGIN_TL, int widthStep=0, long timeStamp=-1, int maxFaces=1)
Performs face tracking (one or more faces) in the given image and returns tracking results and status...
int defined
Set with regards to the 3D model used.
bool setAuFittingModelConfiguration(std::string au_fitting_model_configuration)
Sets the value of the au_fitting_model_configuration parameter.
bool setMeshFittingModelConfiguration(std::string mesh_fitting_model_configuration)
Sets the value of the mesh_fitting_model_configuration parameter.
bool emotionsActivated
Boolean variable that states if emotions analyser is turned on or off.
bool setProcessEyes(unsigned int process_eyes)
Sets the value of the process_eyes parameter.
float faceTranslation[3]
Translation of the head from the camera.
int init(const char *dataPath)
Initialise VisageFaceAnalyser.
Implements methods that are used to determine specific version of device software is running on.
unsigned char * GrabFrame(long &timeStamp)
VisageTracker calls this function periodically to get the new frame to process.
AnalyserInformer * analyserInformer
Informer used for displaying analyser information.
VisageConfiguration getTrackerConfiguration()
Returns tracking configuration.
enable gender estimation or check whether gender data files have been properly initialized
float faceRotation[3]
Rotation of the head.
int activeDisplay
Current drawing options variable.
float faceRotationApparent[3]
Rotation of the head from the camera viewpoint This variable is set only while tracker is tracking (T...
Face data structure, used as container for all face tracking and detection results.
bool genderActivated
Boolean variable that states if gender analyser is turned on or off.
long getCurrentTimeMs()
Function used for measuring tracker speed.
int widthStep
Size of aligned image row in bytes.
bool setPoseFittingModelConfiguration(std::string pose_fitting_model_configuration)
Sets the value of the pose_fitting_model_configuration parameter.
Implements a simple frame grabber that serves a single image to the tracker in order to demonstrate t...
FDP * featurePoints2D
Facial feature points (2D coordinates).
int glWidth
Size of the OpenGL view.