【问题标题】:How to define customized detector for iOS AVFoundation?如何为 iOS AVFoundation 定义自定义检测器?
【发布时间】:2017-01-08 21:04:01
【问题描述】:

我想使用 iPhone 从相机输入中检测一些三角形图案。我找到了一些可以使用 AVFoundation 检测 QR/条形码的示例代码。主要部分似乎是 AVMetadataMachineReadableCodeObject 类。以下是 AppCoda 的一些示例代码:

func captureOutput(captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [AnyObject]!, fromConnection connection: AVCaptureConnection!) {

// Check if the metadataObjects array is not nil and it contains at least one object.
if metadataObjects == nil || metadataObjects.count == 0 {
    qrCodeFrameView?.frame = CGRectZero
    messageLabel.text = "No barcode/QR code is detected"
    return
}

// Get the metadata object.
let metadataObj = metadataObjects[0] as! AVMetadataMachineReadableCodeObject

// Here we use filter method to check if the type of metadataObj is supported
// Instead of hardcoding the AVMetadataObjectTypeQRCode, we check if the type
// can be found in the array of supported bar codes.
if supportedBarCodes.contains(metadataObj.type) {
    // if metadataObj.type == AVMetadataObjectTypeQRCode {
    // If the found metadata is equal to the QR code metadata then update the status label's text and set the bounds
    let barCodeObject = videoPreviewLayer?.transformedMetadataObjectForMetadataObject(metadataObj)
    qrCodeFrameView?.frame = barCodeObject!.bounds

    if metadataObj.stringValue != nil {
        messageLabel.text = metadataObj.stringValue
    }
}

在上面的代码中,一旦检测到二维码,就会绘制一个边界框并更新文本字段。同样,AVMetadataFaceObject 类用于人脸检测应用程序。我从参考资料中看到,这两个类都是 AVMetadataObject 的子类。

我想知道是否可以通过编写 AVMetadataObject 的子类来自定义三角形检测器,例如,我们将子类称为 AVMetadataTriangleObject。 (我有一个现成的检测算法,并且有用 Matlab 编写的代码。将其转录成 swift 应该不难。)如果这种方法是不可能的,任何人都可以提出实现上述目标的替代方法吗?

非常感谢!

【问题讨论】:

    标签: ios swift avfoundation ios-camera


    【解决方案1】:

    AVMetadataObject 没有提供任何钩子来实现这样的事情,除了AVAssetResourceLoaderAVFoundation 不允许太多扩展。

    我认为您应该将您的算法转录为 swift 并针对您从 AVCaptureVideoDataOutput 捕获时获得的捕获的 CMSampleBuffer 图像运行它。

    【讨论】:

    • 感谢 Rhythmic 的快速响应。我现在将研究CMSampleBuffer
    猜你喜欢
    • 2015-08-15
    • 1970-01-01
    • 1970-01-01
    • 2017-01-17
    • 1970-01-01
    • 1970-01-01
    • 2016-10-25
    • 1970-01-01
    • 2014-05-11
    相关资源
    最近更新 更多