29 lines
824 B
Python
29 lines
824 B
Python
|
from PyQt5.QtCore import QThread, pyqtSignal
|
||
|
from collections import deque
|
||
|
import numpy as np
|
||
|
|
||
|
|
||
|
class StorageThread(QThread):
|
||
|
frames_ready = pyqtSignal(np.ndarray)
|
||
|
|
||
|
def __init__(self, max_frames=300):
|
||
|
super().__init__()
|
||
|
self.frame_buffer = deque(maxlen=max_frames)
|
||
|
self.running = True
|
||
|
|
||
|
def run(self):
|
||
|
while self.running:
|
||
|
if len(self.frame_buffer) >= self.frame_buffer.maxlen:
|
||
|
frames = np.array(list(self.frame_buffer))
|
||
|
self.frames_ready.emit(frames)
|
||
|
self.frame_buffer.clear()
|
||
|
# print('Frames ready:', frames.shape)
|
||
|
self.msleep(100) # 休眠100ms
|
||
|
|
||
|
def store_frame(self, frame):
|
||
|
self.frame_buffer.append(frame)
|
||
|
|
||
|
def stop(self):
|
||
|
self.running = False
|
||
|
self.wait()
|