Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You need to override - (void)updateOrientation and - (void)layoutPreviewLayer.

CvVideoCameraMod.h

 #import <opencv2/highgui/cap_ios.h>

@protocol CvVideoCameraDelegateMod <CvVideoCameraDelegate>
@end

@interface CvVideoCameraMod : CvVideoCamera

- (void)updateOrientation;
- (void)layoutPreviewLayer;

@property (nonatomic, retain) CALayer *customPreviewLayer;

@end

CvVideoCameraMod.m

#import "CvVideoCameraMod.h"

 #define DEGREES_RADIANS(angle) ((angle) / 180.0 * M_PI)

@implementation CvVideoCameraMod

- (void)updateOrientation;
{
    NSLog(@"Would be rotating now... but I stopped it! :)");
    self.customPreviewLayer.bounds = CGRectMake(0, 0, self.parentView.frame.size.width, self.parentView.frame.size.height);
    [self layoutPreviewLayer];
}



- (void)layoutPreviewLayer;
{
    if (self.parentView != nil)
    {
        CALayer* layer = self.customPreviewLayer;
        CGRect bounds = self.customPreviewLayer.bounds;
        int rotation_angle = 0;

        switch (defaultAVCaptureVideoOrientation) {
            case AVCaptureVideoOrientationLandscapeRight:
                rotation_angle = 180;
                break;
            case AVCaptureVideoOrientationPortraitUpsideDown:
                rotation_angle = 270;
                break;
            case AVCaptureVideoOrientationPortrait:
                rotation_angle = 90;
            case AVCaptureVideoOrientationLandscapeLeft:
                break;
            default:
                break;
        }

        layer.position = CGPointMake(self.parentView.frame.size.width/2., self.parentView.frame.size.height/2.);
        layer.affineTransform = CGAffineTransformMakeRotation( DEGREES_RADIANS(rotation_angle) );
        layer.bounds = bounds;
    }
}
@end