首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用AVCaptureOutput的CIDetector

使用AVCaptureOutput的CIDetector
EN

Stack Overflow用户
提问于 2015-01-17 20:16:22
回答 1查看 1K关注 0票数 0

我正在尝试用AVFoundation和CIDetector从视频输入中一帧一帧地检测微笑。在captureOutput中使用时,CIDetector在准确性方面非常不一致。同样的面部表情可以根据光线、离相机的距离和照片中的其他面孔快速地从微笑到不微笑。有没有一种方法可以在不降低CIDetector速度的情况下减少它的抖动?

代码语言:javascript
复制
@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是在其他ViewControllers中使用相同的CIDetector实例的单例。我将探测器精度设置为Low,因为High太慢了。

代码语言:javascript
复制
- (id)init {
    if (self = [super init]) {
        detector = [CIDetector detectorOfType:CIDetectorTypeFace
                                      context:[CIContext contextWithOptions:nil]
                                      options:@{CIDetectorAccuracy:CIDetectorAccuracyLow}];
    }
    return self;
}
EN

回答 1

Stack Overflow用户

发布于 2015-02-10 03:23:47

我目前正在处理同样的问题,我发现在CIDetector工作之前对帧进行预处理以稳定对比度和亮度的效果非常好。我的项目是静态帧,我不知道这将如何工作与视频帧…

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27999375

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档