Ios 带有AVCaptureOutput的CIDetector
我试图通过AVFoundation和CIDetector从视频输入中逐帧检测微笑。在captureOutput中使用CIDetector时,其准确性非常不一致。同样的面部表情可以从微笑快速反弹到不微笑,这取决于光线、与相机的距离以及图片中的其他面部。有没有一种方法可以让CIDetector在不太慢的情况下不那么紧张Ios 带有AVCaptureOutput的CIDetector,ios,objective-c,avfoundation,Ios,Objective C,Avfoundation,我试图通过AVFoundation和CIDetector从视频输入中逐帧检测微笑。在captureOutput中使用CIDetector时,其准确性非常不一致。同样的面部表情可以从微笑快速反弹到不微笑,这取决于光线、与相机的距离以及图片中的其他面部。有没有一种方法可以让CIDetector在不太慢的情况下不那么紧张 @interface CameraViewController () { BOOL smiling; } ... - (void)captureOutput:(AVCap
@interface CameraViewController () {
BOOL smiling;
}
...
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {
CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CFDictionaryRef attachments = CMCopyDictionaryOfAttachments(kCFAllocatorDefault, sampleBuffer, kCMAttachmentMode_ShouldPropagate);
CIImage *ciImage = [[CIImage alloc] initWithCVPixelBuffer:pixelBuffer options:(__bridge NSDictionary *)attachments];
if (attachments)
CFRelease(attachments);
//CIImage translates all the pixels -90 deg; set orientation taking this into account
NSNumber *orientation;
switch ([UIDevice currentDevice].orientation) {
case UIDeviceOrientationPortrait:
orientation = @6;
break;
case UIDeviceOrientationPortraitUpsideDown:
orientation = @8;
break;
case UIDeviceOrientationLandscapeLeft:
orientation = @3;
break;
case UIDeviceOrientationLandscapeRight:
orientation = @1;
break;
default:
orientation = @6;
break;
}
NSArray *faces = [[[SmileDetector sharedDetector] detector] featuresInImage:ciImage
options:@{CIDetectorSmile: @(YES), CIDetectorImageOrientation:orientation}];
smiling = NO;
for (CIFaceFeature* face in faces)
if (face.hasSmile) {
smiling = YES;
break;
}
}
SmileDetector是在其他ViewController中使用相同CIDetector实例的单例。我将探测器精度设置为低,因为高精度太慢
- (id)init {
if (self = [super init]) {
detector = [CIDetector detectorOfType:CIDetectorTypeFace
context:[CIContext contextWithOptions:nil]
options:@{CIDetectorAccuracy:CIDetectorAccuracyLow}];
}
return self;
}
我目前正在处理同样的问题,我发现在CIDetector工作之前,对帧进行预处理以稳定对比度和亮度效果非常好。我的项目使用的是静止帧,我不知道这对视频帧的效果如何…也许只是改变精度@{CIDetectorAccuracy:CIDetectorAccuracyHigh}尝试过,太慢:帧在CIDetector分析最后一帧之前更新。不,如果添加自动调整调用“let adjustments=sourceImg.autoAdjustmentFilters”,则会进一步延迟执行