refactor python
This commit is contained in:
parent
8cf30c728e
commit
28098b6632
@ -11,23 +11,7 @@ if __name__ == "__main__":
|
|||||||
path = "/home/kellan/datasets/caltech/set00/V000.txt"
|
path = "/home/kellan/datasets/caltech/set00/V000.txt"
|
||||||
# open annotation file
|
# open annotation file
|
||||||
f = open(path)
|
f = open(path)
|
||||||
(nFrame, nSample) = sft.caltech.parse_header(f)
|
annotations = sft.parse_caltech(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))
|
|
||||||
|
|
||||||
for each in annotations:
|
for each in annotations:
|
||||||
print each
|
print each
|
||||||
|
@ -259,4 +259,23 @@ class caltech:
|
|||||||
def parse_occl(l):
|
def parse_occl(l):
|
||||||
occl = re.match(r'^occl\s*=(\[[\d\s\.\;]+\])$', l).group(1)
|
occl = re.match(r'^occl\s*=(\[[\d\s\.\;]+\])$', l).group(1)
|
||||||
occl = re.sub(r"\s(?!\])", ",", occl)
|
occl = re.sub(r"\s(?!\])", ",", occl)
|
||||||
return eval(occl)
|
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
|
Loading…
x
Reference in New Issue
Block a user