X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=research%2FTCS%2Fpressure%2Fprocess_digits.py;h=1b2c9dde974ade44865a31240f020a2a5f6a5abe;hb=8616b26b4c97640f230ad45597e72b216a041b4b;hp=d58bcb979a7dca825a604d08bb032a1cb3299aaa;hpb=184b02dc5f607e25887f8c0d96316dc0e1124994;p=matches%2Fhonours.git diff --git a/research/TCS/pressure/process_digits.py b/research/TCS/pressure/process_digits.py index d58bcb97..1b2c9dde 100755 --- a/research/TCS/pressure/process_digits.py +++ b/research/TCS/pressure/process_digits.py @@ -84,6 +84,7 @@ def PickDigit(pix, r): "1110110" : 2, "0000011" : 1, "1011111" : 0 + } w = r[2] - r[0] @@ -114,6 +115,7 @@ def PickDigit(pix, r): #Check where the boxes are + """ if (filled in d) == False: img = Image.new("RGB", (r[2]-r[0], r[3]-r[1]), "white") draw = ImageDraw.Draw(img) @@ -133,9 +135,12 @@ def PickDigit(pix, r): draw.rectangle(box, fill=None, outline="blue") img.show() #return 0 + """ - - return d[filled] + if filled in d: + return d[filled] + else: + return None def Process(fileName): results = [] @@ -160,7 +165,11 @@ def Process(fileName): #test.show() for r in rect: - results.append(PickDigit(pix, r)) + digit = PickDigit(pix, r) + if digit != None: + results.append(digit) + else: + return None return results def PixToList(pix, bounds): @@ -187,9 +196,16 @@ if __name__ == "__main__": #sys.exit(0) r = Process(sys.argv[1]) - print(str(r[0]) + "." + str(r[1]) + str(r[2]) + "e-" + str(r[3])) - - + if r == None: + print("?") + sys.exit(1) + + if (len(r) == 4): + print(str(r[0]) + "." + str(r[1]) + str(r[2]) + "e-" + str(r[3])) + elif (len(r) == 3): + print(str(r[0]) + "." + str(r[1]) + "e-" + str(r[2])) + else: + print("#?") sys.exit(0)