【图像处理】模板匹配的学习笔记

OpenCV的模板匹配算法

  • cv.TM_CCOEFF
  • cv.TM_CCOEFF_NORMED
  • cv.TM_CCORR
  • cv.TM_CCORR_NORMED
  • cv.TM_SQDIFF
  • cv.TM_SQDIFF_NORMED

匹配代码模板

python 复制代码
image = cv2.imread(r"scene.png", cv2.IMREAD_GRAYSCALE)
template = cv2.imread(r"element.png", cv2.IMREAD_GRAYSCALE)
res = cv2.matchTemplate(img, template, cv2.TM_CCOEFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)

if max_val > 0.8:
    print("Detected")
else:
    print("Not detected")

Note:

  1. cv2.TM_CCOEFF_NORMED:相较于其它方法,通常被认为具有较好的鲁棒性
相关推荐
码农飞飞1 个月前
详解Rust枚举类型(enum)的用法
开发语言·rust·match·枚举·匹配·内存安全
master cat8 个月前
子串匹配--------c++
c++·匹配·子串