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:
For comparison the in the camera app:
You need to adjust defaultAVCaptureSessionPreset
Eg:
self.videoCamera.defaultAVCaptureSessionPreset = AVCaptureSessionPreset1280x720;
Here is the a table of all tested camera sessionPreset's on devices, that support iOS 9
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.