【问题标题】:Find location of a symbol on an image with python使用python在图像上查找符号的位置
【发布时间】:2020-09-05 11:50:21
【问题描述】:

我正在尝试在我的图像上找到特定符号。例如,以此为例: Screenshot,我如何定位心形符号(如按钮)的位置?以像素为单位的位置,坐标系的原点位于左下角。我想通过使用python来di。非常感谢!

PS:喜欢的符号可以改变任何屏幕截图的位置

【问题讨论】:

  • 有两个心形符号,你的意思是两个?

标签: python image python-2.7 image-processing python-imaging-library


【解决方案1】:

如果它是一个简单的恒定大小且定义明确的图像,看起来是这样,您可以使用模板匹配

在 python 中有一个很好的Scikit Image module

简而言之:

from skimage.io import imread
from skimage.feature import match_template
from skimage.color import rgb2gray

image = imread('big_image.jpg')
template = imread('template.jpg')

image_gray = rgb2gray(image)
template_gray = rgb2gray(template)

result = match_template(image_gray, template_gray)
ij = np.unravel_index(np.argmax(result), result.shape)
x, y = ij[::-1]

【讨论】:

  • 非常感谢您的回复,它真的很有用,但是我想知道是否有更快的方法来找到那个心形符号的位置。 Skimage 在找到它方面做得很好,但是它有点慢。有什么建议吗?
  • 根据模板的像素大小、可区分性以及您需要的位置准确程度,一个简单的加速解决方案可能是在获取坐标之前对图像进行下采样。例如,如果您在每个方向上将采样率降低 2 倍(例如scipy.ndimage.zoom(image_gray, 0.5) 等),您可能会看到大约 4 倍的加速,并且您的位置将精确到最接近的 2 个像素。
猜你喜欢
  • 1970-01-01
  • 2012-12-24
  • 1970-01-01
  • 1970-01-01
  • 2011-02-15
  • 2016-11-23
  • 2020-03-12
  • 2011-03-09
  • 2011-01-05
相关资源
最近更新 更多