ImagegrabとImageStatを使用してPILでこれを行う方法が見つかりました。ここで、ゲームウィンドウの画面と作物をつかむためには:上記
def getScreen():
# Grab image and crop it to the desired window. Find pixel borders manually.
box = (left, top, right, bottom)
im = ImageGrab.grab().crop(box)
#im.save('testcrop.jpg') # optionally save your crop
for y in reversed(range(8)):
for x in reversed(range(8)):
#sqh,sqw are the height and width of each piece.
#each pieceim is one of the game piece squares
piecebox = (sqw*(x), sqh*(y), sqw*(x+1), sqh*(y+1))
pieceim = im.crop(piecebox)
#pieceim.save('piececrop_xy_'+ str(x) + str(y) + '.jpg')
stats = ImageStat.Stat(pieceim)
statsmean = stats.mean
Rows[x][y] = whichpiece(statsmean)
すべての64個分の画像を作成し、piecetype、配列「列」のアレイに記憶を識別する。次に、各piecetypeのstats.meanで平均RGB値を取得し、辞書(rgbdict)に格納しました。すべての出力をExcelにコピーし、カラータイプでフィルタリングして平均を取得します。次に、RSSメソッドとその辞書を使用して、既知のpiecetypeにイメージを統計的に一致させました。 (RSSのREF:http://www.charlesrcook.com/archive/2010/09/05/creating-a-bejeweled-blitz-bot-in-c.aspx)これらの二つの機能を持つ
rgbdict = {
'blue':[65.48478993, 149.0030965, 179.4636593], #1
'red':[105.3613444,55.95710092, 36.07481793], #2
......
}
def whichpiece(statsmean):
bestScore = 100
curScore= 0
pieceColor = 'empty'
for key in rgbdict.keys():
curScore = (math.pow((statsmean[0]/255) - (rgbdict[key][0]/255), 2)
+ math.pow((statsmean[1]/255) - (rgbdict[key][1]/255), 2)
+ math.pow((statsmean[2]/255) - (rgbdict[key][2]/255), 2))
if curScore < bestScore:
pieceColor = key
bestScore = curScore
return piececolor
画面が掻きすることができ、及び基板の状態を決定することができる移動する際にアレイに移します。これが誰にも役立つなら運が良ければ、移動ピッカーを微調整するかどうか教えてください。