ImageGrab.grab()方法太慢 [英] ImageGrab.grab() method is too slow
问题描述
因此,我需要每秒获取一堆屏幕截图,例如5.我正在使用它来为游戏编写机器人程序.但是imagegrab方法大约需要0.3秒,这对我来说实在是太慢了.即使指定了bbox值,它仍然需要0.3秒.我想应该提到我在Mac上.对我来说有更好的方法吗?
So i need to get a bunch of screenshots every second, like 5. I am using it to program a bot for a game. However imagegrab method takes like 0.3 seconds, which is terribly slow for me. Even after specifying the bbox values it still takes like 0.3 seconds. I think should mention that I am on a mac. Is there a better way for me
我什至尝试了os.system("screencapture filename.png")
,它的运行时间为0.15-0.2秒,这很好,但是我想走得更快.
I even tried the os.system("screencapture filename.png")
which has a runtime of 0.15-0.2 seconds which is nice but I want to go faster.
推荐答案
所以我如何使用
os.system("screencapture -R0,0,100,100 filename.png")
im = Image.open("filename.png")
您可以在其中替换0,0,100,100的位置. 它的运行时间少于0.1s,更像是0.06s.
Where you can replace 0,0,100,100 accordingly. It had a run time of less than 0.1s, more like 0.06s.
这篇关于ImageGrab.grab()方法太慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!