OpenCVvideo处理教程问题

我遵循OpenCV网站上的iOSvideo处理教程,并设法编译并安装在设备上。 但是,当我点击“开始”button,没有看到发生。 显然,我的- (void)processImage:(Mat&)imagecallback都不会被调用。 你能给我一些提示,可能是什么问题?

我检查了一些东西:

  • actionStart被调用,并且两个日志行打印YES
  • self对象在分配给self.videoCamera.delegate时有效
  • imageView在屏幕上有效且可见
  • videoCamerastart方法被调用时被初始化

我使用iPhone 3GS进行testing。

这里是我的ViewController.h的完整源码:

 #import <UIKit/UIKit.h> #import <opencv2/highgui/cap_ios.h> @interface ViewController : UIViewController <CvVideoCameraDelegate> { IBOutlet UIImageView* imageView; IBOutlet UIButton* button; CvVideoCamera* videoCamera; } - (IBAction)actionStart:(id)sender; @property (nonatomic, strong) CvVideoCamera* videoCamera; @end 

和ViewController.mm:

 @implementation ViewController @synthesize videoCamera; - (void)viewDidLoad { [super viewDidLoad]; 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); } @end 

我在iPhone 4上testing过,效果很好。 也许iPhone 3GS没有前置摄像头? 然后你必须改变这一行: self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionFront to self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionBack