【发布时间】:2021-09-13 19:22:59
【问题描述】:
如何使cv2.imshow 输出与plt.imshow 输出相同?
# loading image
img0 = cv2.imread("image.png")
# converting to gray scale
gray = cv2.cvtColor(img0, cv2.COLOR_BGR2GRAY)
# remove noise
img = cv2.GaussianBlur(gray, (3, 3), 0)
# convolute with proper kernels
laplacian = cv2.Laplacian(img, cv2.CV_64F)
sobelx = cv2.Sobel(img, cv2.CV_64F, 1, 0, ksize=5) # x
sobely = cv2.Sobel(img, cv2.CV_64F, 0, 1, ksize=5) # y
imgboth = cv2.addWeighted(sobelx, 0.5, sobely, 0.5, 0)
plt.imshow(imgboth, cmap='gray')
plt.show()
cv2.imshow("img", cv2.resize(imgboth, (960, 540)))
cv2.waitKey(0)
cv2.destroyAllWindows()
原图
plt.output
cv2.imshow
【问题讨论】:
-
使用浮点数,缩放值,然后添加 0.5 使 0 变为灰色。如果你愿意,我会回答。
-
请。您可以添加一个有效的答案吗? @克里斯托弗
标签: image opencv matplotlib