12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- from PyQt5 import QtGui
- from PyQt5.QtWidgets import QDialog
- from PyQt5.QtGui import QImage
- from PyQt5.QtGui import QPixmap
- #引入
- from ui.jt_ui import Ui_Dialog
- from dev.camera import CameraDev
- class Win(QDialog): # 扩展QDialog(新增,覆盖功能)
- def __init__(self): # 实现构造器(完成初始化,数据初始化,功能初始化)
- super(Win, self).__init__() # 调用父类构造器
- # 调用ui
- # 创建对象
- self.ui = Ui_Dialog()
- self.ui.setupUi(self)
- #创建一个设备对象
- self.dev = CameraDev()
- # 启动设备线程工作
- self.dev.start()
- #3.绑定信号与槽
- self.dev.sig_video.connect(self.showVideo)
- # 3.定义槽(slot)函数 (Qt技术:信号与槽),一定与信号同型
- def showVideo(self,data,h,w,c):
- # print("(",h,",",w,",",c,")") # python 格式字符串
- # 1. 使用data,h,w,c创建 QImage
- q_img = QImage(
- data, # 图像的字节数组
- w, # 图像宽度
- h, # 图像高度
- w*c, # 图像每行字节数
- QImage.Format_BGR888 # 图像格式BGR,每个通道8个bit,1个字节
- )
- # 2.使用QImage创建 QPixmap
- pix_img = QPixmap.fromImage(q_img)
-
- # 3.显示QLabel:lblVideo
- self.ui.label.setPixmap(pix_img)
- # 4.适当的缩放
- self.ui.label.setScaledContents(True)
- def closeEvent(self,e): #当窗体关闭前会调用
- # 关闭摄像头
- # 释放设备
- # 停止多任务
- print("窗口关闭")
-
|