12345678910111213141516171819202122232425262728293031 |
- from PyQt5.QtCore import QThread, pyqtSignal
- import cv2
- class DThread(QThread):
- signal_video = pyqtSignal(bytes, int, int, int)
- def __init__(self):
- super(DThread, self).__init__()
- self.is_over = False
- self.dev = cv2.VideoCapture(0, cv2.CAP_DSHOW)
-
- def run(self):
- while not self.is_over:
- status, img = self.dev.read()
- if status:
- # 处理并发送
- h, w, c = img.shape
- self.signal_video.emit(img.tobytes(), h, w, c)
- else:
- print("设备出错")
- break
- QThread.usleep(100000)
- def close(self):
- self.is_over = True
- while self.isRunning():
- pass
- print("线程正常退出")
- self.dev.release()
|