Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Mat clone or just assignement?

I have a class that has a member of type Mat. I am doing some operation on the input image parameter and saving the image after step X in that member and returning the image after step Y. My problem is how to do it better:

  1. assigning the step X image to the member; or
  2. assigning the clone of step X image to the member?

The code is something like:

class Processing
{
private:
  cv::Mat m_img;

public:
  cv::Mat getTopHat() const { return m_topHat; }
  cv::Mat binarization(const cv::Mat& imgIn)
  {
    cv::Mat img2;
    processing1(imgIn, img2);
    processing2(img2, img2);
    m_img = img2.clone(); // or
    // m_img = img2;
    processing3(img2, img2);
    return img2;
  }
};

I am not sure if I do the second operation (assignment) is ok regarding the data. Any suggestions?

Mat clone or just assignement?

I have a class that has a member of type Mat. I am doing some operation on the input image parameter and saving the image after step X in that member and returning the image after step Y. My problem is how to do it better:

  1. assigning the step X image to the member; or
  2. assigning the clone of step X image to the member?

The code is something like:

class Processing
{
private:
  cv::Mat m_img;

public:
  cv::Mat getTopHat() getImg() const { return m_topHat; m_img; }
  cv::Mat binarization(const cv::Mat& imgIn)
  {
    cv::Mat img2;
    processing1(imgIn, img2);
    processing2(img2, img2);
    m_img = img2.clone(); // or
    // m_img = img2;
    processing3(img2, img2);
    return img2;
  }
};

I am not sure if I do the second operation (assignment) is ok regarding the data. Any suggestions?