我想知道是什么意思 (height,width)=img.shape[:2]

时间:2021-02-01 10:12:12

标签: python numpy

我不知道这是什么意思

def rotate(img,angle,rotPoint=None):
    (height,width)=img.shape[:2]
    if rotPoint is None:
        rotPoint= (width//2,height//2)
    rotMate=cv.getRotationMatrix2D(rotPoint,angle,1.0)
    dimensions=(width,height)
    return cv.warpAffine(img,rotMate,dimensions)

我的意思是:

def rotate(img,angle,rotPoint=None):
    (height,width)=img.shape[:2]

我想要一些解释

2 个答案:

答案 0 :(得分:0)

shape 对象的 img 属性显然是一个包含一些图像数据的列表,这里的前两个元素被复制到变量 height 和 {{1} }.

答案 1 :(得分:0)

这取决于“img”对象的类型。你在用什么?我假设 opencv ?

然后对象的形状包含一个元组(rows, columns, channels)(height,width)=img.shape[:2] 是元组解包的示例,您可以使用它从形状元组中提取 rowscolumns 值。

相关问题