简体   繁体   中英

OpenCV camera preview on iOS stretched

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

Method to find device's camera resolution iOS

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM