如何使用.boundingbox在Swift中的条形码周围绘制边框?
我有一个带条形码扫描仪的应用程序,当应用程序扫描时,我想在条形码周围绘制一个盒子。我想我可以使用.boundingbox
来完成此操作,但是我不确定该如何处理。
这是我现在对条形码处理程序的设置:
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
}
这用于创建vndetectbarcodesrequest
,该将传递给vnimagerequesthandler.perform()
函数。
我试图找到一种用CashApeLayer
绘制盒子的方法,但尚未找到一种使该工作的方法。条形码扫描系统中是否内置了一些东西,可以让我在条形码周围画一个盒子?还是我可以使用边界框绘制它的不同方式?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查此
Check if this link is useful. It is not related to border but you will get an idea about boundingbox.