0

我正在尝试使用 swift 和简单的 AVCaptureSession 以及谷歌的 MLKit Barcode Detector 来检测 PDF417 条形码。但是,它不会检测没有结束行的截断 PDF417 条码。是否有任何快速库可以通过附加图像层将其添加到条形码的末尾?我目前也有条码的角落:

func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {

    let barcodeScanner = BarcodeScanner.barcodeScanner(options: barcodeOptions)

   // print("Capturing", Date())

    let image = VisionImage(buffer: sampleBuffer)
    image.orientation = imageOrientation(
      deviceOrientation: UIDevice.current.orientation,
      cameraPosition: AVCaptureDevice.Position.front)

    guard let barcodes = try? barcodeScanner.results(in: image) else {return}

    for barcode in barcodes {
     let corners = barcode.cornerPoints

    print(corners)

      //let displayValue = barcode.displayValue
      let rawValue = barcode.rawValue

角落: 在此处输入图像描述

截断:

在此处输入图像描述

非截断

非截断 PDF417

4

1 回答 1

1

一种选择是将 sampleBuffer 加载到 a 中CGContext并在其上绘制。

您可以使用此答案中描述的方法将 转换CMSampleBuffer为 a 。CGImage

然后可以将 CGImage 绘制到 CGContext 中。使用截断代码的角坐标,您可以通过扩展左上角和右上角以及左下角和右下角跨越的线来计算停止模式的角。

CGContext有绘制线条和路径的方法。

在 a 上CGContext,您可以使用move(to: point)addLine(to: point)closePath()setFillColor(color)strokePath()等方法fillPath()

完成所有绘图操作后,使用makeImage()检索输出图像。

然后,您可以从 UIImage 创建视觉图像,您可以使用UIImage(cgImage: contextOutput).

于 2020-06-08T22:16:25.843 回答