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ù)。