だから、スタックオーバーフローメンバーの助けを借りて、私は次のコードを持っています:
data = "needle's (which is a png image) base64 code goes here"
decoded = data.decode('base64')
f = cStringIO.StringIO(decoded)
image = Image.open(f)
needle = image.load()
while True:
screenshot = ImageGrab.grab()
haystack = screenshot.load()
if detectImage(haystack, needle):
break
else:
time.sleep(5)
針が干し草の山にあるかどうかを確認するために、次のコードを作成しました。
def detectImage(haystack, needle):
counter = 0
for hayrow in haystack:
for haypix in hayrow:
for needlerow in needle:
for needlepix in needlerow:
if haypix == needlepix:
counter += 1
if counter == 980: #the needle has 980 pixels
return True
else:
return False
問題は、3 行目で次のエラーが発生することです: 'PixelAccess' object is not iterable
needle と haystack の両方を numpy/scipy 配列にコピーする方が簡単であると提案されました。次に、2D 配列の針が 2D 配列の干し草の山内にあるかどうかを確認する関数を使用できます。
次のことについて助けが必要です:
1) これらの配列を numpy 配列に変換します。
2) 2D アレイの針が 2D アレイの干し草の山内にあるかどうかを確認する関数。私の機能は動作しません。