Last active
August 24, 2022 09:06
-
-
Save hietalajulius/a4a8f7686ff793263070341aa2339517 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func setupLayers() { | |
previewLayer = AVCaptureVideoPreviewLayer(session: session) | |
previewLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill | |
rootLayer = previewView.layer | |
previewLayer.frame = rootLayer.bounds | |
rootLayer.addSublayer(previewLayer) | |
inferenceTimeBounds = CGRect(x: rootLayer.frame.midX-75, y: rootLayer.frame.maxY-70, width: 150, height: 17) | |
inferenceTimeLayer = createRectLayer(inferenceTimeBounds, [1,1,1,1]) | |
inferenceTimeLayer.cornerRadius = 7 | |
rootLayer.addSublayer(inferenceTimeLayer) | |
detectionLayer = CALayer() | |
detectionLayer.bounds = CGRect(x: 0.0, | |
y: 0.0, | |
width: bufferSize.width, | |
height: bufferSize.height) | |
detectionLayer.position = CGPoint(x: rootLayer.bounds.midX, y: rootLayer.bounds.midY) | |
rootLayer.addSublayer(detectionLayer) | |
let xScale: CGFloat = rootLayer.bounds.size.width / bufferSize.height | |
let yScale: CGFloat = rootLayer.bounds.size.height / bufferSize.width | |
let scale = fmax(xScale, yScale) | |
detectionLayer.setAffineTransform(CGAffineTransform(rotationAngle: CGFloat(.pi / 2.0)).scaledBy(x: scale, y: -scale)) | |
detectionLayer.position = CGPoint(x: rootLayer.bounds.midX, y: rootLayer.bounds.midY) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment