iOS 人脸识别拾遗一 坐标转换 截取

// 得到图片的尺寸
               CIImage *faceImage = [CIImage imageWithCGImage:image.CGImage];
               
               CGSize inputImageSize = [faceImage extent].size;
               //将image沿y轴对称 这个不能少 少了取到的image为空
                CGAffineTransform transform = CGAffineTransformScale(CGAffineTransformIdentity, 1, -1);
               //将图片上移
               transform = CGAffineTransformTranslate(transform, 0, -inputImageSize.height);
               
            //取第一张脸去截取
            CIFaceFeature *faceFeature = [features firstObject];
            //获取人脸的frame
            CGRect faceViewBounds = CGRectApplyAffineTransform(faceFeature.bounds, transform);
          
           UIImage *smallImage = [VideoCaptureView ct_imageFromImage:image inRect:faceViewBounds];

附 裁剪image

+ (UIImage *)imageFromImage:(UIImage *)image inRect:(CGRect)rect{
     

    //截取部分图片并生成新图片
    CGImageRef sourceImageRef = [image CGImage];
    CGImageRef newImageRef = CGImageCreateWithImageInRect(sourceImageRef, rect);
    UIImage *newImage = [UIImage imageWithCGImage:newImageRef scale:1 orientation:image.imageOrientation];
    return newImage;
}

你可能感兴趣的:(oc)