我在学习图像预处理的时候在着上面找了一个程序运行,早上还能跑,下午就报错了 import cv2 import numpy as np import matplotlib.pyplot as plt # 读取图片 img = cv2.imread('D:\image\gaosi.jpg', cv2.IMREAD_GRAYSCALE) source = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB) # 均值滤波 result1 = cv2.blur(source, (5, 5)) result2 = cv2.blur(source, (7, 7)) # 方框滤波 result3 = cv2.boxFilter(source, -1, (5, 5), normalize=1) result4 = cv2.boxFilter(source, -1, (7, 7), normalize=1) # 高斯滤波 result5 = cv2.GaussianBlur(source, (3, 3), 0) result6 = cv2.GaussianBlur(source, (15, 15), 0) # 中值滤波 result7 = cv2.medianBlur(source, 3) # 高斯双边滤波 result8 = cv2.bilateralFilter(source, 15, 50, 50) # 显示图形 titles = ['Source', 'Blur 5*5', 'Blur 7*7', 'BoxFilter 5*5', 'BoxFilter 7*7', 'GaussianBlur 3*3', 'GaussianBlur 15*15', 'medianBlur', 'bilateralFilter'] images = [source, result1, result2, result3, result4, result5, result6, result7, result8] fig = plt.figure(figsize=(10, 10)) # 设置大小 for i in range(9): plt.subplot(3, 3, i + 1), plt.imshow(images[i], 'gray') plt.title(titles[i]) plt.xticks([]), plt.yticks([]) plt.show() fig.savefig('fig.jpg', bbox_inches='tight')
报错结果:
img = cv2.imread('D:\image\gaosi.jpg', cv2.IMREAD_GRAYSCALE)
TypeError: imread() takes 1 positional argument but 2 were given