如何根据图像的RBG颜色获得的坐标点击站点?

发布于 2025-02-03 21:19:44 字数 858 浏览 3 评论 0原文

我正在尝试为游戏创建一种机器人,其中球体随机出现在某个位置,球体具有特定的颜色,因此我可以将它们放在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野鹿林 2025-02-10 21:19:44

您也可以使用 androidViewClient/culebra 仅对脚本进行一些更改,该更改可用于您的脚本

#! /usr/bin/env python3

import keyboard
import time
from PIL import Image

from com.dtmilano.android.viewclient import ViewClient, KEY_EVENT

device, serialno = ViewClient.connectToDeviceOrExit()

while keyboard.is_pressed('q') == False:
    img = device.takeSnapshot(reconnect=True)
    w, h = img.size
    for x in range(0, w, 5): 
        for y in range(0, h, 5):
            r, g, b, a = img.getpixel((x, y))
            if b == 129:
                device.touch(x, y)
                time.sleep(5)
                break

注意,该更改可与您一起使用,这要么可用模拟器或真实设备,因为它没有从计算机中获取屏幕截图。

You can also use AndroidViewClient/culebra only doing a few changes to your script

#! /usr/bin/env python3

import keyboard
import time
from PIL import Image

from com.dtmilano.android.viewclient import ViewClient, KEY_EVENT

device, serialno = ViewClient.connectToDeviceOrExit()

while keyboard.is_pressed('q') == False:
    img = device.takeSnapshot(reconnect=True)
    w, h = img.size
    for x in range(0, w, 5): 
        for y in range(0, h, 5):
            r, g, b, a = img.getpixel((x, y))
            if b == 129:
                device.touch(x, y)
                time.sleep(5)
                break

Notice that this works either with an emulator or a real device as it's not getting the screenshot from your computer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文