如何使用.boundingbox在Swift中的条形码周围绘制边框?

发布于 2025-01-24 04:48:04 字数 722 浏览 6 评论 0原文

我有一个带条形码扫描仪的应用程序,当应用程序扫描时,我想在条形码周围绘制一个盒子。我想我可以使用.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寂寞花火° 2025-01-31 04:48:04

检查此

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文