xiaoweiwei 1 anno fa
parent
commit
9bd16b0601

+ 1 - 0
Day05/app.bat

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

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


+ 53 - 0
Day05/dev/camera.py

@@ -0,0 +1,53 @@
+from PyQt5.QtCore import QThread
+import cv2
+import numpy as np
+
+
+#from cv2 
+# import VideoCapture
+
+
+#1.定义一个信号
+from PyQt5.QtCore import pyqtSignal
+
+
+class CameraDev(QThread):
+    sig_video = pyqtSignal(bytes, int, int, int)
+    #(字节序列
+    def __init__(self):
+        super(CameraDev, self).__init__()
+
+        #初始化摄像头
+        self.cam =cv2.VideoCapture(
+            0,#摄像头编号
+            cv2.CAP_DSHOW
+        )
+        self.isOver =False
+    def run(self):
+        kernel = np.array([
+            [-1, 0, 1],
+            [-1, 0, 1],
+            [-1, 0, 1]
+        ])
+        #设备线程任务
+        while not self.isOver:
+            #print("设备准备工作")
+            status, img = self.cam.read()  #从摄像头读取图像
+            if status:
+            # print(img.shape)
+                #显示图像
+                img = cv2.GaussianBlur(img, (3,3), 1.0)
+                #调用人工智能浮雕效果
+                #img = cv2.filter2D(img, -1, kernel, delta = 200.0)
+                self.sig_video.emit(img.tobytes(), img.shape[0], img.shape[1], img.shape[2])
+            
+            QThread.usleep(100000) 
+
+    def close(self):
+        self.isOver = True
+        while self.isRunning():
+            pass
+        print("线程终止")
+
+        self.cam.release()
+        print("设备释放")

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


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


+ 9 - 0
Day05/frame/app.py

@@ -0,0 +1,9 @@
+from PyQt5.QtWidgets import QApplication
+from frame.win import Win
+
+class App(QApplication):
+    def __init__(self):
+        super(App, self).__init__([])
+        
+        self.win = Win()
+        self.win.show()

+ 45 - 0
Day05/frame/win.py

@@ -0,0 +1,45 @@
+from PyQt5 import QtGui
+from PyQt5.QtWidgets import QDialog
+#引入
+from PyQt5.QtGui import QImage
+from PyQt5.QtGui import QPixmap
+
+from ui.Ui_traffic import Ui_Dialog
+
+from dev.camera import CameraDev
+
+class Win(QDialog): #扩展
+    def __init__(self): #实现构造器
+        super(Win, self).__init__()
+        #调用ui
+        self.ui = Ui_Dialog()
+        self.ui.setupUi(self)
+        self.dev = CameraDev()
+        #启动线程
+        self.dev.start()
+        #绑定信号
+        self.dev.sig_video.connect(self.showVideo)
+
+
+    #3.定义槽(slot)函数  一定与信号同型
+    def showVideo(self, data, h, w, c):
+     #print("(", h, ",", w, ",", c, ")")
+        #1.
+        q_img = QImage(
+            data, #图像字节数
+            w, #图像宽度
+            h, #图像亮度
+            w*c, # 图像高度
+            QImage.Format_BGR888)   #图像格式bgr
+        # 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)
+    def closeEvent(self, e):
+        #关闭摄像头
+        self.dev.close()
+        print("窗口关闭")

+ 8 - 0
Day05/main.py

@@ -0,0 +1,8 @@
+import PyQt5.QtCore
+from frame.app import App
+
+PyQt5.QtCore.QCoreApplication.setAttribute(PyQt5.QtCore.Qt.AA_EnableHighDpiScaling)
+app = App()
+app.exec()
+#消息循环
+print("程序正常终止")

+ 59 - 0
Day05/ui/Ui_traffic.py

@@ -0,0 +1,59 @@
+# -*- coding: utf-8 -*-
+
+# Form implementation generated from reading ui file 'e:\文件\20200404405duwei\Day05\ui\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(489, 528)
+        Dialog.setStyleSheet("border-width:2px;\n"
+"border-style:dot;\n"
+"boeder-color:pink;")
+        self.label = QtWidgets.QLabel(Dialog)
+        self.label.setGeometry(QtCore.QRect(30, 80, 301, 271))
+        self.label.setStyleSheet("border-width:2px;\n"
+"border-style:solid;\n"
+"border-color:red;\n"
+"border-radius:10px;")
+        self.label.setObjectName("label")
+        self.pushButton = QtWidgets.QPushButton(Dialog)
+        self.pushButton.setGeometry(QtCore.QRect(120, 410, 231, 51))
+        self.pushButton.setStyleSheet("border-width:2px;\n"
+"background-color: rgb(0, 0, 255);\n"
+"border-style:solid;\n"
+"border-radius:10px;\n"
+"border-left-color:#bbbbbb;\n"
+"border-right-color:#bbbbbb;")
+        self.pushButton.setObjectName("pushButton")
+        self.label_2 = QtWidgets.QLabel(Dialog)
+        self.label_2.setGeometry(QtCore.QRect(150, 30, 201, 41))
+        self.label_2.setStyleSheet("alternate-background-color: rgb(85, 255, 255);\n"
+"font: 20pt \"Agency FB\";\n"
+"border-color: rgb(255, 0, 0);\n"
+"border-radius:15px;\n"
+"")
+        self.label_2.setObjectName("label_2")
+        self.label_3 = QtWidgets.QLabel(Dialog)
+        self.label_3.setGeometry(QtCore.QRect(390, 210, 71, 81))
+        self.label_3.setStyleSheet("background-color: rgb(170, 255, 255);")
+        self.label_3.setObjectName("label_3")
+
+        self.retranslateUi(Dialog)
+        QtCore.QMetaObject.connectSlotsByName(Dialog)
+
+    def retranslateUi(self, Dialog):
+        _translate = QtCore.QCoreApplication.translate
+        Dialog.setWindowTitle(_translate("Dialog", "智能交通监控系统"))
+        self.label.setText(_translate("Dialog", "<html><head/><body><p align=\"center\"><br/></p><p align=\"center\"><br/></p><p align=\"center\"><span style=\" font-size:14pt; font-weight:600;\">视频显示区</span></p></body></html>"))
+        self.pushButton.setText(_translate("Dialog", "抓取视频"))
+        self.label_2.setText(_translate("Dialog", "视频监控系统"))
+        self.label_3.setText(_translate("Dialog", "数据"))

BIN
Day05/ui/__pycache__/Ui_traffic.cpython-39.pyc


+ 1 - 0
Day05/ui/tools.bat

@@ -0,0 +1 @@
+@rem @符号在执行命令,不回显命令

+ 100 - 0
Day05/ui/traffic.ui

@@ -0,0 +1,100 @@
+<?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>489</width>
+    <height>528</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>智能交通监控系统</string>
+  </property>
+  <property name="styleSheet">
+   <string notr="true">border-width:2px;
+border-style:dot;
+boeder-color:pink;</string>
+  </property>
+  <widget class="QLabel" name="label">
+   <property name="geometry">
+    <rect>
+     <x>30</x>
+     <y>80</y>
+     <width>301</width>
+     <height>271</height>
+    </rect>
+   </property>
+   <property name="styleSheet">
+    <string notr="true">border-width:2px;
+border-style:solid;
+border-color:red;
+border-radius:10px;</string>
+   </property>
+   <property name="text">
+    <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;br/&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;br/&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:14pt; font-weight:600;&quot;&gt;视频显示区&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+   </property>
+  </widget>
+  <widget class="QPushButton" name="pushButton">
+   <property name="geometry">
+    <rect>
+     <x>120</x>
+     <y>410</y>
+     <width>231</width>
+     <height>51</height>
+    </rect>
+   </property>
+   <property name="styleSheet">
+    <string notr="true">border-width:2px;
+background-color: rgb(0, 0, 255);
+border-style:solid;
+border-radius:10px;
+border-left-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>150</x>
+     <y>30</y>
+     <width>201</width>
+     <height>41</height>
+    </rect>
+   </property>
+   <property name="styleSheet">
+    <string notr="true">alternate-background-color: rgb(85, 255, 255);
+font: 20pt &quot;Agency FB&quot;;
+border-color: rgb(255, 0, 0);
+border-radius:15px;
+</string>
+   </property>
+   <property name="text">
+    <string>视频监控系统</string>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_3">
+   <property name="geometry">
+    <rect>
+     <x>390</x>
+     <y>210</y>
+     <width>71</width>
+     <height>81</height>
+    </rect>
+   </property>
+   <property name="styleSheet">
+    <string notr="true">background-color: rgb(170, 255, 255);</string>
+   </property>
+   <property name="text">
+    <string>数据</string>
+   </property>
+  </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 78 - 0
Day06/game.ui

@@ -0,0 +1,78 @@
+<?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>474</width>
+    <height>425</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>猜拳</string>
+  </property>
+  <widget class="QLabel" name="label">
+   <property name="geometry">
+    <rect>
+     <x>180</x>
+     <y>20</y>
+     <width>91</width>
+     <height>31</height>
+    </rect>
+   </property>
+   <property name="styleSheet">
+    <string notr="true">font: 14pt &quot;Agency FB&quot;;</string>
+   </property>
+   <property name="text">
+    <string>猜拳游戏</string>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_2">
+   <property name="geometry">
+    <rect>
+     <x>30</x>
+     <y>90</y>
+     <width>311</width>
+     <height>241</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;br/&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;br/&gt;&lt;span style=&quot; font-size:18pt; font-weight:600;&quot;&gt;比赛区域&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+   </property>
+  </widget>
+  <widget class="QPushButton" name="pushButton">
+   <property name="geometry">
+    <rect>
+     <x>200</x>
+     <y>380</y>
+     <width>75</width>
+     <height>23</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>抓取图像</string>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_3">
+   <property name="geometry">
+    <rect>
+     <x>370</x>
+     <y>80</y>
+     <width>71</width>
+     <height>71</height>
+    </rect>
+   </property>
+   <property name="styleSheet">
+    <string notr="true">border-bottom-color: rgb(255, 255, 255);
+border-bottom-color: rgb(255, 0, 0);</string>
+   </property>
+   <property name="text">
+    <string>结果显示</string>
+   </property>
+  </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>