import numpy as np
import pyautogui
import cv2
import time
import sys
from PIL import ImageGrab
import directkeys
import pyscreenshot
cords = [0,1800, 160,1040]
mousepos = pyautogui.position()
print(mousepos)
green = (106,199,0)
low_red = np.array([161,155,84])
high_red = np.array([179,255,255])
screen = ImageGrab.grab(bbox=cords)
screenrgb = screen.convert('RGB')
while True:
for y in range(screenrgb.height):
for x in range(screenrgb.width):
r, g , b = screenrgb.getpixel(x1,y2)
if (r,g,b) == green:
pyautogui.click(screenrgb.getpixel(x1,y2))
这是我的代码,但是我看不到为什么程序没有单击鼠标或将鼠标移到所需位置
答案 0 :(得分:0)
您正在使用x1
和y1
而不在代码中对其进行定义。
如果您想使用x
和y
(如果您刚刚在for
子句中定义了它,
您应该使用x
,y
而不是x1
和y1
。
import numpy as np
import pyautogui
import cv2
import time
import sys
from PIL import ImageGrab
import directkeys
import pyscreenshot
cords = [0,1800, 160,1040]
mousepos = pyautogui.position()
print(mousepos)
green = (106,199,0)
low_red = np.array([161,155,84])
high_red = np.array([179,255,255])
screen = ImageGrab.grab(bbox=cords)
screenrgb = screen.convert('RGB')
while True:
for y in range(screenrgb.height):
for x in range(screenrgb.width):
r, g , b = screenrgb.getpixel(x,y)
if (r,g,b) == green:
pyautogui.click(screenrgb.getpixel(x,y))