使用 OpenCV 和 Python-2.7 进行屏幕捕获

2023-12-22

我在用着Python 2.7 and OpenCV 2.4.9.

我需要捕获向用户显示的当前帧并将其加载为cv::Mat


这是我使用@Raoul 技巧编写的解决方案代码。

我使用 PIL ImageGrab 模块来抓取打印屏幕帧。

import numpy as np
from PIL import ImageGrab
import cv2

while(True):
    printscreen_pil =  ImageGrab.grab()
    printscreen_numpy =   np.array(printscreen_pil.getdata(),dtype='uint8')\
    .reshape((printscreen_pil.size[1],printscreen_pil.size[0],3)) 
    cv2.imshow('window',printscreen_numpy)
    if cv2.waitKey(25) & 0xFF == ord('q'):
        cv2.destroyAllWindows()
        break
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 OpenCV 和 Python-2.7 进行屏幕捕获 的相关文章

随机推荐