我按照iOS video processing tutorial on the OpenCV site设法编译并在设备上安装它。但是当我点击“开始”按钮时,没有任何可见的事情发生。显然,我的- (void)processImage:(Mat&)image
回调从未被调用过。你能给我一些提示可能是什么问题吗?
我检查了一些事情:
actionStart
,两个日志行都打印为YES self
对象在分配到self.videoCamera.delegate
imageView
在屏幕上有效且可见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
答案 0 :(得分:8)
我在iPhone 4上测试过,效果很好。也许iPhone 3GS没有前置摄像头?然后,您必须更改此行:self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionFront
至self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionBack