0

I have an app with a barcode scanner, and I would like to draw a box around the barcode when the app scans it. I think I can do this with .boundingBox but I am not really sure how to go about this.

Here is my setup for the barcode handler right now:

func barcodeRequestHandler(request: VNRequest, error: Error?) {
    guard let results = request.results as? [VNBarcodeObservation],
          let payloadStringValue = results.last?.payloadStringValue,
          let box = results.last?.boundingBox
          
    else {
        return
    }
    
    // I think I can do something with 'box' here
}

This is used to create a VNDetectBarcodesRequest, which is passed to a VNImageRequestHandler.perform() function.

I have tried to find a way to draw the box with a CAShapeLayer, but haven't yet found a way to make that work. Is there something built into the barcode scanning system that would let me draw a box around the barcode? Or a different way I can use the bounding box to draw it?

Charlie
  • 136
  • 1
  • 8
  • Take a look a [this](https://medium.com/appcoda-tutorials/how-to-build-qr-code-scanner-app-in-swift-b5532406dd6b). Might be exactly what you are looking for @Charlie :) – Suyash Medhavi Apr 24 '22 at 18:45

1 Answers1

0

Check if this link is useful. It is not related to border but you will get an idea about boundingbox.