如何在Python,Pyautogui中访问屏幕截图图像?

时间:2020-09-07 04:03:57

标签: python pyautogui

我正在使用pyautogui截图当前屏幕,我想知道是否可以通过剪贴板访问该图像以进行进一步处理? 代码:

import pyautogui
import time
x = 1
while x < 4:
    capture = pyautogui.screenshot('/Users/Desktop/Screen/image'+str(x)+'.png')
    x += 1
    time.sleep(2)

谢谢。

1 个答案:

答案 0 :(得分:2)

是的,可以粘贴。通常,要利用图像,可以使用OpenCv将其转换为Standalone WSGI Containers的cv2图像数组:

import pyautogui
import time
import cv2
import numpy as np
x = 1
while x < 4:

    capture = pyautogui.screenshot('saved_'+str(x)+'.png')
    capture = cv2.cvtColor(np.array(capture), cv2.COLOR_RGB2BGR)
    cv2.imshow("image",capture)
    cv2.waitKey(0)

    x += 1
    time.sleep(2)