我正在使用MSS捕获屏幕截图。(因为它捕获更快的截图)
但我不知道如何去捕捉一个特定的窗口在Mac上,我知道他们有win32为Windows用户。他们的代码我现在只是一个不断循环捕获我的主监视器。
网址:main.py
import cv2 as cv
import numpy as np
from time import time
from mss import mss
def window_capture():
loop_time = time()
with mss() as sct:
monitor = {"top": 40, "left": 0, "width": 800, "height": 600}
while(True):
screenshot = np.array(sct.grab(monitor))
screenshot = cv.cvtColor(screenshot, cv.COLOR_RGB2BGR)
cv.imshow('Computer Vision', screenshot)
print('FPS {}'.format(1 / (time() - loop_time)))
loop_time = time()
if cv.waitKey(1) == ord('q'):
cv.destroyAllWindows()
break
window_capture()
print('Done.')
字符串
3条答案
按热度按时间ewm0tg9j1#
我写了下面的
ObjectiveC
,它获取了macOS中所有窗口的名称,所有者,窗口ID和屏幕上的位置。我将其保存为windowlist.m
,并使用文件顶部注解中的命令编译它:字符串
它的输出如下所示,每行的最后4项分别是窗口的左上角、高度和宽度。您可以使用Python的
subprocess.Popen()
“as” 运行此程序并获取窗口列表,或者您可以使用PyObjc
Python模块将其转换为Python:型
lvjbypge2#
字符串
MacOS的问题解决方案,很容易找到Windows的答案,但Mac就不是了。这是代码的人。Solid 40fps.如果你用cv2或pyautogui做同样的事情,它会给出5fps。
yx2lnoni3#
如果你想打开Chrome浏览器,可以使用Python内置包webbrowser。您需要提供一个路径到Chrome应用程序,例如:第一个月
一旦浏览器打开,应用程序的位置将是它离开的地方。MSS不允许您选择应用程序。相反,您可以抓取整个屏幕或设置的位置(如您指定的
monitor = {"top": 40, "left": 0, "width": 800, "height": 600}
)。因此,您可能希望强制浏览器全屏显示。这可以通过使用pyautogui包中的热键来实现。字符串
(* 注意:我只在Windows上测试过,但应该可以在MacOS上运行 *)