Created
May 15, 2014 16:11
-
-
Save psycharo-zz/7e6422a491d93e1e3219 to your computer and use it in GitHub Desktop.
reading .seq files from caltech pedestrian dataset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def read_seq(path): | |
def read_header(ifile): | |
feed = ifile.read(4) | |
norpix = ifile.read(24) | |
version = struct.unpack('@i', ifile.read(4)) | |
length = struct.unpack('@i', ifile.read(4)) | |
assert(length != 1024) | |
descr = ifile.read(512) | |
params = [struct.unpack('@i', ifile.read(4))[0] for i in range(0,9)] | |
fps = struct.unpack('@d', ifile.read(8)) | |
# skipping the rest | |
ifile.read(432) | |
image_ext = {100:'raw', 102:'jpg',201:'jpg',1:'png',2:'png'} | |
return {'w':params[0],'h':params[1], | |
'bdepth':params[2], | |
'ext':image_ext[params[5]], | |
'format':params[5], | |
'size':params[4], | |
'true_size':params[8], | |
'num_frames':params[6]} | |
ifile = open(path, 'rb') | |
params = read_header(ifile) | |
bytes = open(path, 'rb').read() | |
# this is freaking magic, but it works | |
extra = 8 | |
s = 1024 | |
seek = [0]*(params['num_frames']+1) | |
seek[0] = 1024 | |
images = [] | |
for i in range(0, params['num_frames']): | |
tmp = struct.unpack_from('@I', bytes[s:s+4])[0] | |
s = seek[i] + tmp + extra | |
if i == 0: | |
val = struct.unpack_from('@B', bytes[s:s+1])[0] | |
if val != 0: | |
s -= 4 | |
else: | |
extra += 8 | |
s += 8 | |
seek[i+1] = s | |
nbytes = struct.unpack_from('@i', bytes[s:s+4])[0] | |
I = bytes[s+4:s+nbytes] | |
tmp_file = '/tmp/img%d.jpg' % i | |
open(tmp_file, 'wb+').write(I) | |
img = cv2.imread(tmp_file) | |
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) | |
images.append(img) | |
return images |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What all packages are required to run this Code? I am not getting any output now.