-
Notifications
You must be signed in to change notification settings - Fork 0
/
videoadapter.py
36 lines (27 loc) · 1014 Bytes
/
videoadapter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import numpy as np
from PyQt5.QtCore import pyqtSignal, QObject
class VideoAdapter(QObject):
changed_pixmap_sig = pyqtSignal(np.ndarray)
def __init__(self):
super().__init__()
self.grabbers = dict()
self.activeKey = None
def runAdapter(self):
for gr in self.grabbers.values():
gr.grabber_signal.connect(self.execute)
gr.start()
def execute(self, data):
self.changed_pixmap_sig.emit(data)
def addVideoGrabber(self, grabber):
if not grabber.key in self.grabbers:
self.grabbers[grabber.key] = grabber
if self.activeKey is None:
self.activeGrabber(grabber.key)
def activeGrabber(self, key):
if self.activeKey is not key:
if self.activeKey is not None:
prevgr = self.grabbers[self.activeKey]
prevgr.releaseGrab()
self.activeKey = key
gr = self.grabbers[self.activeKey]
gr.setGrab()