【发布时间】: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