How do I use the metadataOutputRectOfInterestForRect method and rectOfInterest property to scan a specific area? (QR Code)

前端 未结 8 1948
时光说笑
时光说笑 2020-12-04 18:00

I am building a QR code scanner with Swift and everything works in that regard. The issue I have is that I am trying to make only a small area of the entire visible A

8条回答
  •  独厮守ぢ
    2020-12-04 18:40

    I managed to create an effect of having a region of interest. I tried all the proposed solutions but the region was either a CGPoint.zero or had inappropriate size (after converting frames to a 0-1 coordinate). It's actually a hack for those who can't get the regionOfInterest to work and doesn't optimize the detection.

    In:

    func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) 
    

    I have the following code:

    let visualCodeObject = videoPreviewLayer?.transformedMetadataObject(for: metadataObj)
    if self.viewfinderView.frame.contains(visualCodeObject.bounds) { 
        //visual code is inside the viewfinder, you can now handle detection
    }
    

提交回复
热议问题