ios - objective-C : No Matter what I do CIDetector is always nil
<p><p>试图通过 Apple 的人脸检测 API 获得一个简单的概念证明。我看过其他几个例子,包括 Apple 的 SquareCam,还有这个
<a href="https://github.com/jeroentrappers/FaceDetectionPOC" rel="noreferrer noopener nofollow">https://github.com/jeroentrappers/FaceDetectionPOC</a> </p>
<p>基于这些,我似乎在遵循正确的模式来运行 API,但我被卡住了。无论我做什么,我的人脸检测器的 CIDetector 总是为零!!!</p>
<p>我将非常感谢任何帮助、线索 - 提示 - 建议!</p>
<pre><code>-(void)initCamera{
session = [init];
AVCaptureDevice *device;
/*
if(){
device = ;
}else{
device = ;
}*/
device = ;
isUsingFrontFacingCamera = YES;
NSError *error = nil;
AVCaptureDeviceInput *input = ;
if(input && ){
;
}else{
NSLog(@"Error %@", error);
//make this Dlog...
}
videoDataOutput = [init];
NSDictionary *rgbOutputSettings = [NSDictionary dictionaryWithObject:
forKey:(id)kCVPixelBufferPixelFormatTypeKey];
;
;
videoDataOutputQueue = dispatch_queue_create("VideoDataOutputQueue", DISPATCH_QUEUE_SERIAL);
;
[setEnabled:YES];
if () {
;
}
;
;
}
-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection{
CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CFDictionaryRef attachments = CMCopyDictionaryOfAttachments(kCFAllocatorDefault, sampleBuffer, kCMAttachmentMode_ShouldPropagate);
CIImage *ciImage = [ initWithCVPixelBuffer:pixelBuffer options:(__bridge NSDictionary *)attachments];
if(attachments){
CFRelease(attachments);
}
UIDeviceOrientation curDeviceOrientation = [ orientation];
NSDictionary *imageOptions = @{CIDetectorImageOrientation: };
NSDictionary *detectorOptions = @{CIDetectorAccuracy: CIDetectorAccuracyLow};
CIDetector *faceDetector = ;
NSArray *faceFeatures = ;
if(>0){
NSLog(@"GOT a face!");
NSLog(@"%@", faceFeatures);
}
dispatch_async(dispatch_get_main_queue(), ^(void) {
//NSLog(@"updating main thread");
});
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><pre><code>CIDetector *smileDetector = [CIDetector detectorOfType:CIDetectorTypeFace
context:context
options:@{CIDetectorTracking: @YES,
CIDetectorAccuracy: CIDetectorAccuracyLow}];
NSArray *features = ;
if (( > 0) && (((CIFaceFeature *)features).hasSmile)) {
UIImageWriteToSavedPhotosAlbum(image, self, @selector(didFinishWritingImage), features);
} else {
self.label.text = @"Say Cheese!"
}
</code></pre></p>
<p style="font-size: 20px;">关于ios -objective-C: No Matter what I do CIDetector is always nil,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/19055760/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/19055760/
</a>
</p>
页:
[1]