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
你是完全正確的,這是問題所在。該死,我花了1天的時間:) – MrTJ
@MTTJ不客氣! –