Last active
August 29, 2019 01:00
-
-
Save ozgurshn/088c090ed7723479a6e2432d20276771 to your computer and use it in GitHub Desktop.
Setting device orientation in vision image request handler
This file contains hidden or 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
| let exifOrientation = self.exifOrientationForCurrentDeviceOrientation() | |
| guard let requests = self.trackingRequests, !requests.isEmpty else { | |
| // No tracking object detected, so perform initial detection | |
| let imageRequestHandler = VNImageRequestHandler(cvPixelBuffer: pixelBuffer, | |
| orientation: exifOrientation, | |
| options: requestHandlerOptions) | |
| func exifOrientationForDeviceOrientation(_ deviceOrientation: UIDeviceOrientation) -> CGImagePropertyOrientation { | |
| switch deviceOrientation { | |
| case .portraitUpsideDown: | |
| return .rightMirrored | |
| case .landscapeLeft: | |
| return .downMirrored | |
| case .landscapeRight: | |
| return .upMirrored | |
| default: | |
| return .leftMirrored | |
| } | |
| } | |
| func exifOrientationForCurrentDeviceOrientation() -> CGImagePropertyOrientation { | |
| return exifOrientationForDeviceOrientation(UIDevice.current.orientation) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment