LouisZhang 1 year ago
parent
commit
550d5e9cc9

+ 3 - 2
Day03/codes/ex_qt01.py

@@ -15,10 +15,11 @@ dlg = QMainWindow()
 #改变对话框的大小
 dlg.resize(1000,1000)  #设置窗体大小
 dlg.move(100,100)   #设置窗体的位置
-dlg.setWindowTitle("我的窗体")
+dlg.setWindowTitle("我的窗体
+")
 
 #创建一个按钮
-btn = QPushButton("登录",dlg)
+btn = QPushButton("登录"dlg)
 btn.resize(100,36)
 btn.move(200,200)
 

+ 1 - 0
Day05/jiankongapp/AIAPP/aaa.bat

@@ -0,0 +1 @@
+python main.py

BIN
Day05/jiankongapp/AIAPP/dev/__pycache__/camera.cpython-39.pyc


+ 33 - 0
Day05/jiankongapp/AIAPP/dev/camera.py

@@ -0,0 +1,33 @@
+from PyQt5.QtCore import QThread  #引入多线程,设备是多个,一个设备一个任务
+import cv2
+#from cv2 import VideoCapture
+
+# 1.定义信号(引入)
+from PyQt5.QtCore import pyqtSignal
+
+class CameraDev(QThread):
+    #定义信号(定义)
+    sig_video = pyqtSignal(bytes,int,int,int)  #信号传递的数据(图像额二进制数据,字节序列(bytes),图像高度(int))
+    def __init__(self):
+        super(CameraDev,self).__init__()
+        #开始视频抓取的任务初始化
+        #初始化摄像头
+        self.cam = cv2.VideoCapture(
+            0,  #摄像头的编号,cv
+            cv2.CAP_DSHOW  # 视频的处理调用DirectX 3D (DirectShow)
+        )
+
+
+    def run(self):
+        #设备线程的任务,run结束,则任务结束
+        while True:
+           # 反复抓取视频处理
+           #print("设备准备工作!")
+           status,img = self.cam.read()  #从摄像头读取图像
+           if status:
+               #print(img.shape)
+               #显示图像
+               #2.发送信号
+               self.sig_video.emit(img.tobytes(), img.shape[0],img.shape[1],img.shape[2])
+
+           QThread.usleep(100000)  #1000000微秒 = 1秒    

BIN
Day05/jiankongapp/AIAPP/frame/__pycache__/app.cpython-39.pyc


BIN
Day05/jiankongapp/AIAPP/frame/__pycache__/win.cpython-39.pyc


+ 9 - 0
Day05/jiankongapp/AIAPP/frame/app.py

@@ -0,0 +1,9 @@
+from PyQt5.QtWidgets import QApplication
+from frame.win import Win 
+
+class App(QApplication):  #扩展QApplication类
+    def __init__(self):     #实现构造器
+        super(App,self).__init__([])    #调用父类构造器(参数:命令行参数)
+          #调用win
+        self.win = Win()
+        self.win.show()

+ 44 - 0
Day05/jiankongapp/AIAPP/frame/win.py

@@ -0,0 +1,44 @@
+from PyQt5.QtWidgets import QDialog
+from PyQt5.QtGui import QImage
+from PyQt5.QtGui import QPixmap
+
+#  引入
+from ui.traffic_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到当前窗体
+        self.ui.setupUi(self)
+
+        #创建一个设备对象
+        self.dev = CameraDev()
+        # 启动设备的线程工作
+        self.dev.start()
+
+        #绑定信号与槽。
+        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 创建QTmage
+        q_img = QImage(
+            data, #图像的字节数组
+            w,    #图像宽度
+            h,    #图像高度
+            w * c, #图像每行字节数
+            QImage.Format_BGR888  #图像格式BGR,每个通道8个bit,1个字节
+            )
+        #2.使用QTmage创建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)

+ 5 - 0
Day05/jiankongapp/AIAPP/main.py

@@ -0,0 +1,5 @@
+from frame.app import App
+
+app =App()
+
+app.exec()

BIN
Day05/jiankongapp/AIAPP/ui/__pycache__/traffic_ui.cpython-39.pyc


+ 1 - 0
Day05/jiankongapp/AIAPP/ui/app.bat

@@ -0,0 +1 @@
+python main.python

+ 2 - 0
Day05/jiankongapp/AIAPP/ui/tools.bat

@@ -0,0 +1,2 @@
+@rem
+@pyuic5 -o traffic_ui.py traffic.ui

+ 114 - 0
Day05/jiankongapp/AIAPP/ui/traffic.ui

@@ -0,0 +1,114 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Dialog</class>
+ <widget class="QDialog" name="Dialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>455</width>
+    <height>379</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>智能交通监控系统</string>
+  </property>
+  <widget class="QLabel" name="label">
+   <property name="geometry">
+    <rect>
+     <x>30</x>
+     <y>30</y>
+     <width>181</width>
+     <height>141</height>
+    </rect>
+   </property>
+   <property name="styleSheet">
+    <string notr="true">border-width:2px;
+border-style:solid;
+border-radius:10px;
+border-top-color:red;
+border-left-color:red;
+border-bottom-color:red;
+border-right-color:red;
+</string>
+   </property>
+   <property name="text">
+    <string>TextLabel</string>
+   </property>
+  </widget>
+  <widget class="QPushButton" name="pushButton">
+   <property name="geometry">
+    <rect>
+     <x>90</x>
+     <y>190</y>
+     <width>75</width>
+     <height>23</height>
+    </rect>
+   </property>
+   <property name="styleSheet">
+    <string notr="true">border-width:2px;
+border-style:solid;
+border-radius:10px;
+border-top-color:#ffffff;
+border-left-color:#ffffff;
+border-bottom-color:#bbbbbb;
+border-right-color:#bbbbbb;
+</string>
+   </property>
+   <property name="text">
+    <string>抓取图像</string>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_2">
+   <property name="geometry">
+    <rect>
+     <x>90</x>
+     <y>0</y>
+     <width>101</width>
+     <height>16</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>智能交通监控系统</string>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_3">
+   <property name="geometry">
+    <rect>
+     <x>230</x>
+     <y>60</y>
+     <width>51</width>
+     <height>16</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>识别信息:</string>
+   </property>
+  </widget>
+  <widget class="QPushButton" name="pushButton_2">
+   <property name="geometry">
+    <rect>
+     <x>220</x>
+     <y>90</y>
+     <width>81</width>
+     <height>81</height>
+    </rect>
+   </property>
+   <property name="styleSheet">
+    <string notr="true">border-width:2px;
+border-style:solid;
+border-radius:10px;
+border-top-color:red;
+border-left-color:red;
+border-bottom-color:red;
+border-right-color:red;
+</string>
+   </property>
+   <property name="text">
+    <string>显示信息:</string>
+   </property>
+  </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 68 - 0
Day05/jiankongapp/AIAPP/ui/traffic_ui.py

@@ -0,0 +1,68 @@
+# -*- coding: utf-8 -*-
+
+# Form implementation generated from reading ui file 'traffic.ui'
+#
+# Created by: PyQt5 UI code generator 5.15.9
+#
+# WARNING: Any manual changes made to this file will be lost when pyuic5 is
+# run again.  Do not edit this file unless you know what you are doing.
+
+
+from PyQt5 import QtCore, QtGui, QtWidgets
+
+
+class Ui_Dialog(object):
+    def setupUi(self, Dialog):
+        Dialog.setObjectName("Dialog")
+        Dialog.resize(312, 221)
+        self.label = QtWidgets.QLabel(Dialog)
+        self.label.setGeometry(QtCore.QRect(30, 30, 181, 141))
+        self.label.setStyleSheet("border-width:2px;\n"
+"border-style:solid;\n"
+"border-radius:10px;\n"
+"border-top-color:red;\n"
+"border-left-color:red;\n"
+"border-bottom-color:red;\n"
+"border-right-color:red;\n"
+"")
+        self.label.setObjectName("label")
+        self.pushButton = QtWidgets.QPushButton(Dialog)
+        self.pushButton.setGeometry(QtCore.QRect(90, 190, 75, 23))
+        self.pushButton.setStyleSheet("border-width:2px;\n"
+"border-style:solid;\n"
+"border-radius:10px;\n"
+"border-top-color:#ffffff;\n"
+"border-left-color:#ffffff;\n"
+"border-bottom-color:#bbbbbb;\n"
+"border-right-color:#bbbbbb;\n"
+"")
+        self.pushButton.setObjectName("pushButton")
+        self.label_2 = QtWidgets.QLabel(Dialog)
+        self.label_2.setGeometry(QtCore.QRect(90, 0, 101, 16))
+        self.label_2.setObjectName("label_2")
+        self.label_3 = QtWidgets.QLabel(Dialog)
+        self.label_3.setGeometry(QtCore.QRect(230, 60, 51, 16))
+        self.label_3.setObjectName("label_3")
+        self.pushButton_2 = QtWidgets.QPushButton(Dialog)
+        self.pushButton_2.setGeometry(QtCore.QRect(220, 90, 81, 81))
+        self.pushButton_2.setStyleSheet("border-width:2px;\n"
+"border-style:solid;\n"
+"border-radius:10px;\n"
+"border-top-color:red;\n"
+"border-left-color:red;\n"
+"border-bottom-color:red;\n"
+"border-right-color:red;\n"
+"")
+        self.pushButton_2.setObjectName("pushButton_2")
+
+        self.retranslateUi(Dialog)
+        QtCore.QMetaObject.connectSlotsByName(Dialog)
+
+    def retranslateUi(self, Dialog):
+        _translate = QtCore.QCoreApplication.translate
+        Dialog.setWindowTitle(_translate("Dialog", "智能交通监控系统"))
+        self.label.setText(_translate("Dialog", "TextLabel"))
+        self.pushButton.setText(_translate("Dialog", "抓取图像"))
+        self.label_2.setText(_translate("Dialog", "智能交通监控系统"))
+        self.label_3.setText(_translate("Dialog", "识别信息:"))
+        self.pushButton_2.setText(_translate("Dialog", "显示信息:"))