【发布时间】:2021-11-23 22:12:41
【问题描述】:
在执行模板匹配时,显示的输出尺寸非常小,无法确定边界框在哪里,如何在显示输出时显示更大的图像?
这是我的代码:
import cv2
import numpy as np
from matplotlib import pyplot as plt
%matplotlib inline
img_rgb = cv2.imread('ddd/radiobutton.png')
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
template = cv2.imread('ddd/temp.png', 0)
height, width = template.shape[::]
res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
plt.imshow(res, cmap='gray')
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
top_left = min_loc
bottom_right = (top_left[0]+ width, top_left[1]+height)
# cv2.rectangle(img_rgb, top_left, bottom_right, (255, 0, 0), 2)
cv2.rectangle(img_rgb, top_left, bottom_right, (255, 0, 0), 10)
cv2.imshow("Matched image", img_rgb)
plt.imshow(img_rgb)
plt.show(1900,2000)
【问题讨论】:
标签: python opencv matplotlib