错误:(209:输入参数的大小不匹配)

2024-05-19 17:07:40 发布

您现在位置:Python中文网/ 问答频道 /正文

每次运行底部文件时都会出现此错误。奇怪的是,当我把它穿过一个终端时,它运行得很好。然而,当我通过基于web的IDE运行它时,我得到了错误。你知道吗


import cv2
import sys

num_down = 2       # number of downsampling steps
num_bilateral = 7  # number of bilateral filtering steps

img_rgb = cv2.imread(sys.argv[1])

# downsample image using Gaussian pyramid
# We use _ in range because we don't care about the actual index
img_color = img_rgb
for _ in range(num_down):
    img_color = cv2.pyrDown(img_color)

# repeatedly apply small bilateral filter instead of applying one large filter
for _ in range(num_bilateral):
    img_color = cv2.bilateralFilter(img_color, d=9, sigmaColor=9, sigmaSpace=7)

# upsample image to original size
for _ in range(num_down):
    img_color = cv2.pyrUp(img_color)

img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_RGB2GRAY)
img_blur = cv2.medianBlur(img_gray, 7)

# detect and enhance edges
img_edge = cv2.adaptiveThreshold(img_blur, 255,
                                 cv2.ADAPTIVE_THRESH_MEAN_C,
                                 cv2.THRESH_BINARY,
                                 blockSize=9,
                                 C=2)


# convert back to color, bit-AND with color image
img_edge2 = cv2.cvtColor(img_edge, cv2.COLOR_GRAY2RGB)
img_cartoon = cv2.bitwise_and(img_color, img_edge2)

# save
cv2.imwrite(sys.argv[2], img_cartoon)


Traceback (most recent call last): File "blur.py", line 36, in img_cartoon = cv2.bitwise_and(img_color, img_edge2) cv2.error: OpenCV(4.1.0) /io/opencv/modules/core/src/arithm.cpp:229: error: (-209:Sizes of input arguments do not match) The operation is neither 'array op array' (where arrays have the same size and type), nor 'array op scalar', nor 'scalar op array' in function 'binary_op'


Tags: andofinimageimgsysrangergb