You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

OpenCV多模板匹配优化:地图Fiducial Marks识别精度提升问询

地图基准标记(Fiducial Marks)模板匹配优化求助

我需要识别地图上的4个相同基准标记(Fiducial Marks),目前通过网络资料实现了初步功能,但匹配效果远未达标。

已尝试的优化方式:

  • 调整阈值
  • 尝试不同cv2模板匹配方法
  • 缩小图像与模板尺寸

以下是我的代码:

import cv2
import numpy as np
from imutils.object_detection import non_max_suppression
  
# Reading and resizing the image
big_image = cv2.imread('20221028_093830.jpg')
 
scale_percent = 10 # percent of original size
width = int(big_image.shape[1] * scale_percent / 100)
height = int(big_image.shape[0] * scale_percent / 100)
dim = (width, height)

img = cv2.resize(big_image, dim, interpolation = cv2.INTER_AREA)

temp = cv2.imread('try_fiduc.png')
  
# save the image dimensions
W, H = temp.shape[:2]
  
# Converting them to grayscale
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
temp_gray = cv2.cvtColor(temp, cv2.COLOR_BGR2GRAY)

# Blur the image
img_blurred = cv2.GaussianBlur(img_gray, (7, 7), 0)

# Increasing contrast
img_contrast = img_blurred*3

# Passing the image to matchTemplate method
match = cv2.matchTemplate(
    image=img_contrast, templ=temp_gray, 
    method=cv2.TM_CCOEFF
)

# Define a minimum threshold
thresh = 6000000

# Select rectangles with confidence greater than threshold
(y_points, x_points) = np.where(match >= thresh)
  
# initialize our list of rectangles
boxes = list()
  
# loop over the starting (x, y)-coordinates again
for (x, y) in zip(x_points, y_points):
    # update our list of rectangles
    boxes.append((x, y, x + W, y + H))
  
# apply non-maxima suppression to the rectangles
# this will create a single bounding box
boxes = non_max_suppression(np.array(boxes))
  
# loop over the final bounding boxes
for (x1, y1, x2, y2) in boxes:
    # draw the bounding box on the image
    cv2.rectangle(img, (x1, y1), (x2, y2), (255, 0, 0), 3)
  
# Show the template and the final output
cv2.imshow("Template", temp_gray)
cv2.imshow("Image", img_contrast)
cv2.imshow("After NMS", img)
cv2.waitKey(0)
  
# destroy all the windows manually to be on the safe side
cv2.destroyAllWindows()

相关图像

  • 模板图:基准标记模板
  • 待识别图像:待识别地图
  • 当前匹配结果:匹配结果

请问还有哪些方法可以优化模板匹配?最终我希望能够实现远距离识别,且无匹配错误,恳请提供帮助。


内容的提问来源于stack exchange,提问作者Annelotte

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 18:43:12