Click here to load reader
Upload
kosuke-ogawa
View
8.951
Download
0
Embed Size (px)
DESCRIPTION
Citation preview
iOSで笑顔を認識する@koogawa
•小川航佑 Kosuke Ogawa • @koogawa • 趣味と仕事の両方でiOSアプリを開発
• CoreImageを使います • iOS 5から顔認識が使えるようになった • iOS 6から動物認識もできる • iOS 7から笑顔認識もできる
やりかた
精度を指定
• HighとLowを選べる • High:精度は高いが、パフォーマンスは悪い • Low:精度は低いが、パフォーマンスは良い
NSDictionary *options = [NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy];
顔認識用のインスタンス生成
•顔認識なのでCIDetectorTypeFaceを指定
• 今のところCIDetectorTypeFace以外は設定できない
CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeFace context:nil options:options];
UIImageをCIImageに変換
•検出はCIImageクラスでないとできない
•画像の向きに注意する(回転してると正しく認識できない)
CIImage *ciImage = [[CIImage alloc] initWithCGImage:originalImage.CGImage];
笑顔認識を有効にする
NSDictionary *options = @{ CIDetectorSmile: @(YES), };
顔認識実行
•認識できた顔の数だけ返ってくる • 笑っていると判定されるとhasSmileがYESになる
NSArray *features = [detector featuresInImage:image options:options]; for (CIFaceFeature *feature in features) { if (feature.hasSmile) { // 笑ってる! } }