【发布时间】:2020-06-23 15:39:15
【问题描述】:
我的代码的问题是,视频保存后速度加快了很多,我注意到如果我更改 cv2.waitkey() 中的整数值,视频会改变速度,但是即使如果我将它设置为 1,它仍然会加速
import pyautogui
import os, cv2, threading
import numpy
import time
#paths
path_videos = os.chdir('C:/Users/mypcname/Desktop/screenrec/videos')
codec = cv2.VideoWriter_fourcc(*'XVID')
video_file = cv2.VideoWriter(os.getcwd()+ '\\' + 'VIDEO2' + '.avi', codec, 23.976, (1920, 1080))
def rec_loop():
global rec, path_videos, path_frames, frame_number, codec, video_file
while True:
#takes BGR screenshot and makes it in a NumPy array
capture = pyautogui.screenshot()
frame = numpy.array(capture)
#converts BGR screenshot into RGB
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
#shows the recording screen live
cv2.imshow('REC', frame)
video_file.write(frame)
#cancel recording
if cv2.waitKey(250) == ord('Q'):
break
cv2.destroyAllWindows()
video_file.release()
rec_thread = threading.Thread(target=rec_loop)
rec_thread.start()
【问题讨论】:
标签: python-3.x opencv cv2