我对OpenCV有一个问题,其中函数形态学打开未按预期工作。如下图所示,图像的形态学打开会导致阈值模式向下和向右移动
你知道为什么会发生这种移动吗
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread("originalImg.png")
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret,thresh1 = cv2.threshold(img,0,255,cv2.THRESH_TRIANGLE)
print("Calculated threshold", ret)
f, axarr = plt.subplots(1,5)
kernel = np.ones((2,2),np.uint8)
thresh = thresh/255
opened = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, kernel)
axarr[0].imshow(img,cmap='gray')
axarr[0].set_title('original image')
axarr[1].imshow(thresh1,cmap='gray')
axarr[1].set_title('threshold triangle')
axarr[2].imshow(opened,cmap='gray')
axarr[2].set_title('morphology open')
plt.show()
目前没有回答
相关问题 更多 >
编程相关推荐