gpt4 book ai didi

ios - Swift 3 在一行中检测多个条码

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:55:54 34 4
gpt4 key购买 nike

您好,我正在使用 swift3AVFoundation 来检测账单的条形码。我的帐单一行最多有 3 个条形码。如何将全部条码合并为一串,并在一行中的所有条码都被检测并合并为一串后才停止运行?

这是我的账单样本

enter image description here

底部有3个条码

这是我的 AVCaptureMetadataOutputObjectsDelegate 函数

func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [Any]!, from connection: AVCaptureConnection!) {
// This is the delegate'smethod that is called when a code is readed
for metadata in metadataObjects {
let readableObject = metadata as! AVMetadataMachineReadableCodeObject
let code = readableObject.stringValue


self.dismiss(animated: true, completion: nil)
self.delegate?.barcodeReaded(barcode: code!)
print(code!)
print(readableObject.type)
}
}

我们如何修改上面的代码以扫描所有 3 个条形码并将它们组合起来,并在所有条形码都被解码后通知 Viewcontroller?非常感谢任何帮助。谢谢

最佳答案

除非检测到 3 个条码然后组合代码,否则不要停止扫描:

func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [Any]!, from connection: AVCaptureConnection!) {
// This is the delegate'smethod that is called when a code is headed

guard metadataObjects.count == 3 else { return }

var finalString: String = ""

for metadata in metadataObjects {
let readableObject = metadata as! AVMetadataMachineReadableCodeObject
let code = readableObject.stringValue

finalString.append(code!)
print(code!)
print(readableObject.type)
}

self.dismiss(animated: true, completion: nil)
self.delegate?.barcodeReaded(barcode: finalString)
}

关于ios - Swift 3 在一行中检测多个条码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40398896/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com