如果输入的宽度和高度与resize输入和宽度相同,cv2.resize()会做什么?

5

我喜欢快速、紧凑的代码,所以我有一个问题:

def loader(input_path, new_img_width, new_img_height):
    input_image = tifffile.imread(input_path)
    input_image = cv2.resize(input_image, (new_img_width, new_img_height),
                           interpolation=cv2.INTER_NEAREST)
    return input_image

在调用cv2.resize之前,我需要添加一个条件语句来判断new_img_widthnew_img_height是否与input_image相同,或者这个条件语句已经包含在cv2.resize代码中了?

除非必要,否则我不想浪费时间调整图像大小。

1个回答

8

缩放函数的源代码,第4082行:

if (dsize == ssize)
{
    // Source and destination are of same size. Use simple copy.
    src.copyTo(dst);
    return;
}

1
所以如果我不想要一个不必要的副本,最好使用守卫语句。 - empty
1
是的,似乎调整大小函数总是返回一个新的Mat对象。 - unlut

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