Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 怎样才能把图像集中在脸上?_Ios_Objective C_Image_Uiimageview - Fatal编程技术网

Ios 怎样才能把图像集中在脸上?

Ios 怎样才能把图像集中在脸上?,ios,objective-c,image,uiimageview,Ios,Objective C,Image,Uiimageview,我想从图像中检测人脸并将其居中。我该怎么办? 我有一张这样的照片: 我只想显示脸部,如图所示: 这远远超出了单个问题的范围,但是,除非你自己编写人脸检测算法,否则我建议你使用苹果的原生类 示例代码: CIContext *context = [CIContext contextWithOptions:nil]; // 1 NSDictionary *opts = @{ CIDetectorAccuracy : CIDetectorAccuracyHigh

我想从图像中检测人脸并将其居中。我该怎么办? 我有一张这样的照片:

我只想显示脸部,如图所示:


这远远超出了单个问题的范围,但是,除非你自己编写人脸检测算法,否则我建议你使用苹果的原生类

示例代码:

CIContext *context = [CIContext contextWithOptions:nil];                    // 1

NSDictionary *opts = @{ CIDetectorAccuracy : CIDetectorAccuracyHigh };      // 2

CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeFace

                                          context:context

                                          options:opts];                    // 3



opts = @{ CIDetectorImageOrientation :

          [[myImage properties] valueForKey:kCGImagePropertyOrientation] }; // 4

NSArray *features = [detector featuresInImage:myImage options:opts];        // 5
1创建一个上下文;在本例中,是iOS的上下文。您可以使用处理图像中描述的任何上下文创建函数。)您还可以选择在创建检测器时提供nil而不是上下文。)

2创建选项字典以指定探测器的精度。您可以指定低精度或高精度。低精度(CIDetectorAccuracyLow)速度快;本例中显示的高精度是彻底的,但速度较慢

3为面创建检测器。您可以创建的唯一检测器类型是人脸检测器

4设置用于查找面的选项字典。让核心图像知道图像方向很重要,这样探测器就知道在哪里可以找到垂直面。大多数情况下,您将从图像本身读取图像方向,然后将该值提供给选项字典

5使用检测器查找图像中的特征。您提供的图像必须是CIImage对象。Core Image返回CIFeature对象的数组,每个对象表示图像中的一个面

面部特征包括:

left and right eye positions

mouth position

tracking ID and tracking frame count which Core Image uses to follow a face in a video segment
从CIDetector对象获取面特征数组后,可以在该数组中循环以检查每个面和面中每个特征的边界

for (CIFaceFeature *f in features)

{

    NSLog(NSStringFromRect(f.bounds));



    if (f.hasLeftEyePosition)

        NSLog("Left eye %g %g", f.leftEyePosition.x. f.leftEyePosition.y);



    if (f.hasRightEyePosition)

        NSLog("Right eye %g %g", f.rightEyePosition.x. f.rightEyePosition.y);



    if (f.hasmouthPosition)

        NSLog("Mouth %g %g", f.mouthPosition.x. f.mouthPosition.y);

}

检测到人脸后,可以使用标准UIKit/CoreImage类进行缩放和居中。

UiImage没有可见的@interface声明选择器“properties”@GabyFitcal CIImage类使用未声明的标识符“kCGImagePropertyOrientation”,如果您接受已发布的答案,您可能会得到更好的响应。除此之外,以这种简略的方式发布编译错误,没有上下文,并且期望人们帮助你的形式并不好。我只是复制了你的代码,我创建了这个CIImage:'CIImage*CIImage=[UIImage imagename:[NSString stringWithFormat:[self.picture objectAtIndex:indexath.row]].CIImage;'完成这行代码后:“opts=@{CIDetectorImageOrientation:[[ciImage properties]valueForKey:kCGImagePropertyOrientation]};”我得到了这个错误