需求: 在PyQt5中嵌入视频网络摄像头读取的帧
解决方案一:使用opencv
使用opencv获取网络摄像头(局域网)的frame,然后利用定时器,每隔一定的时间更新画面。
下面为关键代码:
import cv2
self.timer_camera = QTimer() # 初始化定时器
self.cap = cv2.VideoCapture() # 初始化摄像头
self.timer_camera.timeout.connect(self.show_camera) #当计时器到了一定的时间调用show_camera函数
def show_camera(self):
flag, self.image = self.cap.read()
show = cv2.resi