title: applying transformation matrix to a list of points in opencv (Python)
body: <p>I'm failing to understand <a href="http://docs.opencv.org/3.0-beta/modules/core/doc/operations_on_arrays.html?highlight=transform#cv2.transform" rel="nofollow noreferrer">the documentation for cv2.transform</a>. Will someone take pity and explain please (in Python)?</p>
  
  <p>I have code that draws a polygon, fills it in, and rotates the image</p>
  
  <pre><code>import numpy as np  
  import cv2
  
  dx,dy = 400,400
  centre = dx//2,dy//2
  img = np.zeros((dy,dx),np.uint8)
  
  # construct a long thin triangle with the apex at the centre of the image
  polygon = np.array([(0,0),(100,10),(100,-10)],np.int32)
  polygon += np.int32(centre)
  
  # draw the filled-in polygon and then rotate the image
  cv2.fillConvexPoly(img,polygon,(255))
  M = cv2.getRotationMatrix2D(centre,20,1) # M.shape =  (2, 3)
  rotatedimage = cv2.warpAffine(img,M,img.shape)
  </code></pre>
  
  <p>I want to rotate the polygon first and then draw it</p>
  
  <pre><code># this is clumsy, I have to extend each vector,
  # apply the matrix to each extended vector,
  # and turn the list of transformed vectors into an numpy array
  extendedpolygon = np.hstack([polygon,np.ones((3,1))])
  rotatedpolygon = np.int32([M.dot(x) for x in extendedpolygon])
  cv2.fillConvexPoly(img,rotatedpolygon,(127))
  </code></pre>
  
  <p>I'd like to do it in one function call but I can't get it right</p>
  
  <pre><code># both of these calls produce the same error
  cv2.transform(polygon,M)
  cv2.transform(polygon.T,M)
  # OpenCV Error: Assertion failed (scn == m.cols || scn + 1 == m.cols) in transform, file /home/david/opencv/modules/core/src/matmul.cpp, line 1947
  </code></pre>
  
  <p>I suspect that it's the phrase "<strong>src</strong> – input array that must have as many channels (1 to 4) as m.cols or m.cols-1" that I'm floundering on. I thought that polygon.T as three coordinates with the x and y parts as separate channels would qualify, but sadly not.</p>
  
  <p>I'm aware that the same question has been asked for C++, I want an answer in Python.</p>