Instantly share code, notes, and snippets.

What would you like to do?
reading .seq files from caltech pedestrian dataset
def read_seq(path):
def read_header(ifile):
feed =
norpix =
version = struct.unpack('@i',
length = struct.unpack('@i',
assert(length != 1024)
descr =
params = [struct.unpack('@i',[0] for i in range(0,9)]
fps = struct.unpack('@d',
# skipping the rest
image_ext = {100:'raw', 102:'jpg',201:'jpg',1:'png',2:'png'}
return {'w':params[0],'h':params[1],
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
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)
return images

This comment has been minimized.

anupamsobti commented May 18, 2017

Does this work?
I got the following error while I was trying this:

    nbytes = struct.unpack_from('@i', bytes[s:s+4])[0]
struct.error: unpack_from requires a buffer of at least 4 bytes

This comment has been minimized.

mckees commented May 22, 2017

@anupamsobti it looks like the last bytes that it tries to unpack are blank. I just got it working by changing line 35.
for i in range(0, params['num_frames']-1):

I do have concerns that this might affect how annotations are read, but I haven't gotten there yet.


This comment has been minimized.

PyPatel commented Dec 15, 2017

What all packages are required to run this Code? I am not getting any output now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment