以下代码是OpenCV perspectiveTransform函数的一个简单示例。
import cv2
import numpy as np
src = np.array(((25, 25), (200, 20), (35, 210), (215, 200)), dtype=np.float32)
dest = np.array(((-50, -50), (50, -50), (-50, 50), (50, 50)), dtype=np.float32)
mtx = cv2.getPerspectiveTransform(src, dest)
original = np.array([((42, 42), (30, 100), (150, 75),(100, 150))], dtype=np.float32)
converted = cv2.perspectiveTransform(original, mtx)
print converted
效果很好,但为什么我需要在cv2.perspectiveTransform(original, mtx)
中的“原始”参数中添加一个额外维度才能使其正常工作?
original.shape => (1,4,2) mtx.shape => (3,3) src.shape => (4,2)