0

For a professional project, I need to detect a person from his picture. So I can get CIFaceFeature for each face.

Then I would get unique values ​​for each face to the identifiers.

I looked on the side of TrackingID, but this one is always equal to 0. I also made ​​some calculations with the position of the eyes and mouth but it depant the distance of the face compared to the iPhone.

   -(void)detectForFacesInUIImage:(UIImage *)facePicture
  {
    CIImage* image = [CIImage imageWithCGImage:facePicture.CGImage];

   //    CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace
   //  context:nil options:[NSDictionary dictionaryWithObject:CIDetectorAccuracyLow forKey:CIDetectorAccuracy]];

       NSArray* features = [detector featuresInImage:image];

  for(CIFaceFeature* faceObject in features)
 {
    CGRect modifiedFaceBounds = faceObject.bounds;
    modifiedFaceBounds.origin.y = facePicture.size.height-faceObject.bounds.size.height-faceObject.bounds.origin.y;

    CGPoint c = [faceObject leftEyePosition];
    NSLog(@"left eye position %f %f = %f", c.x, c.y, c.y - c.x);

    c = [faceObject rightEyePosition];
    NSLog(@"right eye position %f %f = %f", c.x, c.y, c.y - c.x);

    c = [faceObject mouthPosition];
    NSLog(@"mouth eye position %f %f = %f", c.x, c.y, c.y - c.x);

    CGRect d = [faceObject bounds];
    NSLog(@"bounds eye position %f %f", d.size.width, d.size.height);

    NSLog(@"trackID = %d", faceObject.trackingID);
    NSLog(@"\n\n");
    [self addSubViewWithFrame:modifiedFaceBounds];

    if(faceObject.hasLeftEyePosition)
    {

        CGRect leftEye = CGRectMake(faceObject.leftEyePosition.x,(facePicture.size.height-faceObject.leftEyePosition.y), 10, 10);
        [self addSubViewWithFrame:leftEye];
    }

    if(faceObject.hasRightEyePosition)
    {

        CGRect rightEye = CGRectMake(faceObject.rightEyePosition.x, (facePicture.size.height-faceObject.rightEyePosition.y), 10, 10);
        [self addSubViewWithFrame:rightEye];

    }
    if(faceObject.hasMouthPosition)
    {
        CGRect  mouth = CGRectMake(faceObject.mouthPosition.x,facePicture.size.height-faceObject.mouthPosition.y,10, 10);
        [self addSubViewWithFrame:mouth];

        }
      }
    }
Bhavesh Odedra
  • 10,990
  • 12
  • 33
  • 58
user2724028
  • 594
  • 2
  • 8
  • 19
  • This guy had a similar issue and fixed it. http://stackoverflow.com/questions/19983741/cidetector-trackingid-never-present – sangony Feb 03 '14 at 20:58
  • Thank you so much for your answer, i will check it. I hope it will works fine. – user2724028 Feb 04 '14 at 08:24
  • i tried, and it doesn't work. I don't understand why, it's always equal 0. – user2724028 Feb 04 '14 at 19:54
  • Or maybe there is a algorithme for recognise a face, with the location of eyes and/or the mouth. – user2724028 Feb 04 '14 at 20:56
  • OK, take a look at this other post showing how to set up face detection. http://stackoverflow.com/questions/13475387/proper-usage-of-cidetectortracking – sangony Feb 04 '14 at 22:04
  • Also take a look at this tutorial and compare your code. http://maniacdev.com/2011/11/tutorial-easy-face-detection-with-core-image-in-ios-5 – sangony Feb 04 '14 at 22:16

0 Answers0