9

Click here to load reader

iOSで笑顔を認識する

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: iOSで笑顔を認識する

iOSで笑顔を認識する@koogawa

Page 2: iOSで笑顔を認識する

•小川航佑 Kosuke Ogawa • @koogawa • 趣味と仕事の両方でiOSアプリを開発

Page 3: iOSで笑顔を認識する

• CoreImageを使います • iOS 5から顔認識が使えるようになった • iOS 6から動物認識もできる • iOS 7から笑顔認識もできる

Page 4: iOSで笑顔を認識する

やりかた

Page 5: iOSで笑顔を認識する

精度を指定

• HighとLowを選べる • High:精度は高いが、パフォーマンスは悪い • Low:精度は低いが、パフォーマンスは良い

NSDictionary *options = [NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy];

Page 6: iOSで笑顔を認識する

顔認識用のインスタンス生成

•顔認識なのでCIDetectorTypeFaceを指定

• 今のところCIDetectorTypeFace以外は設定できない

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

Page 7: iOSで笑顔を認識する

UIImageをCIImageに変換

•検出はCIImageクラスでないとできない

•画像の向きに注意する(回転してると正しく認識できない)

CIImage *ciImage = [[CIImage alloc] initWithCGImage:originalImage.CGImage];

Page 8: iOSで笑顔を認識する

笑顔認識を有効にする

NSDictionary *options = @{ CIDetectorSmile: @(YES), };

Page 9: iOSで笑顔を認識する

顔認識実行

•認識できた顔の数だけ返ってくる • 笑っていると判定されるとhasSmileがYESになる

NSArray *features = [detector featuresInImage:image options:options]; for (CIFaceFeature *feature in features) { if (feature.hasSmile) { // 笑ってる! } }