I'm using OpenCV 3.2.0 on Xcode 8.2.1+ and trying to create an object detection application on the iPad. The iPad that is in use for testing is an iPad Air 2, which has 2GB of RAM. We have detectors that have already been trained. I want to be able to detect using the detectors prebuilt with images taken on the iPad.
However I cannot get my code to work on the iPad due to the fact that the detectMultiScale requires about 6.4GB of memory to be allocated to run.
Here is a snippet of the code in Objective-C++:
#import <opencv2 opencv.hpp=""> #import "OpenCVWrapper.h" #import <opencv2 imgcodecs="" ios.h=""> -(void) detectObject:(UIImage *)image { double scaleFactor = 1.01; int mergeThreshold = 100; cv::Mat imageMat, imageGray; UIImageToMat(image, imageMat); cv::cvtColor(imageMat, imageGray, cv::COLOR_BGR2GRAY); // This is where we get the error, within this method objectDetector.detectMultiScale(imageMat, _boxes, scaleFactor, mergeThreshold); }
And the error that I get:
POC-Planogram(282,0x1b1481c40) malloc: *** mach_vm_map(size=6395445248) failed (error code=3) *** error: can't allocate region *** set a breakpoint in malloc_error_break to debug OpenCV Error: Insufficient memory (Failed to allocate 6395435520 bytes) in OutOfMemoryError, file /Volumes/build-storage/build/master_iOS-mac/opencv/modules/core/src/alloc.cpp, line 52 OpenCV Error: Assertion failed (u != 0) in create, file /Volumes/build-storage/build/master_iOS-mac/opencv/modules/core/src/matrix.cpp, line 433 libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /Volumes/build-storage/build/master_iOS-mac/opencv/modules/core/src/matrix.cpp:433: error: (-215) u != 0 in function create
A couple of questions that I have concerning this topic are:
- Does this function in OpenCV require that amount of RAM as a minimum to run.
- if it does not, is there perhaps a configuration file inside OpenCV that can be changed to reduce the RAM it uses.
- Is there something in code that can be added to reduce the amount of RAM that needs to be allocated?
Thank you in advance.