6 import sys, os, os.path, glob, math, cv2
7 from datetime import datetime
10 plot_colors = ['b', 'c', 'r', 'g', 'm']
13 bgr = { "red" : ( 0, 0, 255),
14 "green" : ( 0, 255, 0),
15 "blue" : (255, 0 , 0)}
19 lb, rb = map(int, s.split(','))
22 raise argparse.ArgumentTypeError("Must be lb, rb")
24 def call_parser(f, a):
25 return eval( "sft.parse_" + f + "('" + a + "')")
27 if __name__ == "__main__":
28 parser = argparse.ArgumentParser(description = 'Plot ROC curve using Caltech method of per image detection performance estimation.')
31 parser.add_argument("cascade", help = "Path to the tested detector.", nargs='+')
32 parser.add_argument("input", help = "Image sequence pattern.")
33 parser.add_argument("annotations", help = "Path to the annotations.")
36 parser.add_argument("-m", "--min_scale", dest = "min_scale", type = float, metavar= "fl", help = "Minimum scale to be tested.", default = 0.4)
37 parser.add_argument("-M", "--max_scale", dest = "max_scale", type = float, metavar= "fl", help = "Maximum scale to be tested.", default = 5.0)
38 parser.add_argument("-o", "--output", dest = "output", type = str, metavar= "path", help = "Path to store resulting image.", default = "./roc.png")
39 parser.add_argument("-n", "--nscales", dest = "nscales", type = int, metavar= "n", help = "Preferred count of scales from min to max.", default = 55)
41 parser.add_argument("-r", "--scale-range", dest = "scale_range", type = range, default = (128 * 0.4, 128 * 2.4))
42 parser.add_argument("-e", "--extended-range-ratio", dest = "ext_ratio", type = float, default = 1.25)
43 parser.add_argument("-t", "--title", dest = "title", type = str, default = "ROC curve Bahnhof")
46 parser.add_argument("-f", "--anttn-format", dest = "anttn_format", choices = ['inria', 'caltech', "idl"], help = "Annotation file for test sequence.", required = True)
47 parser.add_argument("-l", "--labels", dest = "labels" ,required=True, help = "Plot labels for legend.", nargs='+')
49 args = parser.parse_args()
51 print args.scale_range
55 sft.initPlot(args.title)
56 samples = call_parser(args.anttn_format, args.annotations)
57 for idx, each in enumerate(args.cascade):
59 cascade = sft.cascade(args.min_scale, args.max_scale, args.nscales, each)
61 camera = cv2.VideoCapture(pattern)
63 # for plotting over dataset
72 ret, img = camera.read()
76 name = pattern % (nframes,)
77 _, tail = os.path.split(name)
79 boxes = sft.filter_for_range(samples[tail], args.scale_range, args.ext_ratio)
81 nannotated = nannotated + len(boxes)
83 rects, confs = cascade.detect(img, rois = None)
88 dts = sft.convert2detections(rects, confs)
90 confs = confs.tolist()[0]
91 confs.sort(lambda x, y : -1 if (x - y) > 0 else 1)
92 confidenses = confidenses + confs
94 matched, skip_list = sft.match(boxes, dts)
96 ignored = ignored + skip_list
98 print nframes, nannotated
100 fppi, miss_rate = sft.computeROC(confidenses, tp, nannotated, nframes, ignored)
101 sft.plotLogLog(fppi, miss_rate, plot_colors[idx])
103 sft.showPlot(args.output, args.labels)