小编Han*_*Han的帖子

OpenCv iOS相机预览单一方向,无需拉伸

我正在为iOS编写一个OpenCv Cordova插件.我需要全屏显示相机预览并保持所有iOS设备(iPhone,iPad)的宽高比.

我能够实现人像模式(参见代码)并且在iPhone 6/plus上完美运行但是iPad上的相机预览略有拉伸可能是由于AVCaptureSessionPresetHigh支持的分辨率为1280x720.任何人都有关于如何实现单一方向(仅限横向或纵向)并保持纵横比的任何想法?

我目前启动相机的代码是

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    // Initialize imageView to fullscreen
    imageView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [self.view addSubview:imageView];
    [imageView setContentMode:UIViewContentModeScaleAspectFill];
    [imageView setClipsToBounds:YES];

    self.videoCamera = [[FixedCvVideoCamera alloc] initWithParentView:imageView];
    self.videoCamera.delegate = self;
    self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionBack;
    self.videoCamera.defaultAVCaptureSessionPreset = AVCaptureSessionPresetHigh;
    self.videoCamera.defaultAVCaptureVideoOrientation =  AVCaptureVideoOrientationPortrait;
    self.videoCamera.defaultFPS = 30;
    [self.videoCamera start];
}
Run Code Online (Sandbox Code Playgroud)

请注意,我使用的是FixedCvVideoCamera而不是OpenCv CvVideoCamera类.其原因是,我继承并重写CvVideoCamera的layoutPreviewLayer功能,以保持纵向模式.

 - (void)layoutPreviewLayer;
{
    if (self.parentView != nil)
    {
        CALayer* layer = self->customPreviewLayer;
        CGRect …
Run Code Online (Sandbox Code Playgroud)

xcode opencv ios avcapturesession

5
推荐指数
1
解决办法
1438
查看次数

标签 统计

avcapturesession ×1

ios ×1

opencv ×1

xcode ×1