python : Detect Color Then Click Color

标签 python colors

我正在尝试截屏,检查屏幕截图中的某种颜色,如果找到该颜色,则单击它。

我遇到的问题是颜色的 RGB 值必须准确。

我想知道是否可以将图像转换为颜色很少的图像。

抱歉打扰了。我没有受过适当的训练。我现在只是沉迷于编码。

感谢您花时间阅读本文。

import os, sys
import Image, ImageGrab, ImageOps
import time, random
from random import randrange
import win32api, win32con
from numpy import *


# Globals
# ------------------

x_pad = 0
y_pad = 0


# Screen Grab Function
def screenGrab():
    b1 = (x_pad + 1,y_pad+1,x_pad+1921,y_pad+1081)
    im = ImageGrab.grab()
    ##im.save(os.getcwd() + '\\Snap__' + str(int(time.time())) +'.png', 'PNG')
    return im

## Grab Mouse Position
## MousePos = win32api.GetCursorPos()
## print MousePos

## Type in shell to grab RGB color
## im = screenGrab()
## im.getpixel(MousePos)

## Check Mouse Position for Black
## s = screenGrab()
## if s.getpixel(MousePos) <= (96, 96, 96):
    ##print "I see black."   

# Main 

x = 920
y = 465

# Color Check Then Stop/Click Loop

while True:

    s = screenGrab()
    s.convert("P", palette=Image.ADAPTIVE, colors=5)
    x = x + 10
    xy = (x, y)
    if s.getpixel(xy)== (255, 255, 255):
        break
    else:
        win32api.SetCursorPos((x, y))
        print x
        print y

        if x == 1250:
            x = 700
            y = y + 10
            if y == 985:
                break

如何正确使用“s.convert("P", palette=Image.ADAPTIVE, colors=5)”以便将颜色范围限制为 (0, 255, 0)?

最佳答案

而不是简化你的颜色,为什么在试图找到它是什么颜色时不给出 RGB 值的范围?

(range(200,220), range(200,220), range(200,220))

这会改变所有像素的 RGB 值。

关于 python : Detect Color Then Click Color,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23330178/

相关文章:

python - 使用 GitPython 列出特定 git 提交的目录内容

java - Robocode(java): how can I make my robot change color depending on the result of getEnergy()?

java - 为什么在使用 Flood Fill 算法时会出现 java.lang.StackOverflowError?

colors - CIELAB颜色空间中的坐标范围是多少?

python - 需要使用子进程模块在 2 个 NamedTemporaryFiles 上运行 diff 命令

python - 自定义添加方法在字符串插值期间失败

python tinder 机器人不会发送消息 - 网络错误

python - 在 python sqlite3 模块中导入数据文件(如.csv)的任何其他方式? [不一一插入]

algorithm - 是否有任何颜色生成算法?

colors - 透明背景的 Flutter 卡片