python 实现屏幕录制示例

yipeiwu_com6年前Python基础

PIL 即pollow 的安装命令如下:

pip install pillow

其中cv2的安装是下面这条命令

pip install opencv-python

代码实现:

# coding: utf-8
from PIL import ImageGrab
import numpy as np
import cv2
 
fps = 20
start = 3 # 延时录制
end = 15 # 自动结束时间
 
curScreen = ImageGrab.grab() # 获取屏幕对象
height, width = curScreen.size
 
video = cv2.VideoWriter('video02.avi', cv2.VideoWriter_fourcc(*'XVID'), fps, (height, width))
 
imageNum = 0
while True:
 imageNum += 1
 captureImage = ImageGrab.grab() # 抓取屏幕
 frame = cv2.cvtColor(np.array(captureImage), cv2.COLOR_RGB2BGR)
 
 # 显示无图像的窗口
 cv2.imshow('capturing', np.zeros((1, 255), np.uint8))
 
 # 控制窗口显示位置,方便通过按键方式退出
 cv2.moveWindow('capturing', height - 100, width - 100) 
 if imageNum > fps * start:
  video.write(frame)
 # 退出条件 
 if cv2.waitKey(50) == ord('q') or imageNum > fps * end:
  break
video.release()
cv2.destroyAllWindows()

以上这篇python 实现屏幕录制示例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python Tkinter 简单登录界面的实现

Python Tkinter 简单登录界面的实现

如下所示: from tkinter import * class Reg (Frame): def __init__(self,master): frame = F...

Python GUI自动化实现绕过验证码登录

这篇文章主要介绍了python GUI自动化实现绕过验证码登录,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 1. 获取cookies...

Tensorflow实现神经网络拟合线性回归

Tensorflow实现神经网络拟合线性回归

本文实例为大家分享了Tensorflow实现神经网络拟合线性回归的具体代码,供大家参考,具体内容如下 一、利用简单的一层神经网络拟合一个函数 y = x^2 ,其中加入部分噪声作为偏置值...

Python matplotlib通过plt.scatter画空心圆标记出特定的点方法

Python matplotlib通过plt.scatter画空心圆标记出特定的点方法

在用python画散点图的时候想标记出特定的点,比如在某些点的外围加个空心圆,一样可以通过plt.scatter实现 import matplotlib.pyplot as plt...

python中zip()方法应用实例分析

本文实例分析了python中zip()方法的应用。分享给大家供大家参考,具体如下: 假设有一个集合set, 需要对set中的每个元素指定一个唯一的id,从而组建成一个dict结构。 这个...