如何使CvVideoCamera不自动旋转



我的CvVideoCamera自动旋转,我希望它不要旋转。这已经在错误跟踪器上提出,但有一段时间没有活动了。

子类CvVideoCamera,并只删除旋转代码。我希望我的方向始终是肖像,所以这很简单:

MyCv摄像机.h

#import <opencv2/highgui/cap_ios.h>
@interface MyCvVideoCamera : CvVideoCamera
- (void)updateOrientation;
- (void)layoutPreviewLayer;
@property (nonatomic, retain) CALayer *customPreviewLayer;
@end

MyCvVideoCamera.m

#import "MyCvVideoCamera.h"
@implementation MyCvVideoCamera
- (void)updateOrientation;
{
    // nop
}
- (void)layoutPreviewLayer;
{
    if (self.parentView != nil) {
        CALayer* layer = self.customPreviewLayer;
        CGRect bounds = self.customPreviewLayer.bounds;
        layer.position = CGPointMake(self.parentView.frame.size.width/2., self.parentView.frame.size.height/2.);
        layer.bounds = bounds;
    }
}
@end

为了让它发挥作用,我必须添加:

@protocol CvVideoCameraDelegateMod <CvVideoCameraDelegate>
@end

到上述的MyCvVideoCamera.h

@synthesize customPreviewLayer = _customPreviewLayer;

到MyCvVideoCamera.m

快速修复在初始化CVVideoCamera之前,添加以下行

NSNumber*值=[NSNumber numberWithInt:UIInterfaceOrientationPortrait];[[UIDevice currentDevice]setValue:value for Key:@"orientation"];

self.videoCamera=[[CvVideoCamera alloc]initWithParentView:self.previewImage];self.videoCamera.delegate=自身;

相关内容

  • 没有找到相关文章

最新更新