0

I have a camera app which shows a video preview in a AVCaptureVideoPreviewLayer instance, which includes a CGRect (for example a frame around the user). This layer has the same size as the UIView which contains the layer (for instance 667x375).

How do I translate the CGRect from the layer's coordinate space to the image output?

Vinod Vishwanath
  • 5,821
  • 2
  • 26
  • 40

1 Answers1

0

I found the answer myself; the right way is to use the method metadataOutputRectConverted.

        let tempRect = layer.metadataOutputRectConverted(fromLayerRect: rect)
        let trans_rect = CGRect(x: tempRect.origin.x * image.size.width,
                                y: tempRect.origin.y * image.size.height,
                                width: tempRect.width * image.size.width,
                                height: tempRect.height * image.size.height)

Where image is a UIImage instance.

Vinod Vishwanath
  • 5,821
  • 2
  • 26
  • 40