0
def boardcords(img1, img2):
img1 = asarray(img1) #what your looking for
img2 = asarray(img2) #big
img2y=img2.shape[0]
img2x=img2.shape[1]
stopy=img2y-img1.shape[0]+1
stopx=img2x-img1.shape[1]+1
for x1 in range(0,stopx):
for y1 in range(0,stopy):
x2=x1+img1.shape[1]
y2=y1+img1.shape[0]
pic=img2[y1:y2,x1:x2]
test=pic==img1
if test.all():
return x1, y1
bx, by = boardcords(Image.open('small.png'),Image.open('test.png'))
print (bx, by)
bx2, by2 = boardcords((Image.open('small2.png')),Image.open('test.png'))
print (bx2, by2)
這隻適用於某些原因。它成功地找到的圖像的第一次測試,而不是第二,給下面的錯誤在圖像中查找圖像
AttributeError: 'bool' object has no attribute 'all'
http://s000.tinyupload.com/index.php?file_id=08383055927431033826
圖像如果必要
我試過,然後它不工作的第一個或秒 – Adamater