Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add rotation to ios #540

Merged
merged 7 commits into from
Nov 2, 2023
Merged

Conversation

juanmartin8a
Copy link
Contributor

Add the rotation functionality to iOS. It rotates the image with the given rotation parameter from the InputImage metadata. I use it to rotate the image when the camera in flutter is locked to "portrait up".

@juanmartin8a juanmartin8a changed the title add rotation to ios feat: Add rotation to ios Oct 13, 2023
@fbernaly
Copy link
Collaborator

@juanmartin8a
Copy link
Contributor Author

@fbernaly fbernaly merged commit 13cb50a into flutter-ml:master Nov 2, 2023
2 checks passed
@fbernaly
Copy link
Collaborator

fbernaly commented Nov 2, 2023

This changes are breaking the example app. I will need to revert them. Please submit another PR and make sure our example app works correctly with all the APIs.

Look at this code to include all the possible rotations and camera lens options. Your switch case does not include all of them: https://developers.google.com/ml-kit/vision/face-detection/ios#2.-prepare-the-input-image

It should be something like this:

- (UIImageOrientation)
  imageOrientationFromDeviceOrientation:(UIDeviceOrientation)deviceOrientation
                         cameraPosition:(AVCaptureDevicePosition)cameraPosition {
  switch (deviceOrientation) {
    case UIDeviceOrientationPortrait:
      return cameraPosition == AVCaptureDevicePositionFront ? UIImageOrientationLeftMirrored
                                                            : UIImageOrientationRight;

    case UIDeviceOrientationLandscapeLeft:
      return cameraPosition == AVCaptureDevicePositionFront ? UIImageOrientationDownMirrored
                                                            : UIImageOrientationUp;
    case UIDeviceOrientationPortraitUpsideDown:
      return cameraPosition == AVCaptureDevicePositionFront ? UIImageOrientationRightMirrored
                                                            : UIImageOrientationLeft;
    case UIDeviceOrientationLandscapeRight:
      return cameraPosition == AVCaptureDevicePositionFront ? UIImageOrientationUpMirrored
                                                            : UIImageOrientationDown;
    case UIDeviceOrientationUnknown:
    case UIDeviceOrientationFaceUp:
    case UIDeviceOrientationFaceDown:
      return UIImageOrientationUp;
  }
}

@juanmartin8a
Copy link
Contributor Author

Sure. Should the rotation be determined using the device orientation directly on obj-c or using the rotation parameter that is sent in the metadata through the channel?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants