mirror of https://github.com/opencv/opencv.git
Open Source Computer Vision Library
https://opencv.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
3.1 KiB
88 lines
3.1 KiB
12 years ago
|
#!/usr/bin/env python
|
||
|
|
||
|
import argparse
|
||
|
import sft
|
||
|
|
||
|
import sys, os, os.path, glob, math, cv2
|
||
|
from datetime import datetime
|
||
|
import numpy
|
||
|
|
||
12 years ago
|
plot_colors = ['b', 'r', 'g', 'c', 'm']
|
||
|
|
||
12 years ago
|
# "key" : ( b, g, r)
|
||
|
bgr = { "red" : ( 0, 0, 255),
|
||
|
"green" : ( 0, 255, 0),
|
||
|
"blue" : (255, 0 , 0)}
|
||
|
|
||
12 years ago
|
def call_parser(f, a):
|
||
|
return eval( "sft.parse_" + f + "('" + a + "')")
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
parser = argparse.ArgumentParser(description = 'Plot ROC curve using Caltech mathod of per image detection performance estimation.')
|
||
|
|
||
|
# positional
|
||
12 years ago
|
parser.add_argument("cascade", help = "Path to the tested detector.", nargs='+')
|
||
12 years ago
|
parser.add_argument("input", help = "Image sequence pattern.")
|
||
|
parser.add_argument("annotations", help = "Path to the annotations.")
|
||
|
|
||
|
# optional
|
||
|
parser.add_argument("-m", "--min_scale", dest = "min_scale", type = float, metavar= "fl", help = "Minimum scale to be tested.", default = 0.4)
|
||
|
parser.add_argument("-M", "--max_scale", dest = "max_scale", type = float, metavar= "fl", help = "Maximum scale to be tested.", default = 5.0)
|
||
|
parser.add_argument("-o", "--output", dest = "output", type = str, metavar= "path", help = "Path to store resultiong image.", default = "./roc.png")
|
||
|
parser.add_argument("-n", "--nscales", dest = "nscales", type = int, metavar= "n", help = "Prefered count of scales from min to max.", default = 55)
|
||
|
|
||
|
# required
|
||
|
parser.add_argument("-f", "--anttn-format", dest = "anttn_format", choices = ['inria', 'caltech', "idl"], help = "Annotation file for test sequence.", required = True)
|
||
|
|
||
|
args = parser.parse_args()
|
||
|
|
||
12 years ago
|
print args.cascade
|
||
|
# # parse annotations
|
||
|
sft.initPlot()
|
||
12 years ago
|
samples = call_parser(args.anttn_format, args.annotations)
|
||
12 years ago
|
for idx, each in enumerate(args.cascade):
|
||
|
print each
|
||
|
cascade = sft.cascade(args.min_scale, args.max_scale, args.nscales, each)
|
||
|
pattern = args.input
|
||
|
camera = cv2.VideoCapture(pattern)
|
||
|
|
||
|
# for plotting over dataset
|
||
|
nannotated = 0
|
||
|
nframes = 0
|
||
12 years ago
|
|
||
12 years ago
|
confidenses = []
|
||
|
tp = []
|
||
12 years ago
|
|
||
12 years ago
|
while True:
|
||
|
ret, img = camera.read()
|
||
|
if not ret:
|
||
|
break;
|
||
12 years ago
|
|
||
12 years ago
|
name = pattern % (nframes,)
|
||
|
_, tail = os.path.split(name)
|
||
12 years ago
|
|
||
12 years ago
|
boxes = samples[tail]
|
||
|
boxes = sft.norm_acpect_ratio(boxes, 0.5)
|
||
12 years ago
|
|
||
12 years ago
|
nannotated = nannotated + len(boxes)
|
||
|
nframes = nframes + 1
|
||
|
rects, confs = cascade.detect(img, rois = None)
|
||
12 years ago
|
|
||
12 years ago
|
if confs is None:
|
||
|
continue
|
||
12 years ago
|
|
||
12 years ago
|
dts = sft.convert2detections(rects, confs)
|
||
12 years ago
|
|
||
12 years ago
|
confs = confs.tolist()[0]
|
||
|
confs.sort(lambda x, y : -1 if (x - y) > 0 else 1)
|
||
|
confidenses = confidenses + confs
|
||
12 years ago
|
|
||
12 years ago
|
matched = sft.match(boxes, dts)
|
||
|
tp = tp + matched
|
||
12 years ago
|
|
||
12 years ago
|
print nframes, nannotated
|
||
12 years ago
|
|
||
12 years ago
|
fppi, miss_rate = sft.computeROC(confidenses, tp, nannotated, nframes)
|
||
|
sft.plotLogLog(fppi, miss_rate, plot_colors[idx])
|
||
12 years ago
|
|
||
12 years ago
|
sft.showPlot("roc_curve.png")
|