title: convert openCV matrix into vector
body: <p>Looks deceptively easy. After all we know that an std or openCV vector can be easily converted into Matrix like this: </p>
  
  <pre><code>vector&lt;Point&gt; iptvec(10);
  Mat iP(iptvec);
  </code></pre>
  
  <p>The reverse is suggested in openCV cheatSheet:</p>
  
  <pre><code>vector&lt;Point2f&gt; ptvec = Mat_ &lt;Point2f&gt;(iP);
  </code></pre>
  
  <p>However, there is one caveat: the matrix has to have only one row or one column. To convert an arbitrary matrix you have to reshape:</p>
  
  <pre><code>int sz = iP.cols*iP.rows;
  vector&lt;Point2f&gt; ptvec = Mat &lt;Point2f&gt;(iP.reshape(1, sz));
  </code></pre>
  
  <p>Otherwise you will get an error: </p>
  
  <p>*OpenCV Error: Assertion failed (dims == 2 &amp;&amp; (sizes[0] == 1 || sizes[1] == 1 || sizes[0]*sizes[1] == 0)) in create, file /home/.../OpenCV-2.4.2/modules/core/src/matrix.cpp, line 1385...</p>