如果匹配,我不确定这是否可能在 cv2 中查看特定的行打印位置。
当我尝试比较模板图像时,它正在比较主图像内的整个模板图像(整个块都是白色和黑色)。正因为如此,模板在 70% 的阈值处不匹配。
有什么办法可以让 cv2 不比较整个模板图像而只比较黑线?如下图所示的线条无法识别模板图像,因为在主图像上有一些额外的线条
有谁熟悉如何解决这个问题?
这是我的代码:
import cv2
import numpy as np
threshold = 75
img_rgb = cv2.imread("master_image.bmp")
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
template = cv2.imread("7test.png",0)
w, h = template.shape[::-1]
res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
location = np.where(res >= threshold)