我正在尝试在 python 中使用 mss 和 Opencv 创建屏幕录像机,我正在捕获的视频的颜色与原始计算机屏幕的颜色非常不同。我试图在网上找到解决方案,每个人都说应该使用 cvtColor() 修复它,但我的代码中已经有了它。
import cv2
from PIL import Image
import numpy as np
from mss import mss
import threading
from datetime import datetime
`
def thread_recording():
fourcc=cv2.VideoWriter_fourcc(*'mp4v')
#fourcc=cv2.VideoWriter_fourcc(*'XVID')
out=cv2.VideoWriter(vid_file,fourcc,50,(width,height))
mon = {"top": 0, "left": 0, "width":width, "height":height}
sct = mss()
thread1=threading.Thread(target=record,args=(mon,out,sct))
thread1.start()
def record(mon,out,sct):
global recording
recording=True
while recording:
frame= np.array(sct.grab(mon))
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
out.write(frame)
out.release()
vid_file 变量包含一串带有 mp4 扩展名的输出文件名