2013-01-11 73 views
2

我遵循iOS video processing tutorial on the OpenCV site並設法編譯並將其安裝在設備上。但是當我點擊「開始」按鈕時,沒有任何可見的情況發生。顯然,我的- (void)processImage:(Mat&)image回調從未被調用過。你能給我一些提示,可能是什麼問題?OpenCV視頻處理教程問題

有些事情我檢查:

  • actionStart被調用,並且兩個日誌行打印是在分配給self.videoCamera.delegate
  • imageView
  • self對象是有效是有效的,並在屏幕上可見
  • videoCamera當它的start方法被調用時被初始化

我使用iPhone 3GS進行測試。

這裏是我的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 

回答

8

我在iPhone 4測試,效果很好。也許iPhone 3GS沒有前置攝像頭?然後你必須改變這一行:self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionFrontself.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionBack

+2

你是完全正確的,這是問題所在。該死,我花了1天的時間:) – MrTJ

+0

@MTTJ不客氣! –