我試圖實現內置的iOS 5人臉檢測API。我正在使用UIImagePickerController
的實例來允許用戶拍照,然後我試圖使用CIDetector
來檢測面部特徵。不幸的是,featuresInImage
總是返回大小爲0CIDetector和UIImagePickerController
這裏的數組的代碼:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage* picture = [info objectForKey:UIImagePickerControllerOriginalImage];
NSNumber *orientation = [NSNumber numberWithInt:
[picture imageOrientation]];
NSDictionary *imageOptions =
[NSDictionary dictionaryWithObject:orientation
forKey:CIDetectorImageOrientation];
CIImage *ciimage = [CIImage imageWithCGImage:[picture CGImage]
options:imageOptions];
NSDictionary *detectorOptions =
[NSDictionary dictionaryWithObject:CIDetectorAccuracyLow
forKey:CIDetectorAccuracy];
CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeFace
context:nil
options:detectorOptions];
NSArray *features = [detector featuresInImage:ciimage];
NSLog(@"Feature size: %d", features.count);
}
這總是返回0的功能。但是,如果我使用內置於應用程序中的文件使用UIImage,則臉部檢測效果很好。
我正在使用此代碼Pragmatic Bookshelf article。
對於它的價值,我認爲錯誤是當我將UIImage從相機轉換爲CIImage時,但它可能是任何東西。
+1優秀的答案。 –
什麼是self.image.imageOrientation你能解釋一下嗎? –