etho-python 1.2.4__py3-none-any.whl → 1.2.5__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.
- etho/services/callbacks/_image.py +69 -16
- etho/services/callbacks/_trace.py +12 -10
- {etho_python-1.2.4.dist-info → etho_python-1.2.5.dist-info}/METADATA +2 -1
- {etho_python-1.2.4.dist-info → etho_python-1.2.5.dist-info}/RECORD +7 -7
- {etho_python-1.2.4.dist-info → etho_python-1.2.5.dist-info}/WHEEL +0 -0
- {etho_python-1.2.4.dist-info → etho_python-1.2.5.dist-info}/entry_points.txt +0 -0
- {etho_python-1.2.4.dist-info → etho_python-1.2.5.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Callbacks for processing images."""
|
|
2
2
|
|
|
3
|
-
import logging
|
|
3
|
+
import logging
|
|
4
|
+
from fractions import Fraction
|
|
4
5
|
from xml.dom import NotFoundErr
|
|
5
6
|
import numpy as np
|
|
6
7
|
from . import register_callback
|
|
@@ -15,11 +16,18 @@ try:
|
|
|
15
16
|
import cv2
|
|
16
17
|
|
|
17
18
|
cv2_import_error = None
|
|
18
|
-
except ImportError as cv2_import_error:
|
|
19
|
-
pass
|
|
20
|
-
|
|
21
|
-
try:
|
|
22
|
-
import
|
|
19
|
+
except ImportError as cv2_import_error:
|
|
20
|
+
pass
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
import av
|
|
24
|
+
|
|
25
|
+
av_import_error = None
|
|
26
|
+
except ImportError as av_import_error:
|
|
27
|
+
pass
|
|
28
|
+
|
|
29
|
+
try:
|
|
30
|
+
import ffmpegcv
|
|
23
31
|
|
|
24
32
|
ffmpegcv_import_error = None
|
|
25
33
|
except ImportError as ffmpegcv_import_error:
|
|
@@ -157,7 +165,7 @@ class ImageDisplayPQG(ImageCallback):
|
|
|
157
165
|
|
|
158
166
|
@for_all_methods(log_exceptions(logger))
|
|
159
167
|
@register_callback
|
|
160
|
-
class ImageWriterCV2(ImageCallback):
|
|
168
|
+
class ImageWriterCV2(ImageCallback):
|
|
161
169
|
"""Save images to video using opencv's VideoWriter.
|
|
162
170
|
|
|
163
171
|
Fast but little control over video compression quality.
|
|
@@ -202,15 +210,60 @@ class ImageWriterCV2(ImageCallback):
|
|
|
202
210
|
|
|
203
211
|
self.vw.write(image)
|
|
204
212
|
|
|
205
|
-
def _cleanup(self):
|
|
206
|
-
self.vw.release()
|
|
207
|
-
del self.vw
|
|
208
|
-
super()._cleanup()
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
@for_all_methods(log_exceptions(logger))
|
|
212
|
-
@register_callback
|
|
213
|
-
class
|
|
213
|
+
def _cleanup(self):
|
|
214
|
+
self.vw.release()
|
|
215
|
+
del self.vw
|
|
216
|
+
super()._cleanup()
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
@for_all_methods(log_exceptions(logger))
|
|
220
|
+
@register_callback
|
|
221
|
+
class ImageWriterPyAV(ImageCallback):
|
|
222
|
+
"""Save H.264 video using PyAV."""
|
|
223
|
+
|
|
224
|
+
SUFFIX: str = ".mp4"
|
|
225
|
+
FRIENDLY_NAME = "save_pyav"
|
|
226
|
+
TIMESTAMPS_ONLY = False
|
|
227
|
+
|
|
228
|
+
def __init__(self, data_source, *, poll_timeout=0.01, **kwargs):
|
|
229
|
+
super().__init__(data_source=data_source, poll_timeout=poll_timeout, **kwargs)
|
|
230
|
+
|
|
231
|
+
if av_import_error is not None:
|
|
232
|
+
logger.exception("Could not import PyAV. Aborting!", exc_info=av_import_error)
|
|
233
|
+
raise av_import_error
|
|
234
|
+
|
|
235
|
+
self.container = None
|
|
236
|
+
|
|
237
|
+
def _loop(self, data):
|
|
238
|
+
if hasattr(self.data_source, "WHOAMI") and self.data_source.WHOAMI == "array":
|
|
239
|
+
image = data
|
|
240
|
+
else:
|
|
241
|
+
image, timestamp = data
|
|
242
|
+
|
|
243
|
+
if self.container is None:
|
|
244
|
+
self.container = av.open(self.file_name + self.SUFFIX, "w")
|
|
245
|
+
self.stream = self.container.add_stream("libx264", rate=Fraction(str(self.frame_rate)))
|
|
246
|
+
self.stream.width = image.shape[1]
|
|
247
|
+
self.stream.height = image.shape[0]
|
|
248
|
+
self.stream.pix_fmt = "yuv420p"
|
|
249
|
+
|
|
250
|
+
frame_format = "gray" if image.ndim == 2 else "bgr24"
|
|
251
|
+
frame = av.VideoFrame.from_ndarray(image, format=frame_format)
|
|
252
|
+
for packet in self.stream.encode(frame):
|
|
253
|
+
self.container.mux(packet)
|
|
254
|
+
|
|
255
|
+
def _cleanup(self):
|
|
256
|
+
if self.container is not None:
|
|
257
|
+
for packet in self.stream.encode():
|
|
258
|
+
self.container.mux(packet)
|
|
259
|
+
self.container.close()
|
|
260
|
+
self.container = None
|
|
261
|
+
super()._cleanup()
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
@for_all_methods(log_exceptions(logger))
|
|
265
|
+
@register_callback
|
|
266
|
+
class ImageWriterFCV(ImageCallback):
|
|
214
267
|
"""Save images to video using ffmpegcv.
|
|
215
268
|
|
|
216
269
|
Supports hardware accelerated encoding
|
|
@@ -220,14 +220,16 @@ class SaveZarr(BaseCallback):
|
|
|
220
220
|
raise zarr_import_error
|
|
221
221
|
self.file_name = file_name
|
|
222
222
|
# Backward compatibility for Zarr 2; remove when Python 3.10 support ends.
|
|
223
|
-
if hasattr(zarr, "DirectoryStore"):
|
|
224
|
-
self.f = zarr.DirectoryStore(self.file_name + self.SUFFIX)
|
|
225
|
-
self.arrays = zarr.group(self.f, overwrite=True)
|
|
226
|
-
self._create_array = self.arrays.create_dataset
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
self.
|
|
230
|
-
self.
|
|
223
|
+
if hasattr(zarr, "DirectoryStore"):
|
|
224
|
+
self.f = zarr.DirectoryStore(self.file_name + self.SUFFIX)
|
|
225
|
+
self.arrays = zarr.group(self.f, overwrite=True)
|
|
226
|
+
self._create_array = self.arrays.create_dataset
|
|
227
|
+
self._auto_chunks = True
|
|
228
|
+
else:
|
|
229
|
+
self.f = zarr.storage.LocalStore(self.file_name + self.SUFFIX)
|
|
230
|
+
self.arrays = zarr.group(self.f, overwrite=True, zarr_format=2)
|
|
231
|
+
self._create_array = self.arrays.create_array
|
|
232
|
+
self._auto_chunks = "auto"
|
|
231
233
|
self.vanilla: bool = True
|
|
232
234
|
|
|
233
235
|
self.attrs = attrs
|
|
@@ -245,10 +247,10 @@ class SaveZarr(BaseCallback):
|
|
|
245
247
|
for key, val in self.attrs.items():
|
|
246
248
|
self.arrays["samples"].attrs[key] = val
|
|
247
249
|
|
|
248
|
-
self._create_array("systemtime", shape=(0, 1), chunks=
|
|
250
|
+
self._create_array("systemtime", shape=(0, 1), chunks=self._auto_chunks, dtype=systemtime.dtype, compressor=compressor)
|
|
249
251
|
|
|
250
252
|
sn = np.array(data.shape[:1])[:, np.newaxis]
|
|
251
|
-
self._create_array("samplenumber", shape=(0, 1), chunks=
|
|
253
|
+
self._create_array("samplenumber", shape=(0, 1), chunks=self._auto_chunks, dtype=sn.dtype, compressor=compressor)
|
|
252
254
|
# print([(k, v.shape) for k, v in self.arrays.items()])
|
|
253
255
|
|
|
254
256
|
def _append_data(self, data, systemtime):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: etho-python
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.5
|
|
4
4
|
Summary: etho
|
|
5
5
|
Author-email: Jan Clemens <clemensjan@googlemail.com>
|
|
6
6
|
Requires-Python: >=3.10
|
|
@@ -12,6 +12,7 @@ Requires-Dist: numpy; python_version >= "3.11"
|
|
|
12
12
|
Requires-Dist: scipy
|
|
13
13
|
Requires-Dist: h5py
|
|
14
14
|
Requires-Dist: opencv-python-headless
|
|
15
|
+
Requires-Dist: av>=16,<18
|
|
15
16
|
Requires-Dist: bleak
|
|
16
17
|
Requires-Dist: pandas
|
|
17
18
|
Requires-Dist: pyzmq
|
|
@@ -19,8 +19,8 @@ etho/services/__init__.py,sha256=2H6Sm-5qeyRDRnNYWVTFlqwtLjum-0qVGcBALNAqxgs,134
|
|
|
19
19
|
etho/services/resumable.py,sha256=OPHXhfH0G3iDvuUoeJz3gJiRpLrdSRywJfxqzi2SKHY,17956
|
|
20
20
|
etho/services/callbacks/__init__.py,sha256=XGD_-ZGuYvPOKXn_u3MOYVMC-aa6AFN0HqlB3RXV-pU,550
|
|
21
21
|
etho/services/callbacks/_base.py,sha256=Kd1BdkTgMtg4FzKH7XwzJjmFaJw6BkgKupSiHr8ChPs,2673
|
|
22
|
-
etho/services/callbacks/_image.py,sha256=
|
|
23
|
-
etho/services/callbacks/_trace.py,sha256=
|
|
22
|
+
etho/services/callbacks/_image.py,sha256=9dFPNDvQBxWxPRBNkwvPOU01wji-x3dy83jPDODOzXU,29426
|
|
23
|
+
etho/services/callbacks/_trace.py,sha256=swhn6FAFM8jAgSM_mrsQnas091xmLQ7thJztaXqZWyw,14338
|
|
24
24
|
etho/services/camera/__init__.py,sha256=sHJfESDswESrODpJaTDaQTE8HyMd1h_vl6CrMkEzNlc,365
|
|
25
25
|
etho/services/camera/base.py,sha256=RqaeZGl-PCLaha6fq6OyOni1vPja5oP2xoOa25TOv-A,3646
|
|
26
26
|
etho/services/camera/basler.py,sha256=Snz060KZWejB6A3DI3fPof8b2G6noJ85U-V9mIUgafc,7003
|
|
@@ -42,8 +42,8 @@ etho/utils/runner.py,sha256=XiUWQp0ua1DYwHUdgBr5Z_lz5ZVxBVCidPBgjckEaH8,4171
|
|
|
42
42
|
etho/utils/sound.py,sha256=UUN8AReClsNX6aBtluwWWjNuztk-Xh8m9PsiNmA1cAQ,11704
|
|
43
43
|
etho/utils/tui.py,sha256=zPaV5ItzOa3QuC3DGMNcTWM4N3El87hnAnTy51lacHs,3777
|
|
44
44
|
etho/utils/zeroclient.py,sha256=3wHR9rtHlESLu9UR1hZRsVisGNpLJKYv2m0sIJUbT08,3498
|
|
45
|
-
etho_python-1.2.
|
|
46
|
-
etho_python-1.2.
|
|
47
|
-
etho_python-1.2.
|
|
48
|
-
etho_python-1.2.
|
|
49
|
-
etho_python-1.2.
|
|
45
|
+
etho_python-1.2.5.dist-info/entry_points.txt,sha256=Y9LGGC-42Xm1bv62a_IiLYVq8T2HoPO5fLypuFfqamo,38
|
|
46
|
+
etho_python-1.2.5.dist-info/licenses/LICENSE,sha256=DpD3ghQH7qR9cJdLW41cPartvauhOgGI0CeEXtoWNyI,1068
|
|
47
|
+
etho_python-1.2.5.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
|
|
48
|
+
etho_python-1.2.5.dist-info/METADATA,sha256=UN7hObi_Q2zJh2jUSl5JAnMa-pZ40MIcx4nITPHuOjw,6111
|
|
49
|
+
etho_python-1.2.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|