-
Notifications
You must be signed in to change notification settings - Fork 0
/
getframes.py
executable file
·50 lines (37 loc) · 1.08 KB
/
getframes.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
#!/usr/bin/python
# Tool for extracting single images from big raw files generated by Kitaev
from numpy import *
import sys
import scipy
import os
try:
input_file = sys.argv[1]
output_dir = sys.argv[2]
except:
print 'wrong parameters'
print 'usage: %s input_file output_dir [first_frame] [last_frame]' % sys.argv[0]
sys.exit(1)
filesize = os.path.getsize(input_file)
f = open(input_file)
(w,h) = frombuffer(f.read(8),int,2)
framesize = w * h * 3
nframes = filesize / framesize
print 'dimensions: %i, %i, number of frames: %i' % (w, h, nframes)
try:
first = int(sys.argv[3])
last = int(sys.argv[4])
except:
first = 0
last = nframes - 1
print 'first frame: %i, last frame: %i' % (first, last)
f.seek(8 + framesize*first)
for i in range(last-first+1):
buf = f.read(framesize)
data = frombuffer(buf,uint8)
data = data.reshape((h,w,3))
number = '00000000000%i' % (first+i)
number = number[len(number)-len(str(last)):]
output_file = "%s/%s.jpg" % (output_dir, number)
scipy.misc.imsave(output_file, data)
print output_file
f.close()