瀏覽代碼

first commit

Zhuxinchan 1 年之前
父節點
當前提交
4784d16e0a

二進制
day05/aiapp/dev/__pycache__/camera.cpython-39.pyc


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

@@ -1,5 +1,6 @@
 from PyQt5.QtCore import QThread
 from PyQt5.QtCore import QThread
 import cv2
 import cv2
+import numpy as np
 from cv2 import VideoCapture
 from cv2 import VideoCapture
 # 1.定义信号
 # 1.定义信号
 from PyQt5.QtCore import pyqtSignal
 from PyQt5.QtCore import pyqtSignal
@@ -9,13 +10,31 @@ class CameraDev(QThread):
   def __init__(self):
   def __init__(self):
     super(CameraDev,self).__init__()
     super(CameraDev,self).__init__()
     self.cam = cv2.VideoCapture(0, cv2.CAP_DSHOW)
     self.cam = cv2.VideoCapture(0, cv2.CAP_DSHOW)
+    self.isOver = False
+
   def run(self):
   def run(self):
-    while True:
+    kernel = np.array([
+       [0, -2, 0],
+       [-2, 8, -2],
+       [0, -2, 0]
+    ])
+    while not self.isOver:
       # print("设备准备工作!")
       # print("设备准备工作!")
       status,img = self.cam.read()
       status,img = self.cam.read()
       if status:
       if status:
         #print(img.shape)
         #print(img.shape)
         #显示图像
         #显示图像
+        #img = cv2.GaussianBlur(img,3,1)
+        img = cv2.filter2D(img, -1, kernel, delta=200.0)
         # 2.发送信号
         # 2.发送信号
         self.sig_video.emit(img.tobytes(),img.shape[0],img.shape[1], img.shape[2])
         self.sig_video.emit(img.tobytes(),img.shape[0],img.shape[1], img.shape[2])
-      QThread.usleep(100000)  #1000000微秒 = 1秒
+      QThread.usleep(100000)  #1000000微秒 = 1秒
+  def close(self):
+      self.isOver = True
+      while self.isRunning():
+        pass
+
+      print("线程终止")
+        # 释放设备
+      self.cam.release()
+      print("设备释放")

二進制
day05/aiapp/frame/__pycache__/win.cpython-39.pyc


+ 4 - 1
day05/aiapp/frame/win.py

@@ -24,4 +24,7 @@ class Win(QDialog): # 扩展QDialog(新增,覆盖功能)
             QImage.Format_BGR888)
             QImage.Format_BGR888)
         pix_img = QPixmap.fromImage(q_img)
         pix_img = QPixmap.fromImage(q_img)
         self.ui.label.setPixmap(pix_img)
         self.ui.label.setPixmap(pix_img)
-        self.ui.label.setScaledContents(True)
+        self.ui.label.setScaledContents(True)
+    def closeEvent(self, e): # 当窗体关闭前会调用
+        self.dev.close()
+        print("窗口关闭")

+ 4 - 1
day05/aiapp/main.py

@@ -1,5 +1,8 @@
+import PyQt5.QtCore
 from  frame.app  import App
 from  frame.app  import App
-app = App()
 
 
+PyQt5.QtCore.QCoreApplication.setAttribute(PyQt5.QtCore.Qt.AA_EnableHighDpiScaling)
 
 
+app = App()
 app.exec() # 消息循环(程序循环处理操作系统发过来的消息)阻塞函
 app.exec() # 消息循环(程序循环处理操作系统发过来的消息)阻塞函
+print("程序正常终止")