gpt4 book ai didi

python - 在Python中将plt.imshow()更改为cv2.imshow()

转载 作者:行者123 更新时间:2023-12-02 17:20:16 34 4
gpt4 key购买 nike

我有如下的python代码。

def konvolusi(self, X, F):
X_height = X.shape[0]
X_width = X.shape[1]
F_height = F.shape[0]
F_width = F.shape[1]
H = (F_height) // 2
W = (F_width) // 2
out = np.zeros((X_height, X_width))
for i in np.arange(H+1, X_height - H):
for j in np.arange(W+1, X_width - W):
sum = 0
for k in np.arange(-H, H+1):
for l in np.arange(-W, W+1):
a = X[i+k, j+l]
w = F[H+k, W+l]
sum += (w*a)
out[i,j] = sum
return out

def gaussianBlur(self):
img1 = self.image
gaussian = (1.0 / 345) * np.array(
[[1, 5, 7, 5, 1],
[5, 20, 33, 20, 5],
[7, 33, 55, 33, 7],
[5, 20, 33, 20,5],
[1, 5, 7, 5, 1]])
img = self.konvolusi(img1, gaussian)
self.image = img;
plt.imshow(img, cmap='gray', interpolation='bicubic')
plt.xticks([], plt.yticks([]))
plt.show()
在def gaussianBlur()中,使用 plt.imshow()函数显示img变量,如何使用 cv2.imshow()函数显示img变量?

最佳答案

您需要导入cv2

img = cv2.cvtColor(img,cv2.COLOR_RGB2BGR)
cv2.imshow('img',img)
cv2.waitKey(0)

关于python - 在Python中将plt.imshow()更改为cv2.imshow(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62577685/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com