1

我遇到了 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()

![https://imgur.com/a/N6RMy4T](https://imgur.com/a/N6RMy4T)

生成的图像:https ://imgur.com/a/N6RMy4T 。

4

0 回答 0