iOS Face Detection Issue

前端 未结 4 1162
囚心锁ツ
囚心锁ツ 2021-02-08 10:43

I am trying to use CoreImage\'s face detection in iOS 5 but it is not detecting anything. I am trying to detect faces in an image that was just captured by the camera using thi

4条回答
  •  囚心锁ツ
    2021-02-08 11:14

    Try following. Assuming that you load photo in the image variable:

    NSDictionary *options = [NSDictionary dictionaryWithObject: CIDetectorAccuracyLow forKey: CIDetectorAccuracy];
                CIDetector  *detector = [CIDetector detectorOfType: CIDetectorTypeFace context: nil options: options];
    
            CIImage *ciImage = [CIImage imageWithCGImage: [image CGImage]];
            NSNumber *orientation = [NSNumber numberWithInt:[image imageOrientation]+1];
            NSDictionary *fOptions = [NSDictionary dictionaryWithObject:orientation forKey: CIDetectorImageOrientation];
                NSArray *features = [detector featuresInImage:ciImage options:fOptions];
                for (CIFaceFeature *f in features) {
    
                    NSLog(@"left eye found: %@", (f. hasLeftEyePosition ? @"YES" : @"NO"));
    
                    NSLog(@"right eye found: %@", (f. hasRightEyePosition ? @"YES" : @"NO"));
    
                    NSLog(@"mouth found: %@", (f. hasMouthPosition ? @"YES" : @"NO"));
    
                    if(f.hasLeftEyePosition)
    
                        NSLog(@"left eye position x = %f , y = %f", f.leftEyePosition.x, f.leftEyePosition.y);
    
                    if(f.hasRightEyePosition)
    
                        NSLog(@"right eye position x = %f , y = %f", f.rightEyePosition.x, f.rightEyePosition.y);
    
                    if(f.hasMouthPosition)
    
                        NSLog(@"mouth position x = %f , y = %f", f.mouthPosition.x, f.mouthPosition.y);
    
                }
    

提交回复
热议问题