Python ImageGrab和OpenCV

2024-05-01 04:11:33 发布

您现在位置:Python中文网/ 问答频道 /正文

当我运行下面的代码时,它会打开一个具有适当尺寸的新窗口,并正确地显示屏幕……但是它会不断地在顶部和内部打开新的窗口。在

import numpy as np
from PIL import ImageGrab
import cv2

while(True):
    printscreen_pil = ImageGrab.grab(bbox = (0, 40, 400, 340))
    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

系统为windows 10,64位 python 3.6


Tags: 代码fromimportnumpysizepil屏幕尺寸