问题描述
我正在使用OSX Mavericks上的一些面部检测代码,我试图利用CIDetector提供的多个静态函数中的新的(10.8)面部跟踪。
我有基本的面部检测工作正常,像这样:
- (void)captureOutput:(AVCaptureOutput * )captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection {
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CIImage * image = [CIImage imageWithCVImageBuffer:imageBuffer];
CIDetector * faceDetector = [CIDetector detectorOfType:CIDetectorTypeFace
context:nil
options:@ {CIDetectorAccuracy:CIDetectorAccuracyHigh,
CIDetectorTracking:@YES
}
NSArray * features = [faceDetector featuresInImage:image];
for(CIFaceFeature * feature in features){
if(feature.hasTrackingID){
NSLog(@tracking id:%@,@(feature.trackingID));
}
}
}
功能列表正确但是trackingID从来不似乎存在。
有谁得到这个工作在小牛?
我在这里看到过类似的问题()但我没有学到任何新的东西。
对于它值得它似乎在iOS上正常运行。
再次,答案证明是非常明显的:我不断地重新初始化CIDetector,这是坏的性能,也有复位其内部跟踪数据每帧的结果。因此,第一次检测到面部总是第一次检测到该特定CIDetector实例的面部。
此外,CIDetector在文档中警告: p>
这个类可以维护许多可能影响性能的状态变量,因此为了获得最佳性能,重用CIDetector实例而不是创建新的实例。,从。
I'm working on some face detection code on OSX Mavericks and I'm trying to take advantage of the newish (as of 10.8) face tracking across multiple stills functionality that CIDetector offers.
I have basic face detection working fine, like so:
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection {
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CIImage *image = [CIImage imageWithCVImageBuffer:imageBuffer];
CIDetector *faceDetector = [CIDetector detectorOfType:CIDetectorTypeFace
context:nil
options:@{ CIDetectorAccuracy : CIDetectorAccuracyHigh,
CIDetectorTracking : @YES
}];
NSArray *features = [faceDetector featuresInImage:image];
for ( CIFaceFeature *feature in features ) {
if (feature.hasTrackingID) {
NSLog(@"tracking id: %@", @(feature.trackingID));
}
}
}
The features list does get populated correctly but that trackingID never seems to be present.Has anyone gotten this working on Mavericks? It fails the same way on Mountain Lion.
I have seen a similar question here (CIFaceFeature trackingID is always coming same for multiple faces) but I didn't learn anything new there.
For what it's worth it does seem to function correctly on iOS.
I looked at this code again and the answer turned out to be pretty obvious: I was constantly re-initializing the CIDetector, which was bad for performance and also had the consequence of resetting its internal tracking data each frame. So the first time a face was detected was always the first time a face was detected for that particular CIDetector instance.
Also, CIDetector warns about this in the docs:
"This class can maintain many state variables that can impact performance. So for best performance, reuse CIDetector instances instead of creating new ones.", from https://developer.apple.com/library/mac/documentation/CoreImage/Reference/CIDetector_Ref/Reference/Reference.html.
这篇关于CIDetector trackingID从不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!