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?