系統(tǒng)人臉識(shí)別:解決系統(tǒng)人臉識(shí)別得到的圖片方向問(wèn)題

1、最后獲得的圖像反向轉(zhuǎn)換
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、如果圖像一開(kāi)始就不是正向的
/**
  *   問(wèn)題來(lái)自 UIImage 的取向和 CIDetectorImageOrientation 之間的區(qū)別。從 iOS 的文檔:
     CIDetectorImageOrientation

     要檢測(cè)密鑰被用來(lái)指定圖像的顯示方向的功能。此密鑰是一個(gè) NSNumber 對(duì)象具有相同的值定義的 TIFF 和 EXIF 規(guī)格 ;值的范圍可以從 1 到 8。值指定原點(diǎn) (0,0) 的圖像所在的位置。如果不存在,默認(rèn)值是 1,這意味著圖像的原點(diǎn)是左上角。每個(gè)值所指定的圖像來(lái)源的詳細(xì)信息,請(qǐng)參閱 kCGImagePropertyOrientation。

     可用在 iOS 5.0 和更高版本。

     在 CIDetector.h 中聲明。
     
     所以現(xiàn)在的問(wèn)題是這些兩個(gè)方向之間的轉(zhuǎn)換,在這里是我的代碼中的所作所為、 我測(cè)試和它為所有方向工作:
  *
  */

    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]}];
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • exprot命令 模塊功能主要由兩個(gè)命令構(gòu)成:export和import。export命令用于規(guī)定模塊的對(duì)外接口,...
    梵仇不是大俠閱讀 1,334評(píng)論 0 0
  • 童話劇在下午一點(diǎn)舉行了,序幕開(kāi)始啦!郭宇桐演的多羅西真好!仙女???♀?可真美!像公主一樣。就是沒(méi)有感情,要是有的話...
    張煜梒閱讀 229評(píng)論 0 0
  • 很高興能夠參加達(dá)人躍遷訓(xùn)練營(yíng),雖然在群里互動(dòng)不多,但是一個(gè)星期下來(lái)卻收獲滿滿。 聽(tīng)了6場(chǎng)有價(jià)值的分享: 水清亦有魚(yú)...
    文ww文閱讀 302評(píng)論 0 1
  • 曼羨莊嚴(yán)菩薩體,輕盈靜定悟真虛。 修來(lái)虔敬歸心處,奧妙無(wú)窮法相怡。
    不惑而歌閱讀 816評(píng)論 22 28

友情鏈接更多精彩內(nèi)容