发布于 2017-11-22 19:19:39
下面是使用Python和Python图像操作库枕头的一种简单方法。程序一次扫描较大的图像一个像素,寻找与较小图像的确切副本。
import sys
from PIL import Image
import numpy as np
haystack, needle = (np.array(Image.open(x)) for x in sys.argv[1:3])
for y in range(haystack.shape[0] - needle.shape[0]):
for x in range(haystack.shape[1] - needle.shape[1]):
if np.array_equal(
haystack[y : (y + needle.shape[0]), x : (x + needle.shape[1])],
needle):
print("Found at", (x, y))
exit()
print("Not found")在我的机器上作为python3 subimage.py Capture01.png referenceSamplePic.png调用时,它将在大约2秒后打印Found at (426, 128)。
https://softwarerecs.stackexchange.com/questions/47152
复制相似问题