AVCaptureDevice.RotationCoordinator
to sync device rotation to video preview layer. That was straight forward but the problem was ouput sampleBuffer was not rotated. So, for frame processing purposes I rotated the
sampleBuffer
with below function. private func cgImageOrientation(from rotationAngle: CGFloat) -> CGImagePropertyOrientation {
switch rotationAngle {
case 0: return isFrontCamera ? .upMirrored : .up
case 90: return isFrontCamera ? .rightMirrored : .right
case 180: return isFrontCamera ? .downMirrored : .down
case 270: return isFrontCamera ? .leftMirrored : .left
default: return isFrontCamera ? .upMirrored : .up
}
}
This are just notes for angles I observed and so far got successfull results. (Probably it is device specific so I would like to find a more general way of dealing with this ...)
Model | Device orientation | Camera position | Preview Layer Connection Angle |
Camera | func cgImageOrientation result | ok? |
---|---|---|---|---|---|---|
iPad (A16) | landscape | top | 180 | front | downMirrored | ok |
portrait | right | 90 | front | rightMirrored | ok | |
landscape | bottom | 0 | front | upMirrored | ok | |
portrait | left | 270 | front | leftMirrored | ok |
0 comments :
Post a Comment