简体   繁体   中英

the fastest method of capturing full screen with python?

I was using ImageGrab from PIL, but this is too slow to use for the project.

Are there any alternatives without using PIL?

Capturing an image is equivalent to capture a single frame of a video. You can do it using the VideoCapture method of OpenCV.

import cv2

cap = cv2.VideoCapture(0) # video capture source camera (Here webcam of laptop) 
ret,frame = cap.read() # return a single frame in variable `frame`

while(True):
    cv2.imshow('img',frame) #display the captured image
    if cv2.waitKey(1) & 0xFF == ord('y'): #save on pressing 'y' 
        cv2.imwrite('images/test.png',frame)
        cv2.destroyAllWindows()
        break

cap.release()

Check the OpenCV tutorial for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM