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:
cv2.TM_CCOEFF_NORMED
:相较于其它方法,通常被认为具有较好的鲁棒性