【问题标题】:cidetector on video from iSightiSight 视频中的 cidetector
【发布时间】:2012-01-15 22:03:22
【问题描述】:

我正在尝试制作一个基本的应用程序来显示来自 iSight 的视频输入并使用 CIDetector 进行人脸检测。

我该怎么做? 要使用 CIDetector,我需要 CIImage。我可以以某种方式将每一帧作为 CIImage 并在其上运行检测器吗?然后显示原始输入,加上一些我想添加的效果。

谢谢

【问题讨论】:

    标签: face-detection


    【解决方案1】:

    本质上,您可以结合使用 AVFoundation 来捕获帧,并使用 Core Image 来使用检测来处理这些帧。

    作为起点,您可以从以下教程开始:http://indieambitions.com/idevblogaday/raw-video-data-app-quick-dirty/

    这是设置 EAGLContext、AVCaptureSession 以及所有输入和输出的绝佳开始。它还展示了如何将您的 CMSampleBufferRef 转换为您可以处理的核心图像。

    要启动并运行人脸检测,您需要添加一个 CIDetector(在本例中为 @property (nonatomic, strong) CIDetector *faceDetector),使用以下内容修改 viewDidLoad 代码:

    [CIDetector detectorOfType:CIDetectorTypeFace context:nil options:@{ CIDetectorAccuracy : CIDetectorAccuracyLow }];
    

    一个注意,你可以根据性能改变准确度。

    之后,当您捕获数据时,您可以通过在 captureOutput:DidOutputSampleBuffer:fromConnection: 函数中输入以下代码来收集所有面孔:

        NSArray *featureArray = [self.faceDetector featuresInImage:image];
    
        for (CIFeature *faceFeature in featureArray) {
            if ([faceFeature.type isEqualToString:CIFeatureTypeFace]) {  //future proof!
                CGRect faceRect = faceFeature.bounds;
                //do whatever you want with faceRect here.
            }
        }
    

    注意:这是一种让它启动并运行的方法,但我只能让它在视网膜 iPad 上以微不足道的 15 fps 运行。在 WWDC 视频和后续源代码中,他们使用 CIDetector 非常有效,因此可以做到。

    祝你好运!

    【讨论】:

    猜你喜欢
    • 2013-09-28
    • 2011-04-17
    • 1970-01-01
    • 2010-09-30
    • 2012-05-31
    • 1970-01-01
    • 2018-08-20
    • 2012-04-21
    • 2023-03-27
    相关资源
    最近更新 更多