title: C++ / OpenCV - How can I reshape a cv::Mat?
body: <p>I have a <code>cv::Mat</code> that has the dimensions of <code>40 rows X 32 columns</code>.</p>
  
  <p>However, I need to reshape this <code>cv::Mat</code> so that it will have <code>100 rows X 32 columns</code>, willing the empty elements with <code>0</code>.</p>
  
  <p>I have tried using the code:</p>
  
  <pre><code>cv::Mat mat1 = &lt;from somewhere else&gt;
  mat1.reshape(mat1.cols, 100);
  </code></pre>
  
  <p>But it's failing with the error:</p>
  
  <pre><code>OpenCV Error: Bad argument (The total number of matrix elements is not divisible by the new number of rows) in reshape.
  </code></pre>
  
  <p>Has anyone had any experience in reshaping <code>cv::Mat</code> matrices? Likewise, I would really like to be able to take a <code>100 rows X 32 columns</code> matrix and go back to a <code>40 rows X 32 columns</code> matrix (and just truncate the extra rows); but I'm assuming if I solve one problem then I'll solve the other.</p>