在IOS上打开CV教程不起作用,EXC_BAD_ACCESS

时间:2016-02-24 18:15:54

标签: ios objective-c xcode opencv

我正在尝试为iOS编写一个简单的openCV应用程序,但是我在XCode中使用openCV函数时遇到了麻烦。他们将抛出EXC_BAD_ACCESS(代码= 1),或者不完全工作。我正在使用教程中的processImage示例,但它甚至不起作用。我正在使用XCode 7.3 beta并且相信我已经正确安装了openCV 2.4.11。

ViewController.h

#import <UIKit/UIKit.h>
#import <opencv2/highgui/cap_ios.h>


using namespace cv;

@interface ViewController : UIViewController <CvVideoCameraDelegate>
{
    //IBOutlet UIImageView *imageView;
    CvVideoCamera *camera;
}

@property (nonatomic, retain) CvVideoCamera* camera;

@end

ViewController.mm

#import "ViewController.h"
#import <opencv2/highgui/cap_ios.h>


@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView
@end

@implementation ViewController

@synthesize camera;

- (void)viewDidLoad {
    [super viewDidLoad];

    self.camera = [[CvVideoCamera alloc] initWithParentView: self.imageView];
    self.camera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionBack;

    self.camera.defaultAVCaptureSessionPreset = AVCaptureSessionPresetHigh;
    self.camera.defaultAVCaptureVideoOrientation = AVCaptureVideoOrientationPortrait;
    self.camera.defaultFPS = 60;
    self.camera.grayscaleMode = NO;
    self.camera.delegate = self;
    self.camera.useAVCaptureVideoPreviewLayer = YES;

    self.imageView.frame = self.view.bounds;

    [self.camera start];
}


#pragma mark - Protocol CvVideoCameraDelegate
#ifdef  __cplusplus


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

    // invert image
    bitwise_not(image_copy, image_copy); // ERROR IS THROWN HERE, BUT IT 
                                         // WILL ALSO THROW ON THE CVTCOLOR
                                         // IF I REMOVE THIS LINE
    cvtColor(image_copy, image, CV_BGR2BGRA);
}

#endif


-(void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end

1 个答案:

答案 0 :(得分:0)

我的代码中没有任何问题。也许尝试从here下载最新版本的框架。请注意,标题文件cap_ios.h已移至videoio,这意味着您必须导入:希望有帮助

#import <opencv2/videoio/cap_ios.h>

相关问题