系统人脸识别:解决系统人脸识别得到的图片方向问题

1、最后获得的图像反向转换
int height = CVPixelBufferGetHeight(pixelBuffer);
CGAffineTransform transform = CGAffineTransformMakeScale(1, -1);
transform = CGAffineTransformTranslate(transform, 0, -1 * height);
/* Do your face detection */
CGRect faceRect = CGRectApplyAffineTransform(feature.bounds, transform);
CGPoint mouthPoint = CGPointApplyAffineTransform(feature.mouthPosition, transform);
2、如果图像一开始就不是正向的
/**
  *   问题来自 UIImage 的取向和 CIDetectorImageOrientation 之间的区别。从 iOS 的文档:
     CIDetectorImageOrientation

     要检测密钥被用来指定图像的显示方向的功能。此密钥是一个 NSNumber 对象具有相同的值定义的 TIFF 和 EXIF 规格 ;值的范围可以从 1 到 8。值指定原点 (0,0) 的图像所在的位置。如果不存在,默认值是 1,这意味着图像的原点是左上角。每个值所指定的图像来源的详细信息,请参阅 kCGImagePropertyOrientation。

     可用在 iOS 5.0 和更高版本。

     在 CIDetector.h 中声明。
     
     所以现在的问题是这些两个方向之间的转换,在这里是我的代码中的所作所为、 我测试和它为所有方向工作:
  *
  */

    int exifOrientation;

    switch (image.imageOrientation) {

        case UIImageOrientationUp: {
  
            exifOrientation = 1;
            break; 
        }

        case UIImageOrientationDown: {
          
            exifOrientation = 3;
            break;
        }

        case UIImageOrientationLeft: {
          
            exifOrientation = 8;
            break;
        }

        case UIImageOrientationRight: {
          
            exifOrientation = 6;
            break;
        }

        case UIImageOrientationUpMirrored: {
         
            exifOrientation = 2;
            break;
        }

        case UIImageOrientationDownMirrored: {
          
            exifOrientation = 4;
            break;
        }

        case UIImageOrientationLeftMirrored: {
          
            exifOrientation = 5;
            break;
        }

        case UIImageOrientationRightMirrored: {
            
            exifOrientation = 7;
            break;
        }
    }

    NSDictionary *detectorOptions = @{ CIDetectorAccuracy : CIDetectorAccuracyHigh }; 
// TODO: read doc for more tuneups

    CIDetector *faceDetector = [CIDetector detectorOfType:CIDetectorTypeFace context:nil options:detectorOptions];

    NSArray *features = [faceDetector featuresInImage:[CIImage imageWithCGImage:image.CGImage]
                                              options:@{CIDetectorImageOrientation:[NSNumber 
                                                                                    numberWithInt:exifOrientation]}];
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • exprot命令 模块功能主要由两个命令构成:export和import。export命令用于规定模块的对外接口,...
    梵仇不是大侠阅读 1,293评论 0 0
  • 童话剧在下午一点举行了,序幕开始啦!郭宇桐演的多罗西真好!仙女🧚‍♀️可真美!像公主一样。就是没有感情,要是有的话...
    张煜梒阅读 228评论 0 0
  • 很高兴能够参加达人跃迁训练营,虽然在群里互动不多,但是一个星期下来却收获满满。 听了6场有价值的分享: 水清亦有鱼...
    文ww文阅读 300评论 0 1
  • 曼羡庄严菩萨体,轻盈静定悟真虚。 修来虔敬归心处,奥妙无穷法相怡。
    不惑而歌阅读 805评论 22 28

友情链接更多精彩内容