Reduce memory consumed by method that uses OpenCv on iOS

asked 2013-04-16 06:30:01 -0500

Ríomhaire gravatar image

updated 2013-04-16 08:39:12 -0500

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.

edit retag flag offensive close merge delete

Comments

your stackoverflow-link points to opencv-docu O_o

Guanta gravatar imageGuanta ( 2013-04-16 06:32:21 -0500 )edit

Thanks @Guanta, I've updated it now.

Ríomhaire gravatar imageRíomhaire ( 2013-04-16 06:45:02 -0500 )edit