2 回答

TA贡献1824条经验 获得超5个赞
如果在内循环中没有找到有效像素(因此没有发生),您可以使用该for-else构造,continue如果找到了,则可以使用外循环:breakbreak
for row, pxl in enumerate(pxls):
for col, pxll in enumerate(pxl):
if pxll == (102, 102, 102) and col >= 71 and col <= 328 and row <= 530 and row >= 378:
foundpxl = pxll
print(str(col) + " , " + str(row))
pyautogui.click(col, row)
break
else:
continue
break

TA贡献1859条经验 获得超6个赞
免责声明:我不熟悉 mss。你可以改进的几件事:
无需枚举您不感兴趣的值。您可以这样做:
for row, pxl in enumerate(pxls, start=378):
if row > 530:
break
for col, pxll in enumerate(pxl, start=71):
if col > 328:
break
你不能只截取所需区域的屏幕截图吗?这样的事情应该有效吗?
region = {'top': 378, 'left': 71, 'width': 328-71, 'height': 530-378}
您正在使用双 python 循环操作二维数组。您可以使用一些旨在对数组执行操作的模块,并且速度可以提高几个数量级。像 Pandas 或 NumPy 这样的东西应该能够几乎立即运行。
添加回答
举报