我是新來的opencv。我有多個圖像。示例圖像之一,如左下角所示。基本上我想分離背景和前景,以便邊緣清晰,並且可以正確檢測輪廓。OpenCV python郵票過濾器photoshop
我已經嘗試了許多過濾器,當然使用各種參數的閾值。
最後,當我一直在尋找的Photoshop濾鏡庫我注意到一個過濾器稱爲郵票這是給我想要的結果(右上角)。它使邊緣清晰,我想用一些模糊的軟角落。
我不知道如何獲得與使用python CV2的photoshop郵票過濾器相同的操作?
任何幫助或建議將不勝感激。
原始數據不變圖片
嘗試1: - 代碼
import cv2
import numpy as np
from matplotlib import pyplot as plt
input_img = cv2.imread('images/Tas/t3.bmp')
desired_img = cv2.imread('images/stamp.jpg')
# gray scale
gray = cv2.cvtColor(input_img, cv2.COLOR_BGR2GRAY)
kernel = np.ones((3,3),np.uint8)
thresh1 = cv2.threshold(input_img,80,255,cv2.THRESH_BINARY)[1]
erosion1 = cv2.erode(thresh1,kernel,iterations = 1)
dilation1 = cv2.dilate(erosion1,kernel,iterations = 1)
thresh2 = cv2.threshold(input_img,120,255,cv2.THRESH_BINARY)[1]
erosion2 = cv2.erode(thresh2,kernel,iterations = 1)
dilation2 = cv2.dilate(erosion2,kernel,iterations = 1)
titles = ['Original', 'Desired','thresh1', 'erosion1','dilation1','thresh2','erosion2','dilation2']
images = [input_img, desired_img, thresh1, erosion1,dilation1, thresh2,erosion2, dilation2]
for i in xrange(8):
plt.subplot(2,4,i+1),plt.imshow(images[i])
plt.title(titles[i])
plt.xticks([]),plt.yticks([])
plt.show()
輸出:
它看起來像一個二值化,並可能侵蝕和擴張。顯示原始的原始圖像也 –
嗨@AnderBiguri剛剛添加了原始圖像。 – VK321
@AnderBiguri ..有什麼幫助? – VK321