iOS上的OpenCV相机预览拉长了

时间:2016-05-05 12:47:16

标签: ios opencv camera

我已将OpenCV的文档跟踪到implement the camera preview。这里,CvVideoCamera初始化为UIIamgeView。我现在设置了UIImageView的约束来填充整个屏幕。

相机初始化如下:

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];

我还设置了contentMode: [imageView setContentMode:UIViewContentModeScaleAspectFill]

仍然,相机预览失真:

Distorted

在相机应用程序中进行比较:

correct aspect ratio

1 个答案:

答案 0 :(得分:0)

您需要调整defaultAVCaptureSessionPreset,例如:

self.videoCamera.defaultAVCaptureSessionPreset = AVCaptureSessionPreset1280x720;

以下是支持iOS 9的设备上所有经过测试的相机sessionPreset的表格

Method to find device's camera resolution iOS