Ask Your Question

iOS CvVideoCamera shows up sideways

asked 2014-03-06 01:37:51 -0600

Kenny gravatar image

updated 2014-03-06 01:50:38 -0600

berak gravatar image


I have been working with JavaCV for a while for a AR.Drone project and decided to try something on the iOS. I am trying to use the iPhone camera as a simulator for my drone so that I don't have to fly it all the time.

I am using CvVideoCamera to get the image. I got the image but for some reason the image is rotated 90 degree clockwise. Did anyone run into that problem before?

Here is what I have in the viewDidLoad method:

[super viewDidLoad];

self.video_camera = [[CvVideoCamera alloc] initWithParentView:image_view];
self.video_camera.delegate = self;
self.video_camera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionBack;
self.video_camera.defaultAVCaptureVideoOrientation = AVCaptureVideoOrientationPortrait;
self.video_camera.defaultAVCaptureSessionPreset = AVCaptureSessionPreset352x288;
self.video_camera.defaultFPS = 30;
self.video_camera.grayscaleMode = NO;

Thank you, Kenny

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted

answered 2015-09-25 14:28:02 -0600

otusweb gravatar image

Or even better since you are already using the camera:

self. video_camera.rotateVideo = YES;

edit flag offensive delete link more

answered 2017-01-27 01:41:15 -0600

Prakash iOS gravatar image

Quick fix Before initialize the CVVideoCamera add these lines

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

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

edit flag offensive delete link more


it work for me

anhht gravatar imageanhht ( 2017-10-06 03:49:43 -0600 )edit

answered 2014-03-10 13:08:39 -0600

Kenny gravatar image

Found a solution to the problem, I added the following two lines after the code that posted above:

CGAffineTransform xform = CGAffineTransformMakeRotation(-M_PI / 2);
image_view.transform = xform;
edit flag offensive delete link more

Question Tools


Asked: 2014-03-06 01:37:51 -0600

Seen: 2,490 times

Last updated: Jan 27 '17