使用CV2 识别CheckBox勾选符号

2023-03-17 10:54:08 浏览数 (1)

  1. 安装cv2 pip install opencv-python
  2. 选择匹配模板

temp.png

  1. 使用cv2匹配
代码语言:python代码运行次数:0复制
import cv2
import numpy as np
from matplotlib import pyplot as plt

# 待匹配
img = cv2.imread('1.png', 0)

# 匹配模板
template = cv2.imread('temp.png', 0)
h, w = template.shape

res = cv2.matchTemplate(img,template,cv2.TM_CCOEFF_NORMED)

# 相似度阀值
threshold = 0.7
loc = np.where( res >= threshold)
color = (33, 33, 0)
thickness = 2
for pt in zip(*loc[::-1]):
    cv2.rectangle(img, pt, (pt[0]   w, pt[1]   h), color, thickness)

cv2.imshow('thresh', img)
cv2.waitKey()

0 人点赞