Ask Your Question

Ríomhaire's profile - activity

2013-04-16 06:42:23 -0600 received badge  Editor (source)
2013-04-16 06:30:01 -0600 asked a question Reduce memory consumed by method that uses OpenCv on iOS

I am using OpenCV on iOS to do some image processing on a UIImage.

The method processImage is consuming too much memory. When I profile the App with allocations in Instruments. The Live Bytes peaks at 55MB to 60MB for about a second. This causes the application to crash.

It used to be higher 1. ~90MB, changing int ddepth reduced this ( from CV_16S to CV_8U). While I do understand that reducing the 'desired depth of the destination image' may reduce the memory consumed, I do not understand it's inner workings to pick the best format. 2. ~ 70MB, assigning the output of [self cvMatFromUIImage:imageToProcess] to your variable imageMatrix, which will avoid an extra image creation and reduce the peak value.

The reduction in ddepth also seems to increase the execution time of the method.

I wish to greatly reduce the Live Bytes peak and increase the execution time of the method.

Any insights in how to achieve this would be greatly appreciated.

- (void)processImage:(UIImage *)imageToProcess
{
cv::Mat imageMatrix =  [self cvMatFromUIImage:imageToProcess];

double  sigmaX = 1.0;

int ddepth = CV_8U; //  ddepth – The desired depth of the destination image

cv::GaussianBlur(imageMatrix, imageMatrix, cv::Size(3,3), sigmaX);

cv::Laplacian(imageMatrix, imageMatrix, ddepth, 1);

double minVal;
double maxVal;

cv::minMaxLoc(imageMatrix, &minVal, &maxVal);

std::cout << "min val : " << minVal << std::endl;
std::cout << "max val: " << maxVal << std::endl;

}

Link to the original Stackoverflow thread.