Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

iOS 12 + Mac OS X Mojave EXC_BAD_ACCESS on cvtColor

I've been trying to integrate OpenCV into my iOS project, but have been having trouble with a null pointer exception. I installed version 3.4.2 using Cocoapods, and the following code snippet works fine:

#import <opencv2/opencv.hpp>
#import <opencv2/imgproc/imgproc.hpp>
#import <opencv2/imgcodecs/ios.h>

#import "OpenCVWrapper.h"

@implementation OpenCVWrapper

+ (UIImage *) process:(UIImage *) image {
    cv::Mat m;
    UIImageToMat(image, m);

    // this works fine

    return MatToUIImage(gray);
}

But when I try to do a simple color conversion (or any type of manipulation for that matter) I get an EXC_BAD_ACCESS and it crashes my app

#import <opencv2/opencv.hpp>
#import <opencv2/imgproc/imgproc.hpp>
#import <opencv2/imgcodecs/ios.h>

#import "OpenCVWrapper.h"

@implementation OpenCVWrapper

+ (UIImage *) process:(UIImage *) image {
    cv::Mat m;
    UIImageToMat(image, m);

    cv::Mat gray;
    cv::cvtColor(m, gray, cv::COLOR_BGR2GRAY); // crashes here

    return MatToUIImage(gray);
}

I tried version 2 of opencv and tried stepping through the assembly, but wasn't able to figure out what was causing the problem.

iOS 12 + Mac OS X Mojave EXC_BAD_ACCESS on cvtColor

I've been trying to integrate OpenCV into my iOS project, but have been having trouble with a null pointer exception. I installed version 3.4.2 using Cocoapods, and the following code snippet works fine:

#import <opencv2/opencv.hpp>
#import <opencv2/imgproc/imgproc.hpp>
#import <opencv2/imgcodecs/ios.h>

#import "OpenCVWrapper.h"

@implementation OpenCVWrapper

+ (UIImage *) process:(UIImage *) image {
    cv::Mat m;
    UIImageToMat(image, m);

    // this works fine

    return MatToUIImage(gray);
MatToUIImage(m);
}

But when I try to do a simple color conversion (or any type of manipulation for that matter) I get an EXC_BAD_ACCESS and it crashes my app

#import <opencv2/opencv.hpp>
#import <opencv2/imgproc/imgproc.hpp>
#import <opencv2/imgcodecs/ios.h>

#import "OpenCVWrapper.h"

@implementation OpenCVWrapper

+ (UIImage *) process:(UIImage *) image {
    cv::Mat m;
    UIImageToMat(image, m);

    cv::Mat gray;
    cv::cvtColor(m, gray, cv::COLOR_BGR2GRAY); // crashes here

    return MatToUIImage(gray);
}

I tried version 2 of opencv and tried stepping through the assembly, but wasn't able to figure out what was causing the problem.