From 4622aea86ad845307ba88dd8232893fcb7c56708 Mon Sep 17 00:00:00 2001 From: "marina.kolpakova" Date: Thu, 17 Jan 2013 20:36:39 +0400 Subject: [PATCH] ROC test: add overlap calculation according to Pascal criteria --- apps/sft/misk/roc_test.py | 7 ++----- apps/sft/misk/sft.py | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/apps/sft/misk/roc_test.py b/apps/sft/misk/roc_test.py index 0355ca3a7f..7aae82efc8 100755 --- a/apps/sft/misk/roc_test.py +++ b/apps/sft/misk/roc_test.py @@ -54,13 +54,10 @@ if __name__ == "__main__": sft.draw_rects(img, boxes, (255, 0, 0), lambda x, y : y) frame = frame + 1 - - # sample = samples[] - - - rects, confs = cascade.detect(img, rois = None) + fp = sft.match(boxes, rects, confs) + # # draw results if rects is not None: sft.draw_rects(img, rects[0], (0, 255, 0)) diff --git a/apps/sft/misk/sft.py b/apps/sft/misk/sft.py index 6a6e2fea77..3e9ee88150 100644 --- a/apps/sft/misk/sft.py +++ b/apps/sft/misk/sft.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import cv2, re, glob +import numpy as np def draw_rects(img, rects, color, l = lambda x, y : x + y): if rects is not None: @@ -12,6 +13,24 @@ class Sample: self.image = img self.bbs = bb +class Detection: + def __init__(self, bb, conf): + self.bb = bb + self.conf = conf + + # we use rect-stype for dt and box style for gt. ToDo: fix it + def overlap(self, b): + a = self.bb + print "HERE:", a, b + w = min( a[0] + a[2], b[0] + b[2]) - max(a[0], b[0]); + h = min( a[1] + a[3], b[1] + b[3]) - max(a[1], b[1]); + + cross_area = 0.0 if (w < 0 or h < 0) else float(w * h) + union_area = (a[2] * a[3]) + ((b[2] - b[0]) * (b[3] - b[1])) - cross_area; + + return cross_area / union_area; + + def parse_inria(ipath, f): bbs = [] path = None @@ -39,4 +58,17 @@ def parse_idl(f): l = re.sub(r"\:", ":[", l) l = re.sub(r"(\;|\.)$", "]}", l) map.update(eval(l)) - return map \ No newline at end of file + return map + +def match(gts, rects, confs): + if rects is None: + return 0 + + dts = zip(*[rects.tolist(), confs.tolist()]) + dts = zip(dts[0][0], dts[0][1]) + dts = [Detection(r,c) for r, c in dts] + + for dt in dts: + for gt in gts: + overlap = dt.overlap(gt) + print overlap \ No newline at end of file