title: From Mat to vector<Vec3f> and the other way around without corrupting the image
body: <p>I need to use OpenCV in order to read an image, convert it into a vector of Vec3f, work with the pixels and then convert it back to Mat in order to visualize it.</p>
  
  <p>I'm using C++17.</p>
  
  <p>Here the code so far:</p>
  
  <pre><code>Mat* in = new Mat;
  *in = imread(filepath);
  int rows = in-&gt;rows;
  int cols = in-&gt;cols;
  
  //MAT -&gt; VECTOR
  vector&lt;Vec3f&gt;* src = new vector&lt;Vec3f&gt;(rows * cols);
  if (in-&gt;isContinuous()) {
      src-&gt;assign(in-&gt;datastart, in-&gt;dataend);
  } 
  else {
      for (int i = 0; i &lt; rows; ++i) {
          src-&gt;insert(src-&gt;end(), in-&gt;ptr&lt;Vec3f&gt;(i), in-&gt;ptr&lt;Vec3f&gt;(i)+cols);
      }
  }
  
  //---USE THE VECTOR TO TRASFORM EVERY PIXEL GRAY---
  
  //SHOW 
  imshow("out", cv::Mat(rows, cols, CV_8U, src, cv::Mat::AUTO_STEP));
  </code></pre>
  
  <p>The result is a corrupted image, TV static noise like, even if i don't do the pixel processing phase</p>
  
  <p>Thank you for the help</p>