-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdouble_click_saver.py
executable file
·79 lines (56 loc) · 2.52 KB
/
double_click_saver.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python
from camera import camera
import h5py
import time
import os
import numpy as np
try:
import simplejpeg
except ImportError:
import complexjpeg as simplejpeg
def main():
import optparse
parser = optparse.OptionParser()
parser.add_option('-d', '--directory', type=str, help='directory')
parser.add_option('-n', '--name_pattern', type=str, help='filename template')
parser.add_option('-y', '--click_y', type=float, help='click y')
parser.add_option('-x', '--click_x', type=float, help='click x')
parser.add_option('-t', '--timestamp', default=None, type=float, help='if specified will look for image in history corresponding to the timestamp instead of grabing a new one')
options, args = parser.parse_args()
cam = camera()
s = time.time()
click = np.array([options.click_y, options.click_x])
if options.timestamp != None:
image = cam.get_image_corresponding_to_timestamp(options.timestamp)
else:
image = cam.get_image()
zoom = cam.get_zoom()
calibration = cam.get_calibration()
e = time.time()
print('image read in %.3f seconds' % (e-s))
if not os.path.isdir(options.directory):
os.makedirs(options.directory)
s = time.time()
image_filename = '%s_double_click_zoom_%d_y_%d_x_%d.jpg' % (os.path.join(options.directory, options.name_pattern), int(zoom), int(click[0]), int(click[1]))
cam.save_image(image_filename)
double_click_file = h5py.File('%s_double_click.h5' % os.path.join(options.directory, options.name_pattern), 'w')
#dt = h5py.special_dtype(vlen=np.dtype('uint8'))
jpeg = simplejpeg.encode_jpeg(image)
jpeg = np.frombuffer(jpeg, dtype='uint8')
double_click_file.create_dataset('image',
data=jpeg)
#double_click_file.create_dataset('image',
#data=image,
#compression='gzip',
#dtype=np.uint8)
double_click_file.create_dataset('zoom',
data=int(zoom))
double_click_file.create_dataset('click',
data=click)
double_click_file.create_dataset('calibration',
data=calibration)
double_click_file.close()
e = time.time()
print('double click written in %.3f seconds' % (e-s))
if __name__ == '__main__':
main()