NSScreencast Episode #96 Face Detection
顔認識 画像の目と口にポイントを描く、領域に四角を描く
座標が反対
- CoreImage
- @import CoreImage;
- viewDidLoad
- self.imageView.contentMode = UIViewContentModeScaleAspectFit;
- dispatch_async
- CIDetector detectorOfType:CIDetectorTypeFace
- options:@{ CIDetectorAccuracy : CIDetectorAccuracyHigh }
- NSArray *features = [detector featuresInImage:ciImage];
- CIDetector detectorOfType:CIDetectorTypeFace
- [CIImage imageWithCGImage:[self.imageView.image CGImage]];
- dispatch_async(dispatch_get_main_queue(), ^{
- if ([feature isKindOfClass:[CIFaceFeature class]]) {
- CIFaceFeature *faceFeature = (CIFaceFeature *)feature;
- [self.faces addObject:face];
- if ([feature isKindOfClass:[CIFaceFeature class]]) {
- dispatch_async(dispatch_get_main_queue(), ^{
- drawFaces
- calculate image scale
- CGFloat imageScale = fminf(self.imageView.bounds.size.width / imageSize.width,
- for (FaceView *face in self.faces) {
- calculate image scale
- willRotateToInterfaceOrientation
- face.hidden = YES;
- didRotateFromInterfaceOrientation
- [self drawFaces];
- FaceView
- drawRect
- CGRect faceRect = self.feature.bounds;
- CGContextScaleCTM(context, self.scale, self.scale);
- if ([self.feature hasLeftEyePosition]) {
- [self drawEyeAtPosition:self.feature.leftEyePosition inContext:context];
- if ([self.feature hasRightEyePosition]) {
- if ([self.feature hasMouthPosition]) {
- drawEyeAtPosition
- CGContextSaveGState(context);
- CGContextFillEllipseInRect(context, eyeRect);
- CGContextRestoreGState(context);
- drawMouthAtPosition
- 座標が逆
- origin - bottom left
- position = CGPointMake(position.x, self.imageSize.height - position.y);
- drawRect
- favorite guitarist
- David Jon Gilmour (Pink Floyd)
- Googleの画像検索 (URL) Google Images
Googleの画像から検索すごい