2

This is a similar question to this question which did not receive any answers. I am asking a new one because my bounding is completely different than the previous question.

I am detecting the faces of an AVCaptureSession and adding a rectangle to the screen over the face. I would now like to be able to capture the contents of what's behind the UIView that I'm adding to the screen. If this isn't possible I could settle for cropping each frame as it comes in from captureOutput using the box CGRect. How can I go about doing either of these things?

Here is the code I'm using that takes a face rect and displays a UIView over it:

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

        for face in metadataObjects {
            let transformedMetadataObject = self.cameraLayer.transformedMetadataObject(for: face)!
            let rect = transformedMetadataObject.bounds

            let box = UIView.init(frame: rect)
            box.backgroundColor = UIColor.init(red: 1, green: 1, blue: 1, alpha: 0.5)

            for faceRect in faceRects {
                faceRect.removeFromSuperview()
            }

            faceRects.append(box)
            self.view.addSubview(box)
        }

    }
Alex Wulff
  • 2,039
  • 3
  • 18
  • 29

0 Answers0