|

楼主 |
发表于 2023-6-4 17:11:51
|
显示全部楼层
主界面
- from tkinter import *
- import pyautogui
- import cv2
- import numpy as np
- import datetime
- import time
- from screenObj import *
- top = Tk()
- top.title("考核实况记录表")
- top.geometry('300x100')
- txt = StringVar()
- b1=Entry(top,width=20)
- b1.pack()
- b3=Entry(top,width=20, textvariable=txt)
- b3.pack()
- sco = screenObj(txt)
- def start_screen():
- sco.setText(b1.get())
- print(b1.get())
- sco.start_screen()
- pass
- def stop_screen():
- sco.stop_screen()
- txt.set('录制停止')
- pass
- #添加按钮1
- first = Button(top, text="开始录制", fg="tomato", command=start_screen)
- first.pack()
- #添加按钮2
- second = Button(top, text="停止录制", fg="tomato", command=stop_screen)
- second.pack()
- top.mainloop()
复制代码
录屏程序
- import pyautogui
- import cv2
- import numpy as np
- import datetime
- import time
- import threading
- def get_datetime_str(style='dt'):
- cur_time = datetime.datetime.now()
- date_str = cur_time.strftime('%y%m%d')
- time_str = cur_time.strftime('%H%M%S')
- if style == 'data':
- return date_str
- elif style == 'time':
- return time_str
- else:
- return date_str + '_' + time_str
- class screenObj():
- def __init__(self,txt = '测试'):
- self.path = "D:/image/"
- self.txt = txt
-
- def setText(self,mark):
- self.mark = mark
-
- def start_screen(self):
- self.vw = cv2.VideoWriter(self.path+self.mark+get_datetime_str()+'.avi',
- cv2.VideoWriter_fourcc('I','4','2','0'), 8,(800,450))
- self.on_screen = True
- threading.Thread(target = self.screen_loop).start()
-
- def stop_screen(self):
- self.on_screen = False
-
- def screen_loop(self):
- self.frame = 1
- while self.on_screen:
- print("帧数"+str(self.frame))
- self.txt.set('已经录制'+str(self.frame)+'秒')
- self.frame = self.frame + 1
- img = pyautogui.screenshot()
- # 分别代表:左上角坐标,宽高
- img=img.resize((800,450))
- img = cv2.cvtColor(np.asarray(img), cv2.COLOR_RGB2BGR)
- cv2.putText(img,text= self.mark ,org=(40, 90),
- fontFace=cv2.FONT_HERSHEY_SIMPLEX,fontScale= 2,
- color=(255,0,0),thickness=10,lineType=cv2.LINE_4)
- self.vw.write(img)
- time.sleep(1);
- self.vw.release()
- print("录制结束")
-
- if __name__ == '__main__':
- sco = screenObj()
- sco.setText('aaa')
- sco.start_screen()
- time.sleep(5)
- sco.stop_screen()
-
复制代码 |
|