每当我运行底部文件时,我都会收到此错误。奇怪的是,当我通过终端运行它时,它运行良好。但是,当我通过基于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)
回溯(最近一次通话最近):文件“ blur.py”,第36行,在 img_cartoon = cv2.bitwise_and(img_color,img_edge2)cv2.error:OpenCV(4.1.0)/io/opencv/modules/core/src/arithm.cpp:229:错误: (-209:输入参数的大小不匹配)操作都不是 'array op array'(其中数组具有相同的大小和类型),也不 函数'binary_op'中的'array op scalar'或'scalar op array'