Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5841447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:53:30+00:00 2026-05-22T11:53:30+00:00

I am using OpenCV 2.2 compiled and built from source for iOS. I used

  • 0

I am using OpenCV 2.2 compiled and built from source for iOS. I used this blog post as a guide.

I have played around with getting some stuff to work like making images grayscale, blurring them and even running FAST. My problem however is that my code is leaking memory and this very quickly causes the app to be killed when run on a device.

From the blog post above I use the code below to turn a UIImage into an IplImage

+ (IplImage *)IplImageFromUIImage:(UIImage *)image 
{
    // NOTE you SHOULD cvReleaseImage() for the return value when end of the code.
    CGImageRef imageRef = image.CGImage;

    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    IplImage *iplimage = cvCreateImage(cvSize(image.size.width, image.size.height), IPL_DEPTH_8U, 4);
    CGContextRef contextRef = CGBitmapContextCreate(iplimage->imageData, iplimage->width, iplimage->height,
                                                    iplimage->depth, iplimage->widthStep,
                                                    colorSpace, kCGImageAlphaPremultipliedLast|kCGBitmapByteOrderDefault);
    CGContextDrawImage(contextRef, CGRectMake(0, 0, image.size.width, image.size.height), imageRef);
    CGContextRelease(contextRef);
    CGColorSpaceRelease(colorSpace);

    IplImage *ret = cvCreateImage(cvGetSize(iplimage), IPL_DEPTH_8U, 3);
    cvCvtColor(iplimage, ret, CV_RGBA2RGB);

    cvReleaseImage(&iplimage);

    return ret;
}

This works fine and does not seem to leak any memory however since I am using OpenCV 2.2 I am trying to use the C++ interface so I created the function below.

+ (Mat)MatFromUIImage:(UIImage *)image
{
    IplImage *iplImage = [self IplImageFromUIImage:image];
    Mat result(iplImage, true);
    cvReleaseImage(&iplImage);
    return result;
}

Once I start using this method my app starts leaking and consequently gets killed.

Any ideas on what I am doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T11:53:31+00:00Added an answer on May 22, 2026 at 11:53 am

    Here you are calling

    Mat::Mat(const IplImage* img, bool copyData=false)
    

    With copyData set to true, can you be sure that Mat::release() is being called? If your refcount never returns to 0, your destructor never fires leaving you with lots of copies of the image data in ram.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been following the simple guide at http://www.atinfinity.info/wiki/index.php?OpenCV/Using%20OpenCV%202.2%20on%20iOS%20SDK%204.2 (which uses the older guide
In my C/C++ program, I'm using OpenCV to capture images from my webcam. The
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
I have installed OpenCV C libraries from package management into my Kubuntu 9.10. I
I have compiled opencv on snow leopard and it says it compiled correctly, however
Can I take the image feed from Analog Camera using OpenCV, in a similar
I've just successfully built openCV as a static library for iOS armv7 architecture. However,
I've used this tutorial to build OpenCV on ubuntu. Everything goes well until I
When writing Python code using compiled extensions (the OpenCV Python bindings, for example), PyCharm
I am using opencv 2.1. In my code I have a few images stored

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.