问题描述
首先我知道这个线程存在:
How to count the number of objects detected with Template Matching?
但我不知道为什么给出的解决方案在我的应用程序中不起作用
我已关注此http://docs.opencv.org/3.1.0/d4/dc6/tutorial_py_template_matching.html
我想做什么:
https://i.imgur.com/vc2jXu0.png 我想要这张图片中的内容
https://i.imgur.com/BbKKCjv.png 所有这些符号都被计算在内。
Atm,我只成功地将它们染成蓝色:
import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt
img_rgb = cv.imread('plan3.png')
img_gray = cv.cvtColor(img_rgb,cv.COLOR_BGR2GRAY)
template = cv.imread('template2.png',0)
w,h = template.shape[::-1]
res = cv.matchTemplate(img_gray,template,cv.TM_CCOEFF_norMED)
threshold = 0.8
loc = np.where( res >= threshold)
for pt in zip(*loc[::-1]):
cv.rectangle(img_rgb,pt,(pt[0] + w,pt[1] + h),(0,255),2)
cv.imwrite('res.png',img_rgb)
plt.imshow(img_rgb)
plt.show()'
https://i.imgur.com/iE10p1e.png 它给了我
所以我认为我还没有做我想做的事情,但是当我尝试在我提到的线程上调整代码时,它不起作用。
我尝试添加
found_count = len(loc)
print(len(loc))
但它什么也没做,没有错误。
我确实是个新手
预先感谢您的帮助!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)