如何根据图像的RBG颜色获得的坐标点击站点?
我正在尝试为游戏创建一种机器人,其中球体随机出现在某个位置,球体具有特定的颜色,因此我可以将它们放在RGB中。但是,当我尝试将它们发送到功能时,什么也不会发生。
这是代码,我在做什么错?
我有1周的时间学习python。
from ppadb.client import Client
import time
import keyboard
from pyautogui import *
import pyautogui
client = Client(host="127.0.0.1",port=5037)
devices = client.devices()
device_0 = devices[0]
def click(x,y):
inpu = 'input tap'
device_0.shell(inpu + ' ' + str(x) + ' ' + str(y))
while keyboard.is_pressed('q') == False:
pic = pyautogui.screenshot(region=(1285,65,450,690))
width, height = pic.size
for x in range(0,width,5):
for y in range(0,height,5):
r,g,b = pic.getpixel((x,y))
if b == 129:
click(x+1285, y+65)
time.sleep(5)
break
I am trying to create a kind of bot for a game in which spheres randomly appear in a certain place, the spheres have a specific color, so I can place them with RGB; however, when I try to send them to the function, nothing happens.
This is the code, what am I doing wrong?
I have 1 week learning python in a self-taught way.
from ppadb.client import Client
import time
import keyboard
from pyautogui import *
import pyautogui
client = Client(host="127.0.0.1",port=5037)
devices = client.devices()
device_0 = devices[0]
def click(x,y):
inpu = 'input tap'
device_0.shell(inpu + ' ' + str(x) + ' ' + str(y))
while keyboard.is_pressed('q') == False:
pic = pyautogui.screenshot(region=(1285,65,450,690))
width, height = pic.size
for x in range(0,width,5):
for y in range(0,height,5):
r,g,b = pic.getpixel((x,y))
if b == 129:
click(x+1285, y+65)
time.sleep(5)
break
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您也可以使用 androidViewClient/culebra 仅对脚本进行一些更改,该更改可用于您的脚本
注意,该更改可与您一起使用,这要么可用模拟器或真实设备,因为它没有从计算机中获取屏幕截图。
You can also use AndroidViewClient/culebra only doing a few changes to your script
Notice that this works either with an emulator or a real device as it's not getting the screenshot from your computer.