Zhuxinchan 1 år sedan
förälder
incheckning
d884632329

BIN
day05/aiapp/dev/__pycache__/camera.cpython-39.pyc


+ 21 - 0
day05/aiapp/dev/camera.py

@@ -0,0 +1,21 @@
+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)
+  def __init__(self):
+    super(CameraDev,self).__init__()
+    self.cam = cv2.VideoCapture(0, cv2.CAP_DSHOW)
+  def run(self):
+    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/aiapp/frame/__pycache__/app.cpython-39.pyc


BIN
day05/aiapp/frame/__pycache__/win.cpython-39.pyc


+ 10 - 0
day05/aiapp/frame/app.py

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

+ 27 - 0
day05/aiapp/frame/win.py

@@ -0,0 +1,27 @@
+from PyQt5.QtWidgets import QDialog
+from PyQt5.QtGui import QImage
+from PyQt5.QtGui import QPixmap
+#引入
+from ui.zm_ui import Ui_dialog
+from dev.camera import CameraDev
+
+class Win(QDialog): # 扩展QDialog(新增,覆盖功能)
+    def __init__(self): # 实现构造器(完成初始化,数据初始化,功能初始化)
+        super(Win,self).__init__() # 调用父类构造器
+        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,")")
+        q_img = QImage(
+            data,
+            w,
+            h,
+            w*c,
+            QImage.Format_BGR888)
+        pix_img = QPixmap.fromImage(q_img)
+        self.ui.label.setPixmap(pix_img)
+        self.ui.label.setScaledContents(True)

+ 5 - 0
day05/aiapp/main.py

@@ -0,0 +1,5 @@
+from  frame.app  import App
+app = App()
+
+
+app.exec() # 消息循环(程序循环处理操作系统发过来的消息)阻塞函

BIN
day05/aiapp/ui/__pycache__/zm_ui.cpython-39.pyc


+ 0 - 0
day05/aiapp/ui/tools.bat


+ 96 - 0
day05/aiapp/ui/zm.ui

@@ -0,0 +1,96 @@
+<?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>658</width>
+    <height>492</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>智能交通监控系统</string>
+  </property>
+  <widget class="QLabel" name="label">
+   <property name="geometry">
+    <rect>
+     <x>50</x>
+     <y>80</y>
+     <width>201</width>
+     <height>151</height>
+    </rect>
+   </property>
+   <property name="styleSheet">
+    <string notr="true">border-width:3px;
+border-style:solid;
+border-radius:10px;
+border-top-color:red;
+border-bottom-color:green;
+border-left-color:yellow;
+border-right-color:pink;</string>
+   </property>
+   <property name="text">
+    <string>TextLabel</string>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_2">
+   <property name="geometry">
+    <rect>
+     <x>120</x>
+     <y>20</y>
+     <width>181</width>
+     <height>20</height>
+    </rect>
+   </property>
+   <property name="styleSheet">
+    <string notr="true">font: 10pt &quot;黑体&quot;;</string>
+   </property>
+   <property name="text">
+    <string>智能交通监控系统</string>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_3">
+   <property name="geometry">
+    <rect>
+     <x>140</x>
+     <y>260</y>
+     <width>72</width>
+     <height>15</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>抓取图像</string>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_4">
+   <property name="geometry">
+    <rect>
+     <x>300</x>
+     <y>90</y>
+     <width>72</width>
+     <height>15</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>识别信息</string>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_5">
+   <property name="geometry">
+    <rect>
+     <x>310</x>
+     <y>140</y>
+     <width>101</width>
+     <height>51</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>显示信息</string>
+   </property>
+  </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 52 - 0
day05/aiapp/ui/zm_ui.py

@@ -0,0 +1,52 @@
+# -*- coding: utf-8 -*-
+
+# Form implementation generated from reading ui file 'zm.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(658, 492)
+        self.label = QtWidgets.QLabel(dialog)
+        self.label.setGeometry(QtCore.QRect(50, 80, 201, 151))
+        self.label.setStyleSheet("border-width:3px;\n"
+"border-style:solid;\n"
+"border-radius:10px;\n"
+"border-top-color:red;\n"
+"border-bottom-color:green;\n"
+"border-left-color:yellow;\n"
+"border-right-color:pink;")
+        self.label.setObjectName("label")
+        self.label_2 = QtWidgets.QLabel(dialog)
+        self.label_2.setGeometry(QtCore.QRect(120, 20, 181, 20))
+        self.label_2.setStyleSheet("font: 10pt \"黑体\";")
+        self.label_2.setObjectName("label_2")
+        self.label_3 = QtWidgets.QLabel(dialog)
+        self.label_3.setGeometry(QtCore.QRect(140, 260, 72, 15))
+        self.label_3.setObjectName("label_3")
+        self.label_4 = QtWidgets.QLabel(dialog)
+        self.label_4.setGeometry(QtCore.QRect(300, 90, 72, 15))
+        self.label_4.setObjectName("label_4")
+        self.label_5 = QtWidgets.QLabel(dialog)
+        self.label_5.setGeometry(QtCore.QRect(310, 140, 101, 51))
+        self.label_5.setObjectName("label_5")
+
+        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.label_2.setText(_translate("dialog", "智能交通监控系统"))
+        self.label_3.setText(_translate("dialog", "抓取图像"))
+        self.label_4.setText(_translate("dialog", "识别信息"))
+        self.label_5.setText(_translate("dialog", "显示信息"))