Commit 28098b66 authored by marina.kolpakova's avatar marina.kolpakova

refactor python

parent 8cf30c72
......@@ -11,23 +11,7 @@ if __name__ == "__main__":
path = "/home/kellan/datasets/caltech/set00/V000.txt"
# open annotation file
f = open(path)
(nFrame, nSample) = sft.caltech.parse_header(f)
objects = sft.caltech.extract_objects(f)
caltechSamples = []
annotations = [[] for i in range(nFrame)]
for obj in objects:
(type, start, end) = re.search(r'^lbl=\'(\w+)\'\s+str=(\d+)\s+end=(\d+)\s+hide=0$', obj[0]).groups()
print type, start, end
start = int(start) -1
end = int(end)
pos = sft.caltech.parse_pos(obj[1])
posv = sft.caltech.parse_pos(obj[2])
occl = sft.caltech.parse_occl(obj[3])
for idx, (p, pv, oc) in enumerate(zip(*[pos, posv, occl])):
annotations[start + idx].append((type, p, oc, pv))
annotations = sft.parse_caltech(f)
for each in annotations:
print each
......@@ -259,4 +259,23 @@ class caltech:
def parse_occl(l):
occl = re.match(r'^occl\s*=(\[[\d\s\.\;]+\])$', l).group(1)
occl = re.sub(r"\s(?!\])", ",", occl)
return eval(occl)
\ No newline at end of file
return eval(occl)
def parse_caltech(f):
(nFrame, nSample) = caltech.parse_header(f)
objects = caltech.extract_objects(f)
annotations = [[] for i in range(nFrame)]
for obj in objects:
(type, start, end) = re.search(r'^lbl=\'(\w+)\'\s+str=(\d+)\s+end=(\d+)\s+hide=0$', obj[0]).groups()
print type, start, end
start = int(start) -1
end = int(end)
pos = caltech.parse_pos(obj[1])
posv = caltech.parse_pos(obj[2])
occl = caltech.parse_occl(obj[3])
for idx, (p, pv, oc) in enumerate(zip(*[pos, posv, occl])):
annotations[start + idx].append((type, p, oc, pv))
return annotations
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment