【发布时间】:2021-03-08 17:53:56
【问题描述】:
我想检测包含数字的圆圈。我尝试了圆形检测(霍夫方法),但结果非常糟糕。所以我尝试了模板匹配并得到了更好的结果。但是,仍然有很多圈子错过了。 这是我的代码
import cv2
import numpy as np
from matplotlib import pyplot as plt
from PIL import Image
from numpy import asarray
img = cv2.imread(r'D:\RealPython\facedetectionOpenCV\dataset\dataset_qxgtuu.png')
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
template = cv2.imread(r'D:\RealPython\facedetectionOpenCV\tam.PNG',0)
w, h = template.shape[::-1]
numpydata = asarray(template)
mean= np.mean(numpydata, axis=(0,1))
res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED)
threshold = 0.6
loc = np.where( res >= threshold)
for pt in zip(*loc[::-1]):
cv2.rectangle(img, pt, (pt[0] + w, pt[1] + h), (255,0,0), 2)
cv2.imshow("Detected Circle", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imwrite('res.png',img)
这是我得到的:https://ibb.co/Rcg2gPk
【问题讨论】:
标签: python opencv computer-vision