|
@@ -1,5 +1,6 @@
|
|
|
from PyQt5.QtCore import QChildEvent, QThread # 引入多线程,设备是多个,一个设备一个任务
|
|
|
import cv2
|
|
|
+import numpy as np
|
|
|
# from cv2 import VideoCapture
|
|
|
|
|
|
|
|
@@ -13,7 +14,7 @@ class CameraDev(QThread ):
|
|
|
super(CameraDev,self).__init__()
|
|
|
#开始视频抓取的任务初始化
|
|
|
#初始化摄像头
|
|
|
- self.cam = cv2.VideoCapture(0,cv2.CAP_DSHOW)
|
|
|
+ self.camera = cv2.VideoCapture(0,cv2.CAP_DSHOW)
|
|
|
# 摄像头编号从0开始 视频的处理调用DirectX 3D(DirectShow)
|
|
|
self.isOver = False
|
|
|
|
|
@@ -21,21 +22,21 @@ class CameraDev(QThread ):
|
|
|
|
|
|
def run(self):
|
|
|
kernel = np.array([ # 深度学习就是找到一个kernel是的特征对分类有效
|
|
|
- [1,0,-1]
|
|
|
- [2,0,-2]
|
|
|
+ [1,0,-1],
|
|
|
+ [2,0,-2],
|
|
|
[1,0,-1]
|
|
|
])
|
|
|
# 设备线程的任务,run结束,则任务结束
|
|
|
while not self.isOver:
|
|
|
# 循环抓取视频帧
|
|
|
# print("视频处理")
|
|
|
- status,img = self.cam.read()
|
|
|
+ status,img = self.camera.read()
|
|
|
if status:
|
|
|
# print(img.shape)
|
|
|
# 显示图像
|
|
|
# 调用人工智能模块,进行图像识别
|
|
|
# img = cv2.GaussianBlur(img, (3,3), 1.0) # 被处理图像, 高斯模糊算子的大小
|
|
|
-
|
|
|
+ img = cv2.filter2D(img,-1,kernel,delta=200.0)
|
|
|
# 2.发送信号
|
|
|
self.signal_video.emit(img.tobytes(),img.shape[0],img.shape[1],img.shape[2])
|
|
|
|
|
@@ -45,8 +46,6 @@ class CameraDev(QThread ):
|
|
|
# self.camera.close() #关闭摄像头
|
|
|
# self.camera.release() #释放设备
|
|
|
def close(self):
|
|
|
- # 关闭摄像头
|
|
|
- self.camrera.close()
|
|
|
# 释放设备
|
|
|
self.camera.release()
|
|
|
# 关闭线程,停止多任务
|