如何解决什么是替代灰度值的替代方法?
我正在尝试制作一个机器人来读取 2048 游戏中的数据,并决定最佳动作。我已经为每个数字预设了灰度值。但不幸的是,空槽的灰度值和数字 512 是一样的。是否有任何简单的替代方法可以解决此问题?
The screenshot of the number 512
The screenshot of the empty slot
这是相关的代码:
class Values:
empty = 195
two = 230
four = 225
eight = 190
sixteen = 172
threeTwo = 154
sixFour = 136
oneTwoEight = 204
twoFiveSix = 200
fiveOneTwo = 195
oneZeroTwoFour = 193
twoZeroFourEight = 189
valueArray = [empty,two,four,eight,sixteen,threeTwo,sixFour,oneTwoEight,twoFiveSix,fiveOneTwo,oneZeroTwoFour,twoZeroFourEight]
screenImage = ImageGrab.grab()
grayScreenImage = ImageOps.grayscale(screenImage)
for index,cord in enumerate(Coordinates.coordinateArray):
pixel = grayScreenImage.getpixel(cord)
try:
position = Values.valueArray.index(pixel)
except:
position = 0
if position == 0:
currentGrid[index] = 0
else:
currentGrid[index] = 2 ** position
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。