|
@@ -1,5 +1,6 @@
|
|
|
from PyQt5.QtCore import QThread
|
|
|
import cv2
|
|
|
+import numpy as np
|
|
|
from cv2 import VideoCapture
|
|
|
# 1.定义信号
|
|
|
from PyQt5.QtCore import pyqtSignal
|
|
@@ -9,13 +10,31 @@ class CameraDev(QThread):
|
|
|
def __init__(self):
|
|
|
super(CameraDev,self).__init__()
|
|
|
self.cam = cv2.VideoCapture(0, cv2.CAP_DSHOW)
|
|
|
+ self.isOver = False
|
|
|
+
|
|
|
def run(self):
|
|
|
- while True:
|
|
|
+ kernel = np.array([
|
|
|
+ [0, -2, 0],
|
|
|
+ [-2, 8, -2],
|
|
|
+ [0, -2, 0]
|
|
|
+ ])
|
|
|
+ while not self.isOver:
|
|
|
# print("设备准备工作!")
|
|
|
status,img = self.cam.read()
|
|
|
if status:
|
|
|
#print(img.shape)
|
|
|
#显示图像
|
|
|
+ #img = cv2.GaussianBlur(img,3,1)
|
|
|
+ img = cv2.filter2D(img, -1, kernel, delta=200.0)
|
|
|
# 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("设备释放")
|