我正在用python制作机器人。我想将特定像素的颜色与另一种颜色(83,83,83)进行比较。
我尝试将单引号和双引号的字符串进行比较。它没有用,所以我认为它可能是一个数组。
这是我的机器人代码
import tensorflow as tf
with tf.Graph().as_default(), tf.Session() as sess:
x = tf.placeholder(tf.float32, shape=[None])
y = tf.placeholder(tf.float32, shape=[None])
z = tf.placeholder(tf.float32, shape=[None])
ones = tf.ones_like(x)
r = tf.where(x < y, 17 * ones, tf.where(x > z, 23 * ones, -ones))
print(sess.run(r, feed_dict={x: [0, 1, 2, 3], y: [1, 1, 1, 1], z: [2, 2, 2, 2]}))
# [17. -1. -1. 23.]
它只是没有用,也没有按空格。我也导入了所有依赖项。请帮助,并告诉它它是一个数组,如果是,那么不如不进行比较。(注意:休息时间颜色为(247,247,247))
答案 0 :(得分:2)
请记住,您没有说明pressspace()中的“ py”是什么,也不针对代码段进行声明。
import sys, time
from PIL import ImageGrab
def pressspace():
py.keyDown('space')
py.keyUp('space')
def jump():
px=ImageGrab.grab().load()
color=px[207,445]
c1, c2, c3 = color # just a thought: if included you can compare and print each
# of them to see if they fit a certain value of your liking.
if color==(83, 83, 83):
print ('1 - type: ', type(color))
else:
print ('2 - type: ', type(color))
print (color) # just to print always the color
time.sleep(1) # pause it for one second to prevent SPAM in the output.
# pressspace()
while True:
jump()
sys.stdout.flush() # forces to print directly the result from within an editor if used.
在我的情况下,它是<class 'tuple'>