title: ARKit Barcode tracking and Vision framework
body: <p>I have been trying to draw bounding box for QR code detected during ARSession. The result is:
  <a href="https://i.stack.imgur.com/hlxdF.jpg" rel="nofollow noreferrer">boundingbox 1</a>
  <a href="https://i.stack.imgur.com/q5AKR.jpg" rel="nofollow noreferrer">boundingbox 2</a></p>
  
  <p>The barcode is being tracked, but the geometry of bounding box is wrong.</p>
  
  <p>How to get correct coordinates of bounding box?</p>
  
  <p>The source code is:</p>
  
  <pre><code> public func session(_ session: ARSession, didUpdate frame: ARFrame) {
  
       // Only run one Vision request at a time
       if self.processing {
           return
       }
  
      self.processing = true
  
      let request = VNDetectBarcodesRequest { (request, error) in
  
          if let results = request.results, let result = results.first as? VNBarcodeObservation {
  
              DispatchQueue.main.async {
  
                  let path = CGMutablePath()
  
                  for result in results {
                      guard let barcode = result as? VNBarcodeObservation else { continue }
                      let topLeft = self.convert(point: barcode.topLeft)
                      path.move(to: topLeft)
                      let topRight = self.convert(point: barcode.topRight)
                      path.addLine(to: topRight)
                      let bottomRight = self.convert(point: barcode.bottomRight)
                      path.addLine(to: bottomRight)
                      let bottomLeft = self.convert(point: barcode.bottomLeft)
                      path.addLine(to: bottomLeft)
                      path.addLine(to: topLeft)
                  }                   
                  self.drawLayer.path = path
                  self.processing = false
              }
          } else {
              self.processing = false
          }
      }
  
      DispatchQueue.global(qos: .userInitiated).async {
          do {
              request.symbologies = [.QR]
              let imageRequestHandler = VNImageRequestHandler(cvPixelBuffer: frame.capturedImage, orientation: .right, options: [:])                
              try imageRequestHandler.perform([request])
          } catch {               
          }
      }
  }
  
   private func convert(point: CGPoint) -&gt; CGPoint {
       return CGPoint(x: point.x * view.bounds.size.width,
                     y: (1 - point.y) * view.bounds.size.height)
   }
  </code></pre>