title: How to copy a continuous Mat to an uncontinuous Mat
body: <p>I'm not very familiar with cv::Mat. I met a question while memory copy.</p>
  <p>I get some data from <strong>gpu</strong> and create a Mat using these data.</p>
  <pre><code>// frame_height and frame_width = 112, frame_step = 512
  cv::Mat frame = cv::Mat(frame_height, frame_width, CV_8UC3, src_data, frame_step);
  
  </code></pre>
  <p>However, the memory of these data is not <strong>Continuous</strong> which causes lots of trouble. Then I do some operations on the Mat frame. For example, the <code>cv::warpPerspective</code>:</p>
  <pre><code>cv::warpPerspective(frame, warpImg, M, cv::Size(112, 112),cv::INTER_LINEAR);
  
  </code></pre>
  <p>the output Mat warpImg has the same size of frame: 112 * 112 * 3. But it is <strong>Continuous</strong>, which means I can't <strong>cover</strong> it back to gpu directly since the size of memory in gpu is: 112 * 512 * 3.</p>
  <p>I copy them by rows temporarily:</p>
  <pre><code>    for (int i = 0; i &lt; frame.rows; i++)
      {
          uchar *data = frame.ptr&lt;uchar&gt;(i);
          uchar *data2 = warpImg.ptr&lt;uchar&gt;(i);
          for (int j = 0; j &lt; frame.cols * frame.channels(); j++)
          {
              data[j] = data2[j];
              
          }
      }
  </code></pre>
  <p>It works though it is ugly, I want to know if there is a better way to achieve this.</p>
  <p>Thanks in advance.</p>