1
我有一個地圖,其上有許多跨地圖上傳播的相似符號(樹)的。 I 我使用opencv來查找所有符號的X,Y座標。去除或防止複製模板匹配OpenCV中與Python
它的工作很好,但我得到的重複結果數量巨大。如果我增加過濾器閾值,重複數量會減少,因爲許多符號都會丟失。我已經嘗試編寫一些代碼來根據鄰近度篩選出結果,但我沒有太多運氣。有沒有人對我可以在這裏嘗試什麼有所瞭解?
img_rgb = cv2.imread('images/map.jpg')
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
template = cv2.imread('images/tree.jpg',0)
w, h = template.shape[::-1]
res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED)
threshold = 0.35
matches = np.where(res >= threshold)
tree_count = 0
for pt in matches:
tree_count += 1
cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (255,0,0), 1)
cv2.imwrite('found_map.jpg',img_rgb)
print "Done " + map