123456789101112131415161718192021222324252627282930313233343536 |
- from PyQt5.QtCore import QThread, pyqtSignal
- import cv2
- class DigitDev(QThread):
-
- signal_video = pyqtSignal(int, int, int, bytes)
- def __init__(self):
- super(DigitDev, self).__init__()
- self.is_over = False
- # 初始化设备
- self.dev = cv2.VideoCapture(0, cv2.CAP_DSHOW)
- def run(self):
- while not self.is_over:
- # 图像抓取
- status, image = self.dev.read()
- # 状态判定
- if not status:
- self.dev.release()
- self.exit(0)
- # 如果抓取图像成功,发送
- shape = image.shape
- image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
- self.signal_video.emit(shape[0], shape[1], shape[2], image.tobytes())
- # 视觉暂停
- QThread.usleep(100000)
- def close(self):
- self.is_over = True
- while self.isRunning():
- pass
- # 释放设备
- if self.dev.isOpened():
- self.dev.release()
|