gpt4 book ai didi

linux - pyscreenshot循环滞后显示

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:32:46 27 4
gpt4 key购买 nike

感谢阅读。

我有一个小应用程序,它具有从配置文件中获取信息的功能。例如 K:8 然后检查该键是否按下。它还将使用 P:255.255.255.0010.0010 然后 split(".") 并转换为 int 并检查 10X 位置是否有 RGB 255,255,255 的像素10 岁。

这是一个循环,它似乎工作正常,检查大约需要 0.2 秒。这足以满足我的需要,但我确实需要一个每秒进行几次检查的解决方案。我的问题 是循环执行此操作会导致显示延迟。好像显示减少到大约 2 FPS。所以想知道是否有人知道为什么会发生这种情况,或者我可以做些什么来解决它,同时仍然得到 0.3 秒以内的像素检查?

这是我的功能:

def conditionCheck():
if DataHeader[0][0][:2] == "B:": #Box limits in a string, split and convert to int.
bbox = DataHeader[0][0][2:]
bbox = bbox.split(".")
bboxx1 = int(bbox[0])
bboxy1 = int(bbox[1])
bboxx2 = int(bbox[2])
bboxy2 = int(bbox[3])
pixel = (pyscreenshot.grab(bbox=(bboxx1, bboxy1, bboxx2, bboxy2))).load() #Grab screen, within limits.
cp = 0
while cp < len(DataConditions): #cycle through config file list
rp = 0
conditionPass = 0
while rp < len(DataConditions[cp]): #Cycle through list item's conditions.
if DataConditions[cp][rp][:2] == "K:":
if keyboard.is_pressed(DataConditions[cp][rp][2:]): #Check if key down, set pass to true
conditionPass = 1
rp += 1 #Move to check next condition.
print("PRESSED") #DEBUG
continue
conditionPass = 0
break
if DataConditions[cp][rp][:2] == "P:": #pixel colour check, match = true
pixelData = DataConditions[cp][rp][2:] #pixel data and location in one string, conv to int and split.
pixelData = pixelData.split(".")
pixelLocation = pixel[int(pixelData[3]), int(pixelData[4])]
pixelData = pixelData[0], pixelData[1], pixelData[2]
if pixelLocation == tuple(map(int, pixelData)):
print("PASSED PIXEL") #DEBUG
conditionPass = 1
rp += 1
continue
conditionPass = 0
break
rp += 1
if conditionPass == 1:
return cp #end loop, send line of true condition (in config file)
cp += 1
return 0 #Return 0 if nothing found.

我在 Linux 上运行它,所以我需要一个跨平台/Linux 友好的解决方案。

想法:我有点菜鸟,所以请随时就其他方面提出建议。我知道我会在 C 中获得更快更流畅的结果,但我的应用程序的其他部分很难在 C 中实现(而且我的知识有限)所以我尝试看看这是否可以在 Python 中实现但也许开销太大了吗?

谢谢

最佳答案

一段时间后,我想我已经能够使用不同的插件找到解决方案,但方法相同。因此:

def conditionCheck():
if DataHeader[0][0][:2] == "B:": #Box limits in a string, split and convert to int.
bbox = DataHeader[0][0][2:]
bbox = bbox.split(".")
#bboxx1 = int(bbox[0])
#bboxy1 = int(bbox[1])
#bboxx2 = int(bbox[2])
#bboxy2 = int(bbox[3])
monitorWindow = {"top": int(bbox[0]), "left": int(bbox[1]), "width": int(bbox[2]), "height": int(bbox[3])}
with mss.mss() as sct: #Grab screen, within limits.
sct_img = sct.grab(monitorWindow)
img = Image.new("RGB", sct_img.size)
pixels = img.load()
for x in range(sct_img.width):
for y in range(sct_img.height):
pixels[x, y] = sct_img.pixel(x, y)
cp = 0
while cp < len(DataConditions): #cycle through config file list
rp = 0
conditionPass = 0
while rp < len(DataConditions[cp]): #Cycle through list item's conditions.
if DataConditions[cp][rp][:2] == "K:":
if keyboard.is_pressed(DataConditions[cp][rp][2:]): #Check if key down, set pass to true
conditionPass = 1
rp += 1 #Move to check next condition.
print("PRESSED") #DEBUG
continue
conditionPass = 0
break
if DataConditions[cp][rp][:2] == "P:": #pixel colour check, match = true
pixelData = DataConditions[cp][rp][2:] #pixel data and location in one string, conv to int and split.
pixelData = pixelData.split(".")
pixelLocation = pixels[int(pixelData[3]), int(pixelData[4])]
pixelData = pixelData[0], pixelData[1], pixelData[2]
if pixelLocation == tuple(map(int, pixelData)):
print("PASSED PIXEL") #DEBUG
conditionPass = 1
rp += 1
continue
conditionPass = 0
break
rp += 1
if conditionPass == 1:
return cp #end loop, send line of true condition (in config file)
cp += 1
return 0 #Return 0 if nothing found.

关于linux - pyscreenshot循环滞后显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55076605/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com