【问题标题】:How to develop a Face recognition iPhone app? [closed]如何开发人脸识别 iPhone 应用程序? [关闭]
【发布时间】:2012-05-16 19:48:20
【问题描述】:

我正在尝试开发用于人脸识别/检测的 iPhone。在我的应用程序中,我想让我的 iPhone 相机应该自动对焦和自动捕捉。

如何通过 iPhone 应用识别人脸?

可以在我们的 iPhone 应用程序中自动对焦面部并自动捕捉。如果可能的话,任何人都可以帮忙吗?我只想要有关此的任何建议/想法和教程。

你能帮帮我吗?提前致谢。

【问题讨论】:

  • 使用 Quartz Core 框架的类 CAAnimation。

标签: iphone ios camera face-recognition autofocus


【解决方案1】:

Core Image 有一个新的 CIFaceDetector 来实时检测人脸;您可以从这些示例开始进行概述:
SquareCam
iOS Facial Recognition
Easy Face detection with Core Image

【讨论】:

    【解决方案2】:

    检查此代码。您必须导入以下内容:- CoreImage/CoreImage.h CoreImage/CoreImage.h 之后使用代码:-

    -(void)markFaces:(UIImageView *)facePicture
    {
    // draw a CI image with the previously loaded face detection picture
    CIImage* image = [CIImage imageWithCGImage:facePicture.image.CGImage];
    
    // create a face detector - since speed is not an issue we'll use a high accuracy
    // detector
    CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace 
                                              context:nil options:[NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy]];
    
    // create an array containing all the detected faces from the detector    
    NSArray* features = [detector featuresInImage:image];
    
    // we'll iterate through every detected face.  CIFaceFeature provides us
    // with the width for the entire face, and the coordinates of each eye
    // and the mouth if detected.  Also provided are BOOL's for the eye's and
    // mouth so we can check if they already exist.
    for(CIFaceFeature* faceFeature in features)
    {
        // get the width of the face
        CGFloat faceWidth = faceFeature.bounds.size.width;
    
        // create a UIView using the bounds of the face
        UIView* faceView = [[UIView alloc] initWithFrame:faceFeature.bounds];
    
        // add a border around the newly created UIView
        faceView.layer.borderWidth = 1;
        faceView.layer.borderColor = [[UIColor redColor] CGColor];
    
        // add the new view to create a box around the face
        [self.window addSubview:faceView];
    
        if(faceFeature.hasLeftEyePosition)
        {
            // create a UIView with a size based on the width of the face
            UIView* leftEyeView = [[UIView alloc] initWithFrame:CGRectMake(faceFeature.leftEyePosition.x-faceWidth*0.15, faceFeature.leftEyePosition.y-faceWidth*0.15, faceWidth*0.3, faceWidth*0.3)];
            // change the background color of the eye view
            [leftEyeView setBackgroundColor:[[UIColor blueColor] colorWithAlphaComponent:0.3]];
            // set the position of the leftEyeView based on the face
            [leftEyeView setCenter:faceFeature.leftEyePosition];
            // round the corners
            leftEyeView.layer.cornerRadius = faceWidth*0.15;
            // add the view to the window
            [self.window addSubview:leftEyeView];
        }
    
        if(faceFeature.hasRightEyePosition)
        {
            // create a UIView with a size based on the width of the face
            UIView* leftEye = [[UIView alloc] initWithFrame:CGRectMake(faceFeature.rightEyePosition.x-faceWidth*0.15, faceFeature.rightEyePosition.y-faceWidth*0.15, faceWidth*0.3, faceWidth*0.3)];
            // change the background color of the eye view
            [leftEye setBackgroundColor:[[UIColor blueColor] colorWithAlphaComponent:0.3]];
            // set the position of the rightEyeView based on the face
            [leftEye setCenter:faceFeature.rightEyePosition];
            // round the corners
            leftEye.layer.cornerRadius = faceWidth*0.15;
            // add the new view to the window
            [self.window addSubview:leftEye];
        }
    
        if(faceFeature.hasMouthPosition)
        {
            // create a UIView with a size based on the width of the face
            UIView* mouth = [[UIView alloc] initWithFrame:CGRectMake(faceFeature.mouthPosition.x-faceWidth*0.2, faceFeature.mouthPosition.y-faceWidth*0.2, faceWidth*0.4, faceWidth*0.4)];
            // change the background color for the mouth to green
            [mouth setBackgroundColor:[[UIColor greenColor] colorWithAlphaComponent:0.3]];
            // set the position of the mouthView based on the face
            [mouth setCenter:faceFeature.mouthPosition];
            // round the corners
            mouth.layer.cornerRadius = faceWidth*0.2;
            // add the new view to the window
            [self.window addSubview:mouth];
        }
    }
    }
    
    -(void)faceDetector
    {
    // Load the picture for face detection
    UIImageView* image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"facedetectionpic.jpg"]];
    
    // Draw the face detection image
    [self.window addSubview:image];
    
    // Execute the method used to markFaces in background
    [self performSelectorInBackground:@selector(markFaces:) withObject:image];
    
    // flip image on y-axis to match coordinate system used by core image
    [image setTransform:CGAffineTransformMakeScale(1, -1)];
    
    // flip the entire window to make everything right side up
    [self.window setTransform:CGAffineTransformMakeScale(1, -1)];
    }
    
    
     - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    [self faceDetector]; // execute the faceDetector code
    
    return YES;
    }
    

    希望对你有帮助谢谢:)

    【讨论】:

    • 我想补充一点,这在 iOS >5.0 中可用
    • 请注意:这不是人脸识别,而是人脸检测
    • 这是用于在相机模式下检测人脸吗?
    猜你喜欢
    • 2015-07-06
    • 2011-07-21
    • 2011-10-13
    • 2010-10-31
    • 2015-06-14
    • 1970-01-01
    • 2012-05-03
    • 2011-10-12
    相关资源
    最近更新 更多