title: Numpy-flipped image + cv2.filter2D = assertion failed?
body: <p>I'm trying to use OpenCV's <strong><code>filter2D()</code></strong> for convolution. In my algorithm I need to flip kernel before passing it to the function. My first attempt was to use Numpy's <code>fliplr()</code> and <code>flipud()</code> methods: </p>
  
  <pre><code>def test_np():
      im = np.random.uniform(size=(32, 32))
      k = np.ones((3, 3), dtype=np.float32) / 9.
      k = np.fliplr(np.flipud(k))                # Numpy-flipped kernel
      return cv2.filter2D(im, -1, k)
  </code></pre>
  
  <p>Surprisingly, it gave me an <strong>assertion error</strong> during filtering: </p>
  
  <blockquote>
    <p>OpenCV Error: Assertion failed (src.dims &lt;= 2 &amp;&amp; esz &lt;= (size_t)32) in transpose, file /build/buildd/opencv-2.4.2+dfsg/modules/core/src/matrix.cpp, line 1877
    terminate called after throwing an instance of 'cv::Exception'
      what():  /build/buildd/opencv-2.4.2+dfsg/modules/core/src/matrix.cpp:1877: error: (-215) src.dims &lt;= 2 &amp;&amp; esz &lt;= (size_t)32 in function transpose</p>
  </blockquote>
  
  <p>However, if I change flipping method to OpenCV's <code>flip()</code>: </p>
  
  <pre><code>def test_cv2():
      im = np.random.uniform(size=(32, 32))
      k = np.ones((3, 3), dtype=np.float32) / 9.
      k = cv2.flip(k, -1)                        # OpenCV-flipped kernel
      return cv2.filter2D(im, -1, k)
  </code></pre>
  
  <p><code>filter2D()</code> <strong>works without any problem</strong>. </p>
  
  <p>I checked results of <code>np.fliplr(np.flipud(...))</code> and <code>cv2.flip(...)</code> and they are the same: </p>
  
  <pre><code>k_np = np.fliplr(np.flipud(k))
  k_cv2 = cv2.flip(k, -1)
  (k_np == k_cv2).all()    # gives True
  </code></pre>
  
  <p><strong>So we have 2 arrays that look the same but behave differently</strong>. </p>
  
  <p>I'm curious, <strong>what is the difference</strong> between an array flipped with Numpy and the one flipped with OpenCV? Also, <strong>should I expect similar problems</strong> with other functions? </p>