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 5954399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:57:56+00:00 2026-05-22T17:57:56+00:00

I have following function. I want to copy back some data from Mat to

  • 0

I have following function. I want to copy back some data from Mat to
IplImage * type and return it to the main control.
This is silly, but I couldn’t find a proper way to do this! The cheat
sheet havent say anything about Mat->IplImage * conversion WITH data
copy (since I need it outside the function).

Any idea or pointer is appreciated.
Best
–Ali

int test(IplImage **srcImage, int num_images)
{
  vector<Mat> images(num_images); 
  for (int i = 0; i < num_images; ++i) 
  { 
    images[i] = Mat(srcImage[i]); // I guess should be correct! 
      .... 
     // some manipulations on images[i] 
  } 

  // this should be wrong!
  for (int i = 0; i < num_images; ++i) 
  { 
     cvReleaseImage(&srcImage[i]); 
     srcImage[i] = new IplImage(images[i]); 
     images[i].clear();
   } 
  return 0;
 }
  • 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-22T17:57:56+00:00Added an answer on May 22, 2026 at 5:57 pm

    Short version: Convert to a temporary IplImage, then use cvCopy.

    However, there are several issues with your code:

    int test(IplImage **srcImage, int num_images)
    {
      vector<Mat> images(num_images); 
      for (int i = 0; i < num_images; ++i) 
      { 
        images[i] = Mat(srcImage[i]); // I guess should be correct!
    

    so far, yes.

          .... 
         // some manipulations on images[i] 
    

    If the manipulations are in-place (don’t reallocate the Mats), you don’t need to copy the data back, since the Mat constructor didn’t copy the data in the first place. If you do reallocate, then …

      } 
    
      // this should be wrong!
      for (int i = 0; i < num_images; ++i) 
      { 
         cvReleaseImage(&srcImage[i]);
    

    This can be problematic. images[i] might still be using the same memory.

         srcImage[i] = new IplImage(images[i]);
    

    new IplImage isn’t going to do you any good. It doesn’t have meaningful constructors, use cvCreateImage.

         images[i].clear();
    

    This is not neccessary, as the vector goes out of scope anyway.

       } 
      return 0;
     }
    

    The last loop should look something like this:

    for (int i = 0; i < num_images; ++i) { 
         IplImage* old = srcImage[i]; // store pointer for later deallocation in case of shared data
         IplImage src = images[i];
         srcImage[i] = cvCreateImage(...); // fill appropriate parameters here. If you didn't change size/type/etc, you might not need to create/deallocate(*)
         cvCopy(&src, srcImage[i]);
         cvReleaseImage(&old); // now it is safe to deallocate(*)
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following function that is pulling data from a database. The ajax
I have the following legacy VB6 function that I want to call from C#.
Eg. I have following delegate method I want to use as a callback function
i have a variable like the following and i want a function to only
I have some vector of elements passed to a function and I want to
I have the following function that prunes a tree data structure : public static
I want to copy some files as part of a backup routine. I have
Suppose I have a function that will return a large data structure, with the
I have the following function: CREATE FUNCTION fGetTransactionStatusLog ( @TransactionID int ) RETURNS varchar(8000)
I have the following function: //Function to get random number public static int RandomNumber(int

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.