import time
import cv2
import mss
import numpy
with mss.mss() as sct:
# Part of the screen to capture
monitor = {'top': 40, 'left': 0, 'width': 800, 'height': 640}
while 'Screen capturing':
last_time = time.time()
# Get raw pixels from the screen, save it to a Numpy array
img = numpy.array(sct.grab(monitor))
# Display the picture
cv2.imshow('OpenCV/Numpy normal', img)
# Display the picture in grayscale
# cv2.imshow('OpenCV/Numpy grayscale',
# cv2.cvtColor(img, cv2.COLOR_BGRA2GRAY))
print('fps: {0}'.format(1 / (time.time()-last_time)))
# Press "q" to quit
if cv2.waitKey(25) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break
我不知道用Python执行屏幕录制的机制。但是,您可以使用Python来控制现有的许多屏幕录制程序之一:
对于使用python进行屏幕录制,使用MSS是一个很好的选择。
例如,使用http://python-mss.readthedocs.io/examples.html中的代码,我得到的平均fps为60。
recordscreen.py是用于avconv的命令行选项包装器(以前用于ffmpeg)视频捕获/转换工具。在纯Python中实现这一点太慢了,但是当然您可以为那些工具创建有用的绑定,或者改进现有的绑定,比如AVBin。
相关问题 更多 >
编程相关推荐