首页 > 解决方案 > 显示输出时使用opencv显示更大的图像尺寸

问题描述

在执行模板匹配时,显示的输出尺寸非常小,这无助于确定边界框的位置,如何在显示输出时显示更大的图像?

这是我的代码:

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)

这是一个屏幕截图,它将提供有关小尺寸输出的想法: 在此处输入图像描述

标签: pythonopencvmatplotlib

解决方案


您可以使用以下行更改图形大小:

plt.figure(figsize=(x, y))

参数xy需要设置,为您的特定图像。


推荐阅读