gpt4 book ai didi

python - 在另一个图像中查找透明(png)图像

转载 作者:太空宇宙 更新时间:2023-11-03 15:17:04 40 4
gpt4 key购买 nike

我有一个屏幕截图,我需要在上面找到一些图像(始终具有相同的大小、旋转角度等)。我找到了一些 PIL 和 numpy 的解决方案,但它们只适用于非透明图像。我必须找到类似圆圈的东西,所以我必须在它后面使用透明背景。

示例图像如下所示:

enter image description here

我正在寻找这样的目标:

enter image description here

有什么想法可以实现吗?

最佳答案

由于您要精确匹配图像,因此很容易创建一个 slider 来找到目标。这不是最快的解决方案,但很容易开始工作。

import numpy as np
from scipy.misc import imread

screen = imread("screen.png")
target = imread("cookie.png")

def find_match(screen, target):
dx,dy,_ = target.shape

for x in xrange(screen.shape[0]-dx):
for y in xrange(screen.shape[1]-dy):
diff = (screen[x:x+dx,y:y+dy,:]-target)
dz = np.abs(diff).sum()
if dz == 0: return x,y, dx, dy
return None, None, None, None

x,y,dx,dy = find_match(screen, target)

# Show the result

import pylab as plt
plt.subplot(121)
plt.imshow(screen)

screen_sample = np.copy(screen)
screen_sample[x:x+dx,y:y+dy,:] = 0
plt.subplot(122)
plt.imshow(screen_sample)

plt.tight_layout()
plt.show()

enter image description here

关于python - 在另一个图像中查找透明(png)图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20291430/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com