X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=tools%2Fgpubounds.py;fp=tools%2Fgpubounds.py;h=d054bcc2860c41615771b2099edbec9326d3c8cb;hp=0000000000000000000000000000000000000000;hb=9bdc5bae5786db07e19a43136a126ae8723eb191;hpb=5d9bd33375efe24796ed442077385f67d9661520 diff --git a/tools/gpubounds.py b/tools/gpubounds.py new file mode 100755 index 0000000..d054bcc --- /dev/null +++ b/tools/gpubounds.py @@ -0,0 +1,54 @@ +#!/usr/bin/python +import sys +import os +import math + +# Calculates the total error in coordinates of GPU bounds rectangles of objects + +def ComputeError(reference, other): + if type(reference) == str: + reference = open(reference, "r") + if type(other) == str: + other = open(other, "r") + + total = 0.0 + while True: + a = reference.readline() + b = other.readline() + if a == "" and b == "": + reference.close() + other.close() + return total + if a[0] == '#' and b[0] == '#': + continue + a = map(float, a.strip(" \r\n").split("\t")) + b = map(float, b.strip(" \r\n").split("\t")) + deltaArea = abs(b[3]*b[4] - a[3]*a[4]) + + deltaCoord = b[1] - a[1] + b[2] - a[2] + total += math.sqrt(deltaArea) + abs(deltaCoord) + +# Counts the number of unique bounds +def UniqueBounds(other): + other = open(other, "r") + store = {} + for l in other.readlines(): + if l[0] == "#": + continue + #print "L is " + str(l) + l = map(float, l.strip(" \r\n").split("\t")) + l = tuple(l[1:]) + if not l in store.keys(): + store[l] = 1 + else: + store[l] += 1 + other.close() + return len(store.keys()) + +def main(argv): + print str(ComputeError(argv[1], argv[2])) + "\t" + str(UniqueBounds(argv[1])) + "\t" + str(UniqueBounds(argv[2])) + return 0 + + +if __name__ == "__main__": + sys.exit(main(sys.argv))