Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

cv2.perspectiveTransform() with Python

I am attempting to use the perspectiveTransform() function in Python to warp a set of points:

import cv2
import numpy as np

a = np.array([[1, 2], [4, 5], [7, 8]], dtype='float32')
h = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype='float32')
pointsOut = cv2.perspectiveTransform(a, h)

However, all I get is an error:

cv2.error: /build/buildd/opencv-2.3.1/modules/core/src/matmul.cpp:1916:
error: (-215) scn + 1 == m.cols && (depth == CV_32F || depth == CV_64F)
in function perspectiveTransform

I assume I'm passing the arrays in the wrong format somehow, but I've tried quite a few different combinations of array shapes and data types with no success. What's the right way to do this?