简体   繁体   English

RGB是从ImageGrab获取的吗。grab()。load()是数组还是字符串

[英]Is RGB taken from ImageGrab.grab().load() is in array or string

I am making a bot in python. 我正在用python制作机器人。 I want to compare the colors of a particular pixel with another color which is (83, 83, 83). 我想将特定像素的颜色与(83,83,83)的另一种颜色进行比较。

I tried comparing with a string with single and double quotes. 我尝试与单引号和双引号的字符串进行比较。 It didn't work so I thought that it could be an array. 它没有用,所以我认为它可能是一个数组。

This is my code of the bot 这是我的机器人代码

import pyautogui as py
from PIL import ImageGrab


def pressspace():
    py.keyDown('space')
    py.keyUp('space')

def jump():
    px=ImageGrab.grab().load()
    color=px[207,445]

    if color=='(83, 83, 83)':




        pressspace()

while True:
    jump()

It just didn't work and didn't press the space. 只是没有用,没有按空格。 I have imported all dependencies also. 我也导入了所有依赖项。 Please Help and tell that is it an array and if yes, than how to compare.(Note: rest time the color is (247, 247, 247)) 请帮助并告诉它它是一个数组,如果是,则比如何比较。(注意:休息时间的颜色是(247,247,247))

Keep in mind you didn't state what 'py' in pressspace() is and does for your code snippet. 请记住,您并未说明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.

In my case its an <class 'tuple'> 就我而言,它是一个<class 'tuple'>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM