Ask Your Question

iOS video processing tutorial problem

asked 2013-01-10 11:15:24 -0500

MrTJ gravatar image

I followed the iOS video processing tutorial and managed to compile and install it on the device. However when I click on the "Start" button, nothing visible happens. Apparently neither my - (void)processImage:(Mat&)image callback is never called. Could you give me some hints what could be the problem?

Some things I checked:

  • actionStart is called, and both log lines prints YES
  • the self object is valid when assigned to self.videoCamera.delegate
  • imageView is valid and visible on the screen
  • videoCamera is initialized when its start method is called

Here is the full source of my

@implementation ViewController

@synthesize videoCamera;

- (void)viewDidLoad
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

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

    self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionFront;
    self.videoCamera.defaultAVCaptureSessionPreset = AVCaptureSessionPreset352x288;
    self.videoCamera.defaultAVCaptureVideoOrientation = AVCaptureVideoOrientationPortrait;
    self.videoCamera.defaultFPS = 30;
    self.videoCamera.grayscaleMode = NO;


#pragma mark - UI Actions

- (IBAction)actionStart:(id)sender;
    [self.videoCamera start];
    NSLog(@"video camera running: %d", [self.videoCamera running]);
    NSLog(@"capture session loaded: %d", [self.videoCamera captureSessionLoaded]);

#pragma mark - Protocol CvVideoCameraDelegate

- (void)processImage:(cv::Mat&)image
    // Do some OpenCV stuff with the image
    cv::Mat image_copy;
    cvtColor(image, image_copy, CV_BGRA2BGR);

    // invert image
    bitwise_not(image_copy, image_copy);
    cvtColor(image_copy, image, CV_BGR2BGRA);

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2013-01-26 16:21:48 -0500

What device are you running this on? I ran into the same problem when running it on my iPhone 3GS. I believe the problem is that it's trying to access the "front" camera when my phone doesn't have one. So this line:

self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionFront;

Needs to change to:

self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionBack;

And if that doesn't help, try changing the session preset to something more generic, like AVCaptureSessionPresetMedium.


edit flag offensive delete link more

answered 2013-03-13 23:52:09 -0500

Hi- I get the same problem when running on a 3rd gen iPad. I've tried the two suggestions above with no luck, has anyone had this issue and solved it? It would be great to be able to download the full solution, to rule out the code.

Thanks! -Dave

edit flag offensive delete link more

Question Tools


Asked: 2013-01-10 11:15:24 -0500

Seen: 1,294 times

Last updated: Mar 13 '13