mirror of
https://github.com/opencv/opencv.git
synced 2025-01-18 14:13:15 +08:00
parse Caltech annotations
This commit is contained in:
parent
1fc7134f21
commit
8cf30c728e
33
apps/sft/misc/roc_caltech.py
Executable file
33
apps/sft/misc/roc_caltech.py
Executable file
@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import argparse
|
||||
import sft
|
||||
|
||||
import sys, os, os.path, glob, math, cv2, re
|
||||
from datetime import datetime
|
||||
import numpy
|
||||
|
||||
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))
|
||||
|
||||
for each in annotations:
|
||||
print each
|
@ -9,7 +9,7 @@ import numpy
|
||||
|
||||
plot_colors = ['b', 'c', 'r', 'g', 'm']
|
||||
|
||||
# "key" : ( b, g, r)
|
||||
# "key" : ( b, g, r)
|
||||
bgr = { "red" : ( 0, 0, 255),
|
||||
"green" : ( 0, 255, 0),
|
||||
"blue" : (255, 0 , 0)}
|
||||
|
@ -225,4 +225,38 @@ def resize_sample(image, d_w, d_h):
|
||||
image_to_resize = image
|
||||
interpolation_type = cv2.INTER_CUBIC
|
||||
|
||||
return cv2.resize(image_to_resize,(d_w, d_h), None, 0, 0, interpolation_type)
|
||||
return cv2.resize(image_to_resize,(d_w, d_h), None, 0, 0, interpolation_type)
|
||||
|
||||
newobj = re.compile("^lbl=\'(\w+)\'\s+str=(\d+)\s+end=(\d+)\s+hide=0$")
|
||||
|
||||
class caltech:
|
||||
@staticmethod
|
||||
def extract_objects(f):
|
||||
objects = []
|
||||
tmp = []
|
||||
for l in f:
|
||||
if newobj.match(l) is not None:
|
||||
objects.append(tmp)
|
||||
tmp = []
|
||||
tmp.append(l)
|
||||
return objects[1:]
|
||||
|
||||
@staticmethod
|
||||
def parse_header(f):
|
||||
_ = f.readline() # skip first line (version string)
|
||||
head = f.readline()
|
||||
(nFrame, nSample) = re.search(r'nFrame=(\d+) n=(\d+)', head).groups()
|
||||
return (int(nFrame), int(nSample))
|
||||
|
||||
@staticmethod
|
||||
def parse_pos(l):
|
||||
pos = re.match(r'^posv?\s*=(\[[\d\s\.\;]+\])$', l).group(1)
|
||||
pos = re.sub(r"(\[)(\d)", "\\1[\\2", pos)
|
||||
pos = re.sub(r"\s", ", ", re.sub(r"\;\s+(?=\])", "]", re.sub(r"\;\s+(?!\])", "],[", pos)))
|
||||
return eval(pos)
|
||||
|
||||
@staticmethod
|
||||
def parse_occl(l):
|
||||
occl = re.match(r'^occl\s*=(\[[\d\s\.\;]+\])$', l).group(1)
|
||||
occl = re.sub(r"\s(?!\])", ",", occl)
|
||||
return eval(occl)
|
Loading…
Reference in New Issue
Block a user