bang 1 tahun lalu
induk
melakukan
b42c99852b

+ 54 - 0
Day5/a.ui

@@ -0,0 +1,54 @@
+<?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>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <widget class="QLabel" name="lbvideo">
+   <property name="geometry">
+    <rect>
+     <x>50</x>
+     <y>60</y>
+     <width>251</width>
+     <height>161</height>
+    </rect>
+   </property>
+   <property name="styleSheet">
+    <string notr="true">border-width:5px;
+border-style:dotted;
+border-color:red;
+border-top-color:red;
+border-bottom-color:green;
+border-left-color:green;
+border-right-color:pink;</string>
+   </property>
+   <property name="text">
+    <string>TextLabel</string>
+   </property>
+  </widget>
+  <widget class="QPushButton" name="btucapture">
+   <property name="geometry">
+    <rect>
+     <x>130</x>
+     <y>260</y>
+     <width>93</width>
+     <height>28</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>抓取图像</string>
+   </property>
+  </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 1 - 0
Day5/monitor/app.bat

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

TEMPAT SAMPAH
Day5/monitor/dev/__pycache__/camera.cpython-39.pyc


+ 29 - 0
Day5/monitor/dev/camera.py

@@ -0,0 +1,29 @@
+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, # 摄像头的编号,从0
+            cv2.CAP_DSHOW 
+        )
+
+    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秒

TEMPAT SAMPAH
Day5/monitor/frame/__pycache__/app.cpython-39.pyc


TEMPAT SAMPAH
Day5/monitor/frame/__pycache__/win.cpython-39.pyc


+ 9 - 0
Day5/monitor/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()

+ 38 - 0
Day5/monitor/frame/win.py

@@ -0,0 +1,38 @@
+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):
+    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.定义值
+    def showVideo(self,data, h,w,c):
+        #print(",h,",",w,",",c,")
+        q_img = QImage(
+            data,
+            w,
+            h,
+            w*c, 
+            QImage.Format_BGR888
+        )
+        #2.使用QImage创建QPixmap
+        pix_img = QPixmap.fromImage(q_img)
+        #3.显示
+        self.ui.lbvideo.setPixmap(pix_img)
+        #4.适当缩放
+        self.ui.lbvideo.setScaledContents(True)
+
+       
+    

+ 4 - 0
Day5/monitor/main.py

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

TEMPAT SAMPAH
Day5/monitor/ui/__pycache__/traffic_ui.cpython-39.pyc


+ 50 - 0
Day5/monitor/ui/traffic.ui

@@ -0,0 +1,50 @@
+<?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>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <widget class="QLabel" name="lbvideo">
+   <property name="geometry">
+    <rect>
+     <x>50</x>
+     <y>60</y>
+     <width>251</width>
+     <height>161</height>
+    </rect>
+   </property>
+   <property name="styleSheet">
+    <string notr="true">border-width:1px;
+border-sytle:solid;
+border-color:FF0000;</string>
+   </property>
+   <property name="text">
+    <string>TextLabel</string>
+   </property>
+  </widget>
+  <widget class="QPushButton" name="btucapture">
+   <property name="geometry">
+    <rect>
+     <x>130</x>
+     <y>260</y>
+     <width>93</width>
+     <height>28</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>抓取图像</string>
+   </property>
+  </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 35 - 0
Day5/monitor/ui/traffic_ui.py

@@ -0,0 +1,35 @@
+# -*- 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(400, 300)
+        self.lbvideo = QtWidgets.QLabel(Dialog)
+        self.lbvideo.setGeometry(QtCore.QRect(50, 60, 251, 161))
+        self.lbvideo.setStyleSheet("border-width:1px;\n"
+"border-sytle:solid;\n"
+"border-color:FF0000;")
+        self.lbvideo.setObjectName("lbvideo")
+        self.btucapture = QtWidgets.QPushButton(Dialog)
+        self.btucapture.setGeometry(QtCore.QRect(130, 260, 93, 28))
+        self.btucapture.setObjectName("btucapture")
+
+        self.retranslateUi(Dialog)
+        QtCore.QMetaObject.connectSlotsByName(Dialog)
+
+    def retranslateUi(self, Dialog):
+        _translate = QtCore.QCoreApplication.translate
+        Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
+        self.lbvideo.setText(_translate("Dialog", "TextLabel"))
+        self.btucapture.setText(_translate("Dialog", "抓取图像"))