title: cv2.perspectiveTransform() not accepting homography matrix
body: <p>Below are <code>bookhomography-example-1.jpg</code> and then <code>bookhomography-example-2.jpg</code> from a <a href="http://www.learnopencv.com/homography-examples-using-opencv-python-c/" rel="nofollow noreferrer">popular OpenCV blogpost</a> about homography.</p>
  
  <p>I can do the homography and warp the image, but the <code>h</code> or <code>h[0]</code> do not work when I try to use <code>cv2.perspectiveTransform(pts, h)</code> or <code>cv2.perspectiveTransform(pts, h[0])</code>. I've also tried converting the 2D array <code>h[0]</code> to a tuple of tuples, but no change. It's probably something simple, but I can't figure it out.</p>
  
  <blockquote>
    <p>Error Message:</p>
    
    <p>Traceback (most recent call last):</p>
    
    <p>File "bookhomography stackexchange v00.py", line 36, in  T_dst
    = cv2.perspectiveTransform(pts_dst, h) TypeError: m is not a numerical tuple</p>
  </blockquote>
  
  <p><strong>note:</strong> set <code>False</code> to <code>True</code> to induce failure. One of the two transform lines is the wrong direction but both fail.</p>
  
  <p><a href="https://i.stack.imgur.com/OFHyX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OFHyX.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/Q46q4.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Q46q4.jpg" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/OTT2f.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OTT2f.jpg" alt="enter image description here"></a></p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  import cv2
  
  im_src = cv2.imread("bookhomography-example-2.jpg")
  im_dst = cv2.imread("bookhomography-example-1.jpg")
  
  im_srcrgb = cv2.cvtColor(im_src, cv2.COLOR_BGR2RGB)
  im_dstrgb = cv2.cvtColor(im_dst, cv2.COLOR_BGR2RGB)
  
  pts_src = np.float32([52, 376, 240, 528, 413, 291, 217, 266]).reshape(4, -1)
  pts_dst = np.float32([56, 478, 387, 497, 376, 124, 148, 218]).reshape(4, -1)
  
  h       = cv2.findHomography(pts_src, pts_dst)
  
  print "type(h): ", type(h)
  print "len(h): ", len(h)
  
  print "type(h[0]): ", type(h[0])
  print "len(h[0]): ", len(h[0])
  print "h[0].shape: ", h[0].shape
  
  shape   = im_src.shape[:2][::-1]
  
  print h[0]
  
  print "pts_src:"
  print pts_src
  
  print "pts_dst:"
  print pts_dst
  
  if False:
      T_dst = cv2.perspectiveTransform(pts_dst, h)
      T_src = cv2.perspectiveTransform(pts_src, h)
  
      print "T_src:"
      print T_src
  
      print "T_dst:"
      print T_dst
  
  im_fin  = cv2.warpPerspective(im_src, h[0], shape)
  im_finrgb  = cv2.cvtColor(im_fin, cv2.COLOR_BGR2RGB)
  
  plt.figure()
  plt.subplot(1, 3, 1)
  plt.imshow(im_srcrgb)
  x, y = pts_src.T
  plt.plot(x, y, 'or', ms=8)
  plt.subplot(1, 3, 2)
  plt.imshow(im_dstrgb)
  x, y = pts_dst.T
  plt.plot(x, y, 'or', ms=8)
  plt.subplot(1, 3, 3)
  plt.imshow(im_finrgb)
  x, y = pts_dst.T
  plt.plot(x, y, 'or', ms=8)
  plt.show()
  </code></pre>