OpenCV warpPerspective参数数量

15

在我的脚本中,我有以下代码:

src = numpy.array(cornersSheet, numpy.float32)
dst = numpy.array(cornersDesired, numpy.float32)
transform = cv2.getPerspectiveTransform(src,dst)
finished = cv2.warpPerspective(img, transform, img.shape)

Python 说:

Traceback (most recent call last):
File "./script.py", line 138, in <module>
    finished = cv2.warpPerspective(img, transform, img.shape)
TypeError: function takes exactly 2 arguments (3 given)

但根据文档:

    Python: cv2.warpPerspective(src, M, dsize[, dst[, flags[, borderMode[, borderValue]]]]) → dst

三个参数没问题。我在使用cv2.warpAffine时遇到了相同的问题。

2个回答

27

问题已解决。img.shape 返回一个包含3个元素的元组,而 warpPerspective 需要一个包含2个元素的元组。


5

试试这个

finished = cv2.warpPerspective(img, transform, img.shape[1::-1])

[1::-1] 的意思是什么? - tomfriwel
1
@tomfriwel 在Python中,列表索引是[begin:end:step],因此[1::-1]表示从第二个元素(索引从0开始)到末尾,反向。请参见https://dev59.com/D3RB5IYBdhLWcg3wyqOo - Adam Trhon

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接