【发布时间】:2020-06-19 13:34:42
【问题描述】:
所以,我必须扫描不同颜色的不同条形码。例如,黑色背景上的黄色条形码或白色背景上的黄色条形码。
我对它们被传统的线性和 CCD 条码扫描仪识别没有任何问题。我曾尝试使用 Apple Vision 框架,但它不适用于它们。它们在白色背景的黑色条形码上工作得非常好。
我的条形码都是 Code 128,所以我使用这个代码:
var barcodeObservations: [String : VNBarcodeObservation] = [:]
for barcode in barcodes {
if let detectedBarcode = barcode as? VNBarcodeObservation {
if detectedBarcode.symbology == .code128 {
barcodeObservations[detectedBarcode.payloadStringValue!] = detectedBarcode
}
}
}
在 AVCaptureVideoDataOutputSampleBufferDelegate 下的“captureOutput”函数中,我使用它来过滤我的实时提要为黑白,这有助于识别银色背景上的金色条码(第一张图片):
let context = CIContext(options: nil)
let currentFilter = CIFilter(name: "CIPhotoEffectMono")
currentFilter!.setValue(CIImage(cvImageBuffer: pixelBuffer), forKey: kCIInputImageKey)
let output = currentFilter!.outputImage!
context.render(output, to: pixelBuffer)
如何让 Vision Framework 检测反色条码?
“CIColorInvert”过滤器不起作用。
编辑:这些是条形码:
【问题讨论】:
-
您能否在您的问题中添加一张带有您无法检测到的示例条形码的图片
-
@curiously77 在这里你可以提到
My barcodes are all Code 128 so I use this code for it- 所以to accept barcodes of different colours意味着我认为你需要使用所有支持的符号 - developer.apple.com/documentation/vision/…
标签: swift machine-learning artificial-intelligence coreml apple-vision