菜鸟教程小白 发表于 2022-12-12 14:58:47

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 &amp;&amp; ){
    ;
}else{
    NSLog(@&#34;Error %@&#34;, error);
    //make this Dlog...
}


videoDataOutput = [init];
NSDictionary *rgbOutputSettings = [NSDictionary dictionaryWithObject:
                                  forKey:(id)kCVPixelBufferPixelFormatTypeKey];
;
;

videoDataOutputQueue = dispatch_queue_create(&#34;VideoDataOutputQueue&#34;, 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(&gt;0){
    NSLog(@&#34;GOT a face!&#34;);
    NSLog(@&#34;%@&#34;, faceFeatures);

}


dispatch_async(dispatch_get_main_queue(), ^(void) {
    //NSLog(@&#34;updating main thread&#34;);
});


}
</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 (( &gt; 0) &amp;&amp; (((CIFaceFeature *)features).hasSmile)) {
    UIImageWriteToSavedPhotosAlbum(image, self, @selector(didFinishWritingImage), features);
} else {
    self.label.text = @&#34;Say Cheese!&#34;
}
</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]
查看完整版本: ios - objective-C : No Matter what I do CIDetector is always nil