|
@@ -1,20 +1,73 @@
|
|
|
-from PyQt5.QtWidgets import QDialog
|
|
|
+from PyQt5.QtWidgets import QDialog
|
|
|
|
|
|
-from aiapp.ui.jiankong_ui import Ui_Dialog
|
|
|
-from aiapp.dev.camera import CameraDev
|
|
|
+from PyQt5.QtGui import QImage # ,QPxmap
|
|
|
|
|
|
-class Win(QDialog): #w我们实现的win扩展QDialog(新增,重载与覆盖over load)
|
|
|
- def __init__(self): #构造器
|
|
|
- #完成数据初始化(类的实例化:对象)
|
|
|
- #pass #空语言(ui对象化)
|
|
|
- super(Win, self).__init__()
|
|
|
+from PyQt5.QtGui import QPixmap
|
|
|
+
|
|
|
+# 引入
|
|
|
+
|
|
|
+from ui.jiankong_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()
|
|
|
|
|
|
- # 把ui绑定在Win对话框上面
|
|
|
+ # 关联ui到当前窗体
|
|
|
|
|
|
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) # 自动从QImage转换为QPixmap,QLabel只支持QPixmap格式
|
|
|
+
|
|
|
+ # 3. 显示QLabel:lblVideo
|
|
|
+
|
|
|
+ self.ui.label.setPixmap(pix_img)
|
|
|
+
|
|
|
+ # 4 适当的缩放
|
|
|
+
|
|
|
+ self.ui.label.setScaledContents(True)
|