如何让CvVideoCamera不自动旋转?

时间:2013-02-14 14:21:39

标签: ios objective-c opencv

我的CvVideoCamera自动旋转,我不想这样做。 This has been raised on the bugtracker,但暂时没有任何活动。

3 个答案:

答案 0 :(得分:27)

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

MyCvVideoCamera.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

答案 1 :(得分:3)

为了使其有效,我不得不添加:

@protocol CvVideoCameraDelegateMod <CvVideoCameraDelegate>
@end

到上面描述的MyCvVideoCamera.h

@synthesize customPreviewLayer = _customPreviewLayer;

到MyCvVideoCamera.m

答案 2 :(得分:2)

快速修复 在初始化CVVideoCamera之前添加这些行

NSNumber * value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait]; [[UIDevice currentDevice] setValue:value forKey:@&#34; orientation&#34;];

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