简体   繁体   English

使用 python 捕获全屏的最快方法?

[英]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.我使用的是 PIL 的 ImageGrab,但这对于项目来说太慢了。

Are there any alternatives without using PIL?有没有不使用 PIL 的替代方案?

Capturing an image is equivalent to capture a single frame of a video.捕获图像相当于捕获视频的单帧。 You can do it using the VideoCapture method of OpenCV.您可以使用 OpenCV 的 VideoCapture 方法来完成。

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.查看OpenCV教程了解更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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