首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >面对面图像比较

面对面图像比较
EN

Stack Overflow用户
提问于 2016-01-08 21:54:31
回答 1查看 308关注 0票数 1

我正在尝试制作一个人脸识别应用程序,一旦它检测到这个人的脸,它就会识别他。我已经完成了人脸检测部分,但我找不到一种方法来将人脸与应用程序中存储的相册中的照片进行比较。

人脸检测代码如下:

代码语言:javascript
复制
-(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

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];


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.view 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.view 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.view 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.view addSubview:mouth];

    }

}

}



-(void)faceDetector

{

// Load the picture for face detection

UIImageView* image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"testpicture.png"]];



// Draw the face detection image

[self.view 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.view setTransform:CGAffineTransformMakeScale(1, -1)];





}
EN

回答 1

Stack Overflow用户

发布于 2016-01-08 21:57:47

文档中的

核心图像可以分析和发现图像中的人脸。它执行人脸检测,而不是识别。人脸检测是对包含人脸特征的矩形的识别,而人脸识别是对特定人脸(约翰、玛丽等)的识别。Core Image检测到人脸后,可以提供有关人脸特征的信息,例如眼睛和嘴巴位置。它还可以跟踪视频中识别出的人脸的位置。

不幸的是,苹果还没有提供识别这张脸的api。您可以查看third party libraries.

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34678730

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档