5

I've followed the documentation of OpenCV to implement the camera preview. Here, CvVideoCamera is initialised with a UIIamgeView. I've now set the constraints of my UIImageView to fill out the whole screen.

The initialisation of the camera is as follows:

self.videoCamera = [[VideoCamera alloc] initWithParentView:imageView];
self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionBack;
self.videoCamera.defaultAVCaptureSessionPreset = AVCaptureSessionPresetMedium;
self.videoCamera.defaultAVCaptureVideoOrientation = AVCaptureVideoOrientationPortrait;
self.videoCamera.defaultFPS = 30;
self.videoCamera.grayscaleMode = false;
self.videoCamera.delegate = self;

[self.videoCamera start];

I've also set the contentMode: [imageView setContentMode:UIViewContentModeScaleAspectFill]

Still, the camera preview is distorted:

Distorted

For comparison the in the camera app:

correct aspect ratio

SKR
  • 180
  • 10

1 Answers1

0

You need to adjust defaultAVCaptureSessionPreset E.g.:

self.videoCamera.defaultAVCaptureSessionPreset = AVCaptureSessionPreset1280x720;

Here is the a table of all tested camera sessionPreset's on devices, that support iOS 9

Method to find device's camera resolution iOS

GrafiCode
  • 3,307
  • 3
  • 26
  • 31
Chic
  • 1