OpenCV insufficient memory crash on iOS

asked 2018-02-15 17:26:38 -0600

fellowDev gravatar image

I created a fisherface face recognizer an am trying to train it. When I call the train function it returns this error in the logs.

 FaceDetector(1872,0x1b625bb80) malloc: *** mach_vm_map(size=2016002048) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
OpenCV(3.4.0-dev) Error: Insufficient memory (Failed to allocate 2016000000 bytes) in OutOfMemoryError, file /Users/Name/Desktop/OpenCVBuild/opencv/modules/core/src/alloc.cpp, line 55
OpenCV(3.4.0-dev) Error: Assertion failed (u != 0) in create, file /Users/mustafa/Desktop/OpenCVBuild/opencv/modules/core/src/matrix.cpp, line 436
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: OpenCV(3.4.0-dev) /Users/Name/Desktop/OpenCVBuild/opencv/modules/core/src/matrix.cpp:436: error: (-215) u != 0 in function create


Here is my training function:

-(void) trainFaceRecognitionModel2 {
    NSArray * imageArray2;
    imageArray2 = [NSArray arrayWithObjects:[UIImage imageNamed:@"IMG_1781"], [UIImage imageNamed:@"IMG_1782"], [UIImage imageNamed:@"IMG_1783"], [UIImage imageNamed:@"IMG_1784"], [UIImage imageNamed:@"IMG_1785"], [UIImage imageNamed:@"IMG_1786"], [UIImage imageNamed:@"IMG_1787"], [UIImage imageNamed:@"IMG_1788"], [UIImage imageNamed:@"IMG_1789"], [UIImage imageNamed:@"IMG_1790"], [UIImage imageNamed:@"IMG_1791"], [UIImage imageNamed:@"IMG_1792"], [UIImage imageNamed:@"IMG_1793"], [UIImage imageNamed:@"IMG_1794"], [UIImage imageNamed:@"IMG_1795"], [UIImage imageNamed:@"IMG_1796"], [UIImage imageNamed:@"IMG_1797"], [UIImage imageNamed:@"IMG_1798"], [UIImage imageNamed:@"IMG_1799"], [UIImage imageNamed:@"IMG_1800"], [UIImage imageNamed:@"IMG_1801"], [UIImage imageNamed:@"1801"], [UIImage imageNamed:@"1802"], [UIImage imageNamed:@"IMG_1803"], nil];

    //1781 - 1803

    NSMutableArray * trainArray;

    cv::Mat grayMat;
    std::vector<cv::Mat> images = vector<cv::Mat>();
    std::vector<int> labels;

    for (UIImage* image in imageArray2) {
        cv::Mat imageMat;
        UIImageToMat(image, imageMat);

        cv::cvtColor(imageMat, grayMat, CV_BGR2GRAY);


        printf("training model...");


    model2 -> train(images, labels); //CRASH ON THIS LINE


I am not sure that I am training the model right. How would I reduce the memory usage and solve the problem?

edit retag flag offensive close merge delete


Lowering the amount of images does not work, so I must be training the model wrong. How would I train the model properly?

fellowDev gravatar imagefellowDev ( 2018-02-16 18:23:30 -0600 )edit

I'm having the same problem while trying to stitch a spherical panorama image. It works well with a few images but as soon as i give it lets say 30 images it crashes and gives me this error

singhraman4282 gravatar imagesinghraman4282 ( 2018-08-17 15:36:12 -0600 )edit