Skip to content

Instantly share code, notes, and snippets.

@ozgurshn
Last active August 29, 2019 01:00
Show Gist options
  • Select an option

  • Save ozgurshn/088c090ed7723479a6e2432d20276771 to your computer and use it in GitHub Desktop.

Select an option

Save ozgurshn/088c090ed7723479a6e2432d20276771 to your computer and use it in GitHub Desktop.
Setting device orientation in vision image request handler
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