下面的方法来自《 Professional iOS Augmented Reality book (Apress) 》一书的github存储库。
在基于整体的示例中没有任何代码UIViewController
处理清理。此处调用的 CoreImage 人脸检测例程可能需要几秒钟才能完成。
如果用户导致这个 viewController 消失了怎么办?我知道 ^block 由队列保留,这是将消息发送到 nil (当人脸检测例程返回时)实际上是一种好处的情况吗?
- (IBAction)detectFacialFeatures:(id)sender {
self.detectingView.hidden = NO;
self.scrollView.scrollEnabled = NO;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
CIImage *image = [[CIImage alloc] initWithImage:[FACE_IMAGES objectAtIndex:self.currentIndex]];
NSString *accuracy = self.useHighAccuracy ? CIDetectorAccuracyHigh : CIDetectorAccuracyLow;
NSDictionary *options = [NSDictionary dictionaryWithObject:accuracy forKey:CIDetectorAccuracy];
CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeFace context:nil options:options];
NSArray *features = [detector featuresInImage:image];
dispatch_async(dispatch_get_main_queue(), ^{
[self drawImageAnnotatedWithFeatures:features];
});
});
}