visageSDK
VisageFeaturesDetectorWrapper.mm
1 #include <cv.h>
2 #import "VisageFeaturesDetectorWrapper.h"
3 #import "Utilities.h"
4 #import "Common.h"
5 #import "VisageDrawing.h"
6 #import "ConversionFunctions.h"
7 #define MAX_SIZE 768
8 
9 using namespace VisageSDK;
10 
11 @implementation VisageFeaturesDetectorWrapper
12 
13 - (void)initDetector
14 {
15  NSLog(@"init detector");
16 
17  //initialize licensing
18  //example how to initialize license key
19  //initializeLicenseManager("license-key-filename.vlc");
20 
21  visageFeaturesDetector = new VisageFeaturesDetector("Face Detector.cfg");
22  visageFeaturesDetector->Initialize();
23 }
24 
25 - (UIImage*)drawFeatures:(UIImage *)image
26 {
27  // if detector not initialized return the input image
28  if (visageFeaturesDetector == NULL)
29  return image;
30 
31  // convert input UIImage to IplImage
32  IplImage* input = IplImageFromUIImage(image, 4);
33 
34  // create the output image by copying the input image
35  IplImage* output = cvCreateImage(cvGetSize(input), input->depth, input->nChannels);
36  cvCopyImage(input, output);
37 
38  // resize input image
39  float scale = (float)MAX_SIZE / MAX(input->width, input->height);
40  IplImage* resizedInput = cvCreateImage(cvSize(input->width * scale, input->height * scale), input->depth, input->nChannels);
41  cvResize(input, resizedInput);
42 
43  // detect features
44  int maxFaces = 100;
45  FaceData* data = new FaceData[maxFaces];
46  int faces = -1;
47  faces = visageFeaturesDetector->detectFacialFeatures((VsImage*)resizedInput, data, maxFaces);
48 
49  // draw features into the output image
50  if(faces > 0)
51  {
52  for(int i = 0; i < faces; i++)
53  VisageDrawing::drawResults((VsImage*)resizedInput, &data[i]);
54  }
55 
56  //draw logo
57  if(logo != NULL)
58  VisageDrawing::drawLogo((VsImage*)resizedInput, (VsImage*)logo);
59 
60  // convert the output IplImage to UIImage
61  UIImage* returnImage = UIImageFromIplImage(resizedInput);
62 
63  // release the input and output IplImages
64  cvReleaseImage(&input);
65  cvReleaseImage(&resizedInput);
66  cvReleaseImage(&output);
67 
68  delete[] data;
69  // return
70  return returnImage;
71 }
72 
73 @end
Faces and facial features detector implementation.
Implements simple high-level Objective-C interface around VisageSDK::VisageFeaturesDetector functiona...
void initDetector()
Method for initializing the detector.
Namespace.
Definition: ios_header.h:1
Face data structure, used as container for all face tracking and detection results.
Definition: FaceData.h:259
Image store container.