TypeError:dst不是一个numpy数组,也不是标量调整jpg python

时间:2017-09-09 03:59:55

标签: python numpy

我正在尝试调整图像大小以进行进一步的透视处理,我收到此错误。

File "/home/passerin/Documents/tesis/Project/test/scanner2/scan2.py", line 79, in resize
resized = cv2.resize(img, (height, width), interpolation)
TypeError: dst is not a numpy array, neither a scalar

这是代码......

# load an image
flat_object=cv2.imread("/home/passerin/Documents/tesis/Project/test/scanner2/images/personal-foto-5.png")
# resize the image
flat_object_resized = resize(flat_object, height=600)
# make a copy
flat_object_resized_copy = flat_object.copy()
#convert to HSV color scheme
flat_object_resized_hsv = cv2.cvtColor(flat_object_resized_copy, 
cv2.COLOR_BGR2HSV)
# split HSV to three chanels
hue, saturation, value = cv2.split(flat_object_resized_hsv)

这是出现错误的地方。

def resize(img, width=None, height=None, interpolation=cv2.INTER_AREA):
    global ratio
    w, h, _ = img.shape

    if width is None and height is None:
        return img
    elif width is None:
        ratio = height / h
        width = int(w * ratio)
        # print(width)
        resized = cv2.resize(img, (height, width), interpolation)
        return resized
    else:
        ratio = width / w
        height = int(h * ratio)
        # print(height)
        resized = cv2.resize(img, (height, width), interpolation)
        return resized

1 个答案:

答案 0 :(得分:3)

您正在使用位置参数进行调用,但根据您遗漏的argument specifcation - 它认为您的第三个位置参数是dst参数。即使参数/参数是可选的,如果你不用它们的关键字提供它们,该函数也希望它们按照argspec中给出的顺序。尝试使用关键字参数

调用它
cv2.resize(src = img, dsize = (height, width), interpolation = interpolation)

或只是

cv2.resize(img, (height, width), interpolation = interpolation)