forked from davidgrier/pyfab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
h5video.py
62 lines (47 loc) · 1.52 KB
/
h5video.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
"""Create HDF5 video files"""
import h5py
import time
<<<<<<< HEAD
from PyQt4 import QtCore
class h5video(QtCore.QObject):
=======
class h5video(object):
>>>>>>> 6532502fe930486ec1e7d5fabb39cf57644da78f
"""Object for writing HDF5 video files
"""
def __init__(self, filename="h5video.h5", overwrite=False):
if overwrite:
self.file = h5py.File(filename, 'w')
else:
self.file = h5py.File(filename, 'w-')
self.file.attrs['timestamp'] = time.asctime()
self.file.attrs['HDF5_version'] = h5py.version.hdf5_version
self.file.attrs['h5py_version'] = h5py.version.version
self.images = self.file.create_group("images")
self.images.attrs['timestamp'] = time.asctime()
def close(self):
if isinstance(self.file, h5py.File):
self.file.flush()
self.file.close()
self.images = None
self.file = None
def timestamp(self):
return "%.6f" % time.time()
def write(self, image):
<<<<<<< HEAD
print 'h5 write'
=======
>>>>>>> 6532502fe930486ec1e7d5fabb39cf57644da78f
self.images.create_dataset(self.timestamp(), data=image)
def filename(self):
return self.file.filename()
def main():
import numpy as np
video = h5video("junk.h5", overwrite=True)
for i in np.arange(10):
video.write(np.random.randint(0, 256, size=(480, 640),
dtype=np.uint8))
video.close()
if __name__ == "__main__":
main()