Bil*_*lah 8 python opencv numpy scale computer-vision
有没有更有效的方法来对不同尺寸的图像使用模板匹配?这是我当前的脚本:
import cv2
import numpy as np
img_bgr = cv2.imread('./full.jpg')
img_gray = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2GRAY)
template = cv2.imread('./template.jpg', 0)
w, h = template.shape[::-1]
res = cv2.matchTemplate(img_gray, template,
cv2.TM_CCOEFF_NORMED)
threshold = 0.8
loc = np.where(res >= threshold)
for pt in zip(*loc[::-1]):
cv2.rectangle(img_bgr, pt, (pt[0]+w, pt[1]+h), (0,255,255), 2)
cv2.imshow('detected', img_bgr)
cv2.waitKey(0)
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)
这是我的模板: 模板
我有这些图像,第一个有效,第二个无效,因为尺寸:
起初,我认为它失败了,因为模板与图像的大小
所以我尝试使用本教程:Multi Scale Matching
但这看起来真的很慢而且很笨重,特别是因为我打算在它工作时在视频中使用它。有没有更好的方法来处理这个
此外,最终我也只想检查图像的右上角,我知道这是一个完全不同的问题,但是如果您有任何想法,因为我们正在谈论缩放:)
归档时间: |
|
查看次数: |
6339 次 |
最近记录: |