0

on iOS, is-it possible to get the Camera orientation (in degrees) like Android ?

Camera.CameraInfo info = new Camera.CameraInfo();
Camera.getCameraInfo(cameraId, info);
int degrees = info.orientation;

I tried

NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for(AVCaptureDevice *camera in devices) {
    AVCaptureDeviceInput *deviceInput = [[AVCaptureDeviceInput alloc] initWithDevice:camera error:nil];
    AVCaptureSession *session = [[AVCaptureSession alloc] init];
    [session addInput:deviceInput];
    AVCaptureMetadataOutput *output = [[AVCaptureMetadataOutput alloc] init];
    [session addOutput:output];
    AVCaptureConnection *connection = [output connectionWithMediaType:AVMediaTypeMetadata];
    NSLog(@((int)connection.videoOrientation).stringValue);
}

but it return "0" for all devices

Thanks

pol2020
  • 15
  • 6

1 Answers1

0

AVCaptureConnection has the videoOrientation property.

You can also try using device orientation, if you need to transform photo output somehow. Here you can find some instruction, how to work with device orientation if you need.

lazarevzubov
  • 1,767
  • 2
  • 14
  • 24
  • Is-it possible to get "AVCaptureConnection" from "AVCaptureDevice *inputDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];" ? – pol2020 Apr 21 '22 at 07:06
  • Could you show, how do you use camera in general? How the session is configured? – lazarevzubov Apr 21 '22 at 10:03
  • I need to get all Cameras orientation in a loop. – pol2020 Apr 21 '22 at 11:26
  • videoOrientation has limited set of cases that you can switch over (https://developer.apple.com/documentation/avfoundation/avcapturevideoorientation). The question is how do you use camera? What's the code? If you use a session with a video connection, then videoOrientation will help (while you're handling input from camera). If you just need a set of constants for informative use–you can use the AVCaptureVideoOrientation enum directly. – lazarevzubov Apr 21 '22 at 17:52
  • 1
    I added the code in the body question – pol2020 Apr 22 '22 at 06:10
  • videoOrientation docs say that "This property is only applicable to connections involving video." Have you tried to use AVMediaTypeVideo instead of AVMediaTypeMetadata and using a video-corresponding output? – lazarevzubov Apr 22 '22 at 10:30
  • 1
    lazarevzubov : you're right, thanks. – pol2020 Apr 22 '22 at 21:30