ScreenMagnifier 1.11.0.post8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of ScreenMagnifier might be problematic. Click here for more details.

Files changed (117) hide show
  1. ScreenMagnifier/__init__.py +68 -0
  2. ScreenMagnifier/__main__.py +17 -0
  3. ScreenMagnifier/advancedoverlay.py +593 -0
  4. ScreenMagnifier/advancedpanel.py +521 -0
  5. ScreenMagnifier/analysiscontroller.py +533 -0
  6. ScreenMagnifier/analysisserver.py +404 -0
  7. ScreenMagnifier/colordetector/__init__.py +28 -0
  8. ScreenMagnifier/colordetector/colordetector.py +570 -0
  9. ScreenMagnifier/colordetector/core.py +434 -0
  10. ScreenMagnifier/colordetector/main.py +23 -0
  11. ScreenMagnifier/colordetector/mainwindow.py +182 -0
  12. ScreenMagnifier/colorpanel.py +424 -0
  13. ScreenMagnifier/colorswatches/__init__.py +16 -0
  14. ScreenMagnifier/colorswatches/colorswatches.py +316 -0
  15. ScreenMagnifier/colorswatches/main.py +23 -0
  16. ScreenMagnifier/colorswatches/mainwindow.py +60 -0
  17. ScreenMagnifier/controlpanel.py +234 -0
  18. ScreenMagnifier/detectionpanel.py +790 -0
  19. ScreenMagnifier/facedetector/__init__.py +24 -0
  20. ScreenMagnifier/facedetector/core.py +314 -0
  21. ScreenMagnifier/facedetector/facedetector.py +288 -0
  22. ScreenMagnifier/facedetector/main.py +23 -0
  23. ScreenMagnifier/facedetector/mainwindow.py +122 -0
  24. ScreenMagnifier/facedetector/models/__init__.py +4 -0
  25. ScreenMagnifier/facepointer.py +1121 -0
  26. ScreenMagnifier/features.py +50 -0
  27. ScreenMagnifier/hotkeys/__init__.py +16 -0
  28. ScreenMagnifier/hotkeys/hotkeys.py +379 -0
  29. ScreenMagnifier/hotkeys/main.py +23 -0
  30. ScreenMagnifier/hotkeys/mainwindow.py +56 -0
  31. ScreenMagnifier/imagefilters/__init__.py +24 -0
  32. ScreenMagnifier/imagefilters/core.py +172 -0
  33. ScreenMagnifier/imagefilters/imagefilters.py +220 -0
  34. ScreenMagnifier/imagefilters/main.py +23 -0
  35. ScreenMagnifier/imagefilters/mainwindow.py +120 -0
  36. ScreenMagnifier/magnifierview/__init__.py +16 -0
  37. ScreenMagnifier/magnifierview/magnifierview.py +1249 -0
  38. ScreenMagnifier/magnifierview/main.py +23 -0
  39. ScreenMagnifier/magnifierview/mainwindow.py +91 -0
  40. ScreenMagnifier/main.py +157 -0
  41. ScreenMagnifier/mainwindow.py +1368 -0
  42. ScreenMagnifier/mousecatcher/__init__.py +16 -0
  43. ScreenMagnifier/mousecatcher/main.py +23 -0
  44. ScreenMagnifier/mousecatcher/mainwindow.py +78 -0
  45. ScreenMagnifier/mousecatcher/mousecatcher.py +251 -0
  46. ScreenMagnifier/mousemove.py +259 -0
  47. ScreenMagnifier/netprotocol/__init__.py +25 -0
  48. ScreenMagnifier/netprotocol/main.py +23 -0
  49. ScreenMagnifier/netprotocol/mainwindow.py +91 -0
  50. ScreenMagnifier/netprotocol/netprotocol.py +372 -0
  51. ScreenMagnifier/netprotocol/wire.py +189 -0
  52. ScreenMagnifier/regionselector/__init__.py +16 -0
  53. ScreenMagnifier/regionselector/main.py +23 -0
  54. ScreenMagnifier/regionselector/mainwindow.py +70 -0
  55. ScreenMagnifier/regionselector/regionselector.py +549 -0
  56. ScreenMagnifier/remoteclient.py +636 -0
  57. ScreenMagnifier/resources/icon-128.png +0 -0
  58. ScreenMagnifier/resources/icon-16.png +0 -0
  59. ScreenMagnifier/resources/icon-24.png +0 -0
  60. ScreenMagnifier/resources/icon-256.png +0 -0
  61. ScreenMagnifier/resources/icon-32.png +0 -0
  62. ScreenMagnifier/resources/icon-48.png +0 -0
  63. ScreenMagnifier/resources/icon-512.png +0 -0
  64. ScreenMagnifier/resources/icon-64.png +0 -0
  65. ScreenMagnifier/resources/icon.icns +0 -0
  66. ScreenMagnifier/resources/icon.ico +0 -0
  67. ScreenMagnifier/screengrabber/__init__.py +16 -0
  68. ScreenMagnifier/screengrabber/main.py +23 -0
  69. ScreenMagnifier/screengrabber/mainwindow.py +79 -0
  70. ScreenMagnifier/screengrabber/screengrabber.py +558 -0
  71. ScreenMagnifier/server.py +150 -0
  72. ScreenMagnifier/serverpanel.py +379 -0
  73. ScreenMagnifier/shortcuteditor/__init__.py +16 -0
  74. ScreenMagnifier/shortcuteditor/main.py +23 -0
  75. ScreenMagnifier/shortcuteditor/mainwindow.py +54 -0
  76. ScreenMagnifier/shortcuteditor/shortcuteditor.py +411 -0
  77. ScreenMagnifier/shortcuts.py +118 -0
  78. ScreenMagnifier/shortcutspanel.py +140 -0
  79. ScreenMagnifier/support.py +127 -0
  80. ScreenMagnifier/translations/ar.json +387 -0
  81. ScreenMagnifier/translations/de.json +387 -0
  82. ScreenMagnifier/translations/es.json +387 -0
  83. ScreenMagnifier/translations/fr.json +387 -0
  84. ScreenMagnifier/translations/it.json +387 -0
  85. ScreenMagnifier/translations/ja.json +387 -0
  86. ScreenMagnifier/translations/ko.json +387 -0
  87. ScreenMagnifier/translations/pt_BR.json +387 -0
  88. ScreenMagnifier/translations/ru.json +387 -0
  89. ScreenMagnifier/translations/tr.json +387 -0
  90. ScreenMagnifier/translations/zh_CN.json +387 -0
  91. ScreenMagnifier/translator/__init__.py +16 -0
  92. ScreenMagnifier/translator/main.py +23 -0
  93. ScreenMagnifier/translator/mainwindow.py +62 -0
  94. ScreenMagnifier/translator/translator.py +284 -0
  95. ScreenMagnifier/upscaler/__init__.py +24 -0
  96. ScreenMagnifier/upscaler/core.py +315 -0
  97. ScreenMagnifier/upscaler/main.py +23 -0
  98. ScreenMagnifier/upscaler/mainwindow.py +128 -0
  99. ScreenMagnifier/upscaler/models/FSRCNN-small_x2.pb +0 -0
  100. ScreenMagnifier/upscaler/models/FSRCNN-small_x3.pb +0 -0
  101. ScreenMagnifier/upscaler/models/FSRCNN-small_x4.pb +0 -0
  102. ScreenMagnifier/upscaler/models/FSRCNN_x2.pb +0 -0
  103. ScreenMagnifier/upscaler/models/FSRCNN_x3.pb +0 -0
  104. ScreenMagnifier/upscaler/models/FSRCNN_x4.pb +0 -0
  105. ScreenMagnifier/upscaler/models/LICENSE-FSRCNN +201 -0
  106. ScreenMagnifier/upscaler/models/__init__.py +4 -0
  107. ScreenMagnifier/upscaler/upscaler.py +285 -0
  108. ScreenMagnifier/wincheck.py +65 -0
  109. ScreenMagnifier/zoomoverlay/__init__.py +16 -0
  110. ScreenMagnifier/zoomoverlay/main.py +23 -0
  111. ScreenMagnifier/zoomoverlay/mainwindow.py +99 -0
  112. ScreenMagnifier/zoomoverlay/zoomoverlay.py +1779 -0
  113. screenmagnifier-1.11.0.post8.dist-info/METADATA +591 -0
  114. screenmagnifier-1.11.0.post8.dist-info/RECORD +117 -0
  115. screenmagnifier-1.11.0.post8.dist-info/WHEEL +5 -0
  116. screenmagnifier-1.11.0.post8.dist-info/entry_points.txt +5 -0
  117. screenmagnifier-1.11.0.post8.dist-info/top_level.txt +1 -0
@@ -0,0 +1,533 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ AnalysisController: runs color detection and (optional AI) face detection on the magnified frames and turns the
4
+ results into annotations (boxes, labels, landmarks, privacy blur, color mask) for the view and the lens.
5
+ - Several sources ('view', 'lens'), each rate limited (rateHz) with "latest frame wins".
6
+ - Local analysis runs on a worker thread, so zooming / panning stay smooth.
7
+ - With a connected RemoteClient and useRemote, the analysis runs on the server instead (automatic local fallback
8
+ whenever the server is unavailable).
9
+ - A generation counter drops results computed with outdated settings.
10
+ - colorAppeared(source, name) fires when a target color becomes visible (alerts).
11
+ """
12
+ from ManyQt.QtCore import QObject, QTimer, QSize, Qt, pyqtSignal, pyqtSlot, pyqtProperty
13
+ from ManyQt.QtGui import QImage
14
+ from threading import Thread, Condition
15
+ from os.path import dirname
16
+ from zlib import adler32
17
+ from sys import path
18
+
19
+ if not __package__ and dirname(__file__) not in path:
20
+ path.append(dirname(__file__))
21
+
22
+ try:
23
+ from .colordetector import ColorDetector, maskToOverlay
24
+ from .facedetector import FaceDetector
25
+ except:
26
+ from colordetector import ColorDetector, maskToOverlay
27
+ from facedetector import FaceDetector
28
+
29
+ FACE_COLOR = '#00E5FF' # type: str
30
+ REMOTE_MAX_SIDE = 1280 # type: int # Larger frames are downscaled for remote analysis (smaller would blur thin text).
31
+
32
+
33
+ def frameKey(image):
34
+ """
35
+ :param image: QImage
36
+ :return: (int) Cheap content fingerprint (unchanged screens are not analysed again).
37
+ """
38
+ ptr = image.constBits()
39
+ n = image.sizeInBytes() if hasattr(image, 'sizeInBytes') else image.byteCount() # type: int
40
+ if hasattr(ptr, 'setsize'):
41
+ ptr.setsize(n)
42
+ return adler32(bytes(ptr)) ^ (image.width() << 16) ^ image.height()
43
+
44
+
45
+ class AnalysisController(QObject):
46
+ """
47
+ AnalysisController class.
48
+ """
49
+ annotationsReady = pyqtSignal('QString', object, object, object, object) # type: pyqtSignal # source, list,
50
+ # QSize, QImage, origin [x, y, dpr] | None
51
+ resultsReady = pyqtSignal('QString', object) # type: pyqtSignal # source, {'colors': {...}, 'faces': {...}}
52
+ colorAppeared = pyqtSignal('QString', 'QString') # type: pyqtSignal # source, color name
53
+ settingsChanged = pyqtSignal() # type: pyqtSignal
54
+ _workerDone = pyqtSignal('QString', object, object, int) # type: pyqtSignal # worker -> GUI thread
55
+
56
+ def __init__(self, *args, **kwargs):
57
+ """
58
+ :param colorDetector: (ColorDetector | None) None = create one.
59
+ :param faceDetector: (FaceDetector | None) None = create one.
60
+ :param client: (RemoteClient | None) Server connection used when useRemote is on.
61
+ :param rateHz: (float | int) Analyses per second and per source.
62
+ :param colorEnabled: bool
63
+ :param faceEnabled: bool
64
+ :param useRemote: (bool) Analyse on the server when it is connected.
65
+ :param showBoxes: (bool) Boxes around detected color regions.
66
+ :param showMask: (bool) Color highlight mask.
67
+ :param maskMode: (str | unicode | QString) 'isolate' or 'tint'.
68
+ :param maskAlpha: (float | int) 0 .. 1
69
+ :param faceMode: (str | unicode | QString) 'box', 'landmarks' or 'blur' (privacy).
70
+ :param annotationsReady: callable | None
71
+ :param resultsReady: callable | None
72
+ :param colorAppeared: callable | None
73
+ :param args: any
74
+ :param kwargs: any
75
+ """
76
+ colorDetector = kwargs.pop('colorDetector', None) # type: ColorDetector | None
77
+ faceDetector = kwargs.pop('faceDetector', None) # type: FaceDetector | None
78
+ client = kwargs.pop('client', None)
79
+ rateHz = kwargs.pop('rateHz', 8) # type: float
80
+ colorEnabled = kwargs.pop('colorEnabled', False) # type: bool
81
+ faceEnabled = kwargs.pop('faceEnabled', False) # type: bool
82
+ useRemote = kwargs.pop('useRemote', False) # type: bool
83
+ showBoxes = kwargs.pop('showBoxes', True) # type: bool
84
+ showMask = kwargs.pop('showMask', True) # type: bool
85
+ maskMode = kwargs.pop('maskMode', 'isolate') # type: str
86
+ maskAlpha = kwargs.pop('maskAlpha', 0.6) # type: float
87
+ faceMode = kwargs.pop('faceMode', 'box') # type: str
88
+ annotationsReady = kwargs.pop('annotationsReady', None) # type: callable | None
89
+ resultsReady = kwargs.pop('resultsReady', None) # type: callable | None
90
+ colorAppeared = kwargs.pop('colorAppeared', None) # type: callable | None
91
+ super(AnalysisController, self).__init__(*args, **kwargs)
92
+ for signal, slot in ((self.annotationsReady, annotationsReady), (self.resultsReady, resultsReady),
93
+ (self.colorAppeared, colorAppeared)):
94
+ if callable(slot):
95
+ signal.connect(slot)
96
+ self.__m_colors = colorDetector if colorDetector is not None else ColorDetector(parent=self)
97
+ self.__m_faces = faceDetector if faceDetector is not None else FaceDetector(parent=self)
98
+ self.__m_client = client
99
+ self.__m_rateHz = max(0.5, min(60.0, float(rateHz))) # type: float
100
+ self.__m_colorEnabled = bool(colorEnabled) # type: bool
101
+ self.__m_faceEnabled = bool(faceEnabled) # type: bool
102
+ self.__m_useRemote = bool(useRemote) # type: bool
103
+ self.__m_showBoxes = bool(showBoxes) # type: bool
104
+ self.__m_showMask = bool(showMask) # type: bool
105
+ self.__m_maskMode = 'tint' if u'{}'.format(maskMode) == 'tint' else 'isolate' # type: str
106
+ self.__m_maskAlpha = max(0.0, min(1.0, float(maskAlpha))) # type: float
107
+ self.__m_faceMode = u'{}'.format(faceMode) if u'{}'.format(faceMode) in ('box', 'landmarks', 'blur') else 'box' # type: str
108
+ # State.
109
+ self.__m_frames = {} # type: dict # source -> newest QImage
110
+ self.__m_origins = {} # type: dict # source -> [x, y, dpr] screen position of that frame (or None)
111
+ self.__m_dirty = set() # type: set
112
+ self.__m_present = {} # type: dict # source -> set of visible target names (alerts)
113
+ self.__m_generation = 0 # type: int
114
+ self.__m_last = {} # type: dict # source -> last published result
115
+ self.__m_analysed = {} # type: dict # source -> (frame fingerprint, generation) last dispatched
116
+ # Worker thread.
117
+ self.__m_cond = Condition() # type: Condition
118
+ self.__m_jobs = {} # type: dict # source -> (QImage, generation)
119
+ self.__m_running = True # type: bool
120
+ self.__m_thread = Thread(target=self._work, name='AnalysisWorker') # type: Thread
121
+ self.__m_thread.daemon = True
122
+ self.__m_thread.start()
123
+ self._workerDone.connect(self._onLocalDone, Qt.QueuedConnection)
124
+ # Any detector setting change invalidates in-flight work and re-analyses the last frames.
125
+ self.__m_colors.targetsChanged.connect(self.reanalyse)
126
+ self.__m_colors.settingsChanged.connect(self.reanalyse)
127
+ self.__m_faces.backendChanged.connect(self.reanalyse)
128
+ if client is not None:
129
+ client.analysisReady.connect(self._onRemoteDone)
130
+ self.__m_timer = QTimer(self) # type: QTimer
131
+ self.__m_timer.timeout.connect(self._tick)
132
+ self._updateTimer()
133
+
134
+ # ---------- Helpers ----------
135
+ def _active(self):
136
+ """
137
+ :return: bool
138
+ """
139
+ return self.__m_colorEnabled or self.__m_faceEnabled
140
+
141
+ def _remote(self):
142
+ """
143
+ :return: (bool) Analyse on the server right now.
144
+ """
145
+ return self.__m_useRemote and self.__m_client is not None and self.__m_client.isReady()
146
+
147
+ def _updateTimer(self):
148
+ """
149
+ :return:
150
+ """
151
+ if self._active():
152
+ self.__m_timer.start(int(round(1000.0 / self.__m_rateHz)))
153
+ else:
154
+ self.__m_timer.stop()
155
+
156
+ def _changed(self, reanalyse=True):
157
+ """
158
+ A setting changed: drop in-flight results, re-analyse the last frames, clear when disabled.
159
+ :param reanalyse: bool
160
+ :return:
161
+ """
162
+ self.__m_generation += 1
163
+ self._updateTimer()
164
+ if not self._active():
165
+ for source in list(self.__m_frames):
166
+ self.annotationsReady.emit(source, [], QSize(), QImage(), None)
167
+ self.__m_present = {} # type: dict
168
+ elif reanalyse:
169
+ self.__m_dirty.update(self.__m_frames.keys())
170
+ self.settingsChanged.emit()
171
+
172
+ def _work(self):
173
+ """
174
+ Worker thread: always analyse the newest job of each source.
175
+ :return:
176
+ """
177
+ while True:
178
+ with self.__m_cond:
179
+ while self.__m_running and not self.__m_jobs:
180
+ self.__m_cond.wait()
181
+ if not self.__m_running:
182
+ return
183
+ source = next(iter(self.__m_jobs)) # type: str
184
+ image, generation, origin = self.__m_jobs.pop(source)
185
+ try:
186
+ result, mask = self._analyseLocal(image)
187
+ except Exception as e:
188
+ result, mask = {'error': u'{}'.format(e)}, QImage()
189
+ result['origin'] = origin
190
+ self._workerDone.emit(source, result, mask, generation)
191
+
192
+ def _analyseLocal(self, image):
193
+ """
194
+ :param image: QImage
195
+ :return: (tuple[dict, QImage]) Result and label mask.
196
+ """
197
+ result, mask = {}, QImage() # type: dict, QImage
198
+ if self.__m_colorEnabled:
199
+ colors = self.__m_colors.analyze(image) # type: dict
200
+ label = colors.pop('labelMask', None)
201
+ mask = label if label is not None else QImage() # type: QImage
202
+ result['colors'] = colors
203
+ if self.__m_faceEnabled:
204
+ result['faces'] = self.__m_faces.detect(image)
205
+ return result, mask
206
+
207
+ def _params(self):
208
+ """
209
+ :return: (dict) Analysis settings in the AnalysisServer protocol format.
210
+ """
211
+ cd = self.__m_colors # type: ColorDetector
212
+ fd = self.__m_faces # type: FaceDetector
213
+ return {'colors': {'enabled': self.__m_colorEnabled,
214
+ 'targets': [u'{}'.format(c.name()) for c in cd.getTargetColors()],
215
+ 'tolerance': cd.getTolerance(), 'minArea': cd.getMinArea(),
216
+ 'palette': cd.getPaletteSize(), 'mask': self.__m_showMask,
217
+ 'matchMode': int(cd.getMatchMode()), 'groupDistance': cd.getGroupDistance()},
218
+ 'faces': {'enabled': self.__m_faceEnabled, 'backend': fd.getBackend(),
219
+ 'score': fd.getScoreThreshold(), 'minSize': fd.getMinFaceSize()},
220
+ 'generation': self.__m_generation}
221
+
222
+ @pyqtSlot()
223
+ def _tick(self):
224
+ """
225
+ Rate limiter: dispatch the newest frame of every source that changed.
226
+ :return:
227
+ """
228
+ for source in list(self.__m_dirty):
229
+ image = self.__m_frames.get(source) # type: QImage
230
+ self.__m_dirty.discard(source)
231
+ if image is None or image.isNull():
232
+ continue
233
+ stamp = (frameKey(image), self.__m_generation, self._remote()) # type: tuple
234
+ if self.__m_analysed.get(source) == stamp:
235
+ continue # Same pixels, same settings: the published result is still valid.
236
+ self.__m_analysed[source] = stamp
237
+ if self._remote():
238
+ scale = min(1.0, REMOTE_MAX_SIDE / float(max(image.width(), image.height()))) # type: float
239
+ img = image if scale >= 1.0 else image.scaled(int(image.width() * scale), int(image.height() * scale),
240
+ Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
241
+ params = self._params() # type: dict
242
+ origin = self.__m_origins.get(source) # type: list | None
243
+ params['origin'] = [origin[0], origin[1], origin[2] * min(1.0, scale)] if origin else None
244
+ self.__m_client.requestAnalysis(source, img, params)
245
+ else:
246
+ with self.__m_cond:
247
+ self.__m_jobs[source] = (image.copy(), self.__m_generation, self.__m_origins.get(source))
248
+ self.__m_cond.notify()
249
+
250
+ def _onLocalDone(self, source, result, mask, generation):
251
+ """
252
+ :param source: str | unicode | QString
253
+ :param result: dict
254
+ :param mask: QImage
255
+ :param generation: int
256
+ :return:
257
+ """
258
+ if generation == self.__m_generation and self._active():
259
+ self._publish(u'{}'.format(source), result, mask)
260
+
261
+ def _onRemoteDone(self, source, result, mask):
262
+ """
263
+ :param source: str | unicode | QString
264
+ :param result: dict
265
+ :param mask: QImage
266
+ :return:
267
+ """
268
+ if self._active() and self.__m_useRemote:
269
+ self._publish(u'{}'.format(source), result, mask)
270
+
271
+ def _publish(self, source, result, mask):
272
+ """
273
+ :param source: str | unicode | QString
274
+ :param result: dict
275
+ :param mask: QImage
276
+ :return:
277
+ """
278
+ colors = result.get('colors') or {} # type: dict
279
+ faces = result.get('faces') or {} # type: dict
280
+ w = colors.get('width') or faces.get('width') or 0 # type: int
281
+ h = colors.get('height') or faces.get('height') or 0 # type: int
282
+ annotations = [] # type: list
283
+ if self.__m_colorEnabled and self.__m_showBoxes:
284
+ for d in colors.get('detections', []):
285
+ annotations.append({'rect': d['rect'], 'color': d['color'], 'label': d['name']})
286
+ if self.__m_faceEnabled:
287
+ for f in faces.get('faces', []):
288
+ if self.__m_faceMode == 'blur':
289
+ annotations.append({'rect': f['rect'], 'style': 'blur', 'blocks': 10})
290
+ else:
291
+ annotations.append({'rect': f['rect'], 'color': FACE_COLOR,
292
+ 'label': 'face {:.0f}%'.format(100.0 * float(f.get('score', 1.0))),
293
+ 'points': f.get('landmarks', []) if self.__m_faceMode == 'landmarks' else []})
294
+ overlay = QImage() # type: QImage
295
+ if self.__m_colorEnabled and self.__m_showMask and mask is not None and not mask.isNull():
296
+ overlay = maskToOverlay(mask, self.__m_colors.getTargetColors(), self.__m_maskAlpha, self.__m_maskMode)
297
+ self.__m_last[source] = result
298
+ self.annotationsReady.emit(source, annotations, QSize(int(w), int(h)), overlay, result.get('origin'))
299
+ self.resultsReady.emit(source, result)
300
+ names = set(d['name'] for d in colors.get('detections', [])) # type: set
301
+ for name in sorted(names - self.__m_present.get(source, set())):
302
+ self.colorAppeared.emit(source, name)
303
+ self.__m_present[source] = names
304
+
305
+ # ---------- Public API ----------
306
+ def submit(self, source, image, origin=None, dpr=1.0):
307
+ """
308
+ Offer a new frame; it is analysed at the configured rate (newest frame wins).
309
+ :param source: (str | unicode | QString) 'view', 'lens', ...
310
+ :param image: QImage
311
+ :param origin: (QPoint | None) Screen position of the frame (top-left): results carry it so annotations
312
+ can follow moving content.
313
+ :param dpr: (float | int) Frame pixels per screen point.
314
+ :return:
315
+ """
316
+ if self._active() and image is not None and not image.isNull():
317
+ self.__m_frames[u'{}'.format(source)] = image
318
+ self.__m_origins[u'{}'.format(source)] = [origin.x(), origin.y(), float(dpr)] if origin is not None else None
319
+ self.__m_dirty.add(u'{}'.format(source))
320
+
321
+ @pyqtSlot('QString')
322
+ @pyqtSlot(str)
323
+ def forget(self, source):
324
+ """
325
+ Stop analyzing a source (e.g. the lens was hidden) and clear its annotations.
326
+ :param source: str | unicode | QString
327
+ :return:
328
+ """
329
+ self.__m_frames.pop(u'{}'.format(source), None)
330
+ self.__m_analysed.pop(u'{}'.format(source), None)
331
+ self.__m_dirty.discard(u'{}'.format(source))
332
+ self.__m_present.pop(u'{}'.format(source), None)
333
+ self.annotationsReady.emit(u'{}'.format(source), [], QSize(), QImage(), None)
334
+
335
+ @pyqtSlot()
336
+ def reanalyse(self):
337
+ """
338
+ Settings of the detectors changed: analyse the last frames again.
339
+ :return:
340
+ """
341
+ self._changed()
342
+
343
+ @pyqtSlot()
344
+ def shutdown(self):
345
+ """
346
+ Stop the worker thread (call before quitting).
347
+ :return:
348
+ """
349
+ self.__m_timer.stop()
350
+ with self.__m_cond:
351
+ self.__m_running = False # type: bool
352
+ self.__m_cond.notify()
353
+ self.__m_thread.join(1.0)
354
+
355
+ def getLastResult(self, source):
356
+ """
357
+ :param source: str | unicode | QString
358
+ :return: (dict) Last published result for a source ({} if none).
359
+ """
360
+ return dict(self.__m_last.get(u'{}'.format(source), {}))
361
+
362
+ def getColorDetector(self):
363
+ """
364
+ :return: ColorDetector
365
+ """
366
+ return self.__m_colors
367
+
368
+ def getFaceDetector(self):
369
+ """
370
+ :return: FaceDetector
371
+ """
372
+ return self.__m_faces
373
+
374
+ def isRemoteActive(self):
375
+ """
376
+ :return: (bool) Analyses are currently sent to the server.
377
+ """
378
+ return self._remote()
379
+
380
+ def getRateHz(self):
381
+ """
382
+ :return: float | int
383
+ """
384
+ return self.__m_rateHz
385
+
386
+ @pyqtSlot(float)
387
+ @pyqtSlot(int)
388
+ def setRateHz(self, rateHz):
389
+ """
390
+ :param rateHz: (float | int) 0.5 .. 60
391
+ :return:
392
+ """
393
+ self.__m_rateHz = max(0.5, min(60.0, float(rateHz))) # type: float
394
+ self._updateTimer()
395
+
396
+ def isColorEnabled(self):
397
+ """
398
+ :return: bool
399
+ """
400
+ return self.__m_colorEnabled
401
+
402
+ @pyqtSlot(bool)
403
+ @pyqtSlot(int)
404
+ def setColorEnabled(self, colorEnabled):
405
+ """
406
+ :param colorEnabled: bool
407
+ :return:
408
+ """
409
+ self.__m_colorEnabled = bool(colorEnabled) # type: bool
410
+ self._changed()
411
+
412
+ def isFaceEnabled(self):
413
+ """
414
+ :return: bool
415
+ """
416
+ return self.__m_faceEnabled
417
+
418
+ @pyqtSlot(bool)
419
+ @pyqtSlot(int)
420
+ def setFaceEnabled(self, faceEnabled):
421
+ """
422
+ :param faceEnabled: bool
423
+ :return:
424
+ """
425
+ self.__m_faceEnabled = bool(faceEnabled) # type: bool
426
+ self._changed()
427
+
428
+ def isUseRemote(self):
429
+ """
430
+ :return: bool
431
+ """
432
+ return self.__m_useRemote
433
+
434
+ @pyqtSlot(bool)
435
+ @pyqtSlot(int)
436
+ def setUseRemote(self, useRemote):
437
+ """
438
+ :param useRemote: bool
439
+ :return:
440
+ """
441
+ self.__m_useRemote = bool(useRemote) # type: bool
442
+ self._changed()
443
+
444
+ def isShowBoxes(self):
445
+ """
446
+ :return: bool
447
+ """
448
+ return self.__m_showBoxes
449
+
450
+ @pyqtSlot(bool)
451
+ @pyqtSlot(int)
452
+ def setShowBoxes(self, showBoxes):
453
+ """
454
+ :param showBoxes: bool
455
+ :return:
456
+ """
457
+ self.__m_showBoxes = bool(showBoxes) # type: bool
458
+ self._changed()
459
+
460
+ def isShowMask(self):
461
+ """
462
+ :return: bool
463
+ """
464
+ return self.__m_showMask
465
+
466
+ @pyqtSlot(bool)
467
+ @pyqtSlot(int)
468
+ def setShowMask(self, showMask):
469
+ """
470
+ :param showMask: bool
471
+ :return:
472
+ """
473
+ self.__m_showMask = bool(showMask) # type: bool
474
+ self.__m_colors.setReturnMask(self.__m_showMask)
475
+ self._changed()
476
+
477
+ def getMaskMode(self):
478
+ """
479
+ :return: str | unicode | QString
480
+ """
481
+ return self.__m_maskMode
482
+
483
+ @pyqtSlot('QString')
484
+ @pyqtSlot(str)
485
+ def setMaskMode(self, maskMode):
486
+ """
487
+ :param maskMode: (str | unicode | QString) 'isolate' or 'tint'.
488
+ :return:
489
+ """
490
+ self.__m_maskMode = 'tint' if u'{}'.format(maskMode) == 'tint' else 'isolate' # type: str
491
+ self._changed()
492
+
493
+ def getMaskAlpha(self):
494
+ """
495
+ :return: float | int
496
+ """
497
+ return self.__m_maskAlpha
498
+
499
+ @pyqtSlot(float)
500
+ def setMaskAlpha(self, maskAlpha):
501
+ """
502
+ :param maskAlpha: (float | int) 0 .. 1
503
+ :return:
504
+ """
505
+ self.__m_maskAlpha = max(0.0, min(1.0, float(maskAlpha))) # type: float
506
+ self._changed()
507
+
508
+ def getFaceMode(self):
509
+ """
510
+ :return: str | unicode | QString
511
+ """
512
+ return self.__m_faceMode
513
+
514
+ @pyqtSlot('QString')
515
+ @pyqtSlot(str)
516
+ def setFaceMode(self, faceMode):
517
+ """
518
+ :param faceMode: (str | unicode | QString) 'box', 'landmarks' or 'blur'.
519
+ :return:
520
+ """
521
+ self.__m_faceMode = u'{}'.format(faceMode) if u'{}'.format(faceMode) in ('box', 'landmarks', 'blur') else 'box' # type: str
522
+ self._changed()
523
+
524
+ # ---------- Properties ----------
525
+ rateHz = pyqtProperty(float, fget=getRateHz, fset=setRateHz) # type: pyqtProperty
526
+ colorEnabled = pyqtProperty(bool, fget=isColorEnabled, fset=setColorEnabled) # type: pyqtProperty
527
+ faceEnabled = pyqtProperty(bool, fget=isFaceEnabled, fset=setFaceEnabled) # type: pyqtProperty
528
+ useRemote = pyqtProperty(bool, fget=isUseRemote, fset=setUseRemote) # type: pyqtProperty
529
+ showBoxes = pyqtProperty(bool, fget=isShowBoxes, fset=setShowBoxes) # type: pyqtProperty
530
+ showMask = pyqtProperty(bool, fget=isShowMask, fset=setShowMask) # type: pyqtProperty
531
+ maskMode = pyqtProperty('QString', fget=getMaskMode, fset=setMaskMode) # type: pyqtProperty
532
+ maskAlpha = pyqtProperty(float, fget=getMaskAlpha, fset=setMaskAlpha) # type: pyqtProperty
533
+ faceMode = pyqtProperty('QString', fget=getFaceMode, fset=setFaceMode) # type: pyqtProperty