"1111011" : 9,
"1111111" : 8,
"1000011" : 7,
+ #"1010011" : 7,
"1111101" : 6,
"1111001" : 5,
"0101011" : 4,
"1110110" : 2,
"0000011" : 1,
"1011111" : 0
+
}
w = r[2] - r[0]
h = r[3] - r[1]
- if (w < 0.3 * h):
+ if (w < 0.4 * h):
return 1
- top = GoodFraction(pix,(r[0], r[1], r[0]+w, r[1]+0.15*h)) # Top
- mid = GoodFraction(pix,(r[0], r[1]+0.45*h, r[0]+w, r[1]+0.55*h)) # Middle
- bot = GoodFraction(pix,(r[0], r[1]+0.9*h, r[0]+w, r[1]+h)) # Bottom
- ltop = GoodFraction(pix,(r[0], r[1], r[0]+0.4*w, r[1]+0.5*h)) # Left Top
- lbot = GoodFraction(pix,(r[0], r[1]+0.5*h, r[0]+0.4*w, r[1]+h)) #Left Bottom
- rtop = GoodFraction(pix,(r[0]+0.6*w, r[1],r[0]+w, r[1]+0.5*h)) # Right Top
- rbot = GoodFraction(pix,(r[0]+0.6*w, r[1]+0.5*h, r[0]+w, r[1]+h)) # Right Bottom
+ top = GoodFraction(pix,(r[0]+0.0*w, r[1], r[0]+1.0*w, r[1]+0.15*h)) # Top
+ mid = GoodFraction(pix,(r[0]+0.0*w, r[1]+0.45*h, r[0]+1.0*w, r[1]+0.55*h)) # Middle
+ bot = GoodFraction(pix,(r[0]+0.0*w, r[1]+0.9*h, r[0]+1.0*w, r[1]+h)) # Bottom
+ ltop = GoodFraction(pix,(r[0], r[1]+0.1*h, r[0]+0.4*w, r[1]+0.4*h)) # Left Top
+ lbot = GoodFraction(pix,(r[0], r[1]+0.6*h, r[0]+0.4*w, r[1]+0.9*h)) #Left Bottom
+ rtop = GoodFraction(pix,(r[0]+0.6*w, r[1]+0.1*h,r[0]+w, r[1]+0.4*h)) # Right Top
+ rbot = GoodFraction(pix,(r[0]+0.6*w, r[1]+0.6*h, r[0]+w, r[1]+0.9*h)) # Right Bottom
filled = ""
- fraction = 0.42
+ fraction = 0.4
for f in [top,mid,bot,ltop,lbot,rtop,rbot]:
if f > fraction:
filled += "1"
#Check where the boxes are
"""
- img = Image.new("RGB", (r[2]-r[0], r[3]-r[1]), "white")
- draw = ImageDraw.Draw(img)
- for x in range(r[0], r[2]):
- for y in range(r[1], r[3]):
- draw.rectangle((x-r[0], y-r[1], x-r[0], y-r[1]), fill=pix[x, y], outline=None)
-
- boxes = []
- boxes.append((0, 0, w, 0.15*h)) # Top
- boxes.append((0, 0.45*h, w, 0.55*h)) # Middle
- boxes.append((0, 0.9*h, w, h)) # Bottom
- boxes.append((0, 0, 0.4*w, 0.5*h)) # Left Top
- boxes.append((0, 0.5*h, 0.4*w, h)) # Left Bottom
- boxes.append((0.6*w, 0, w, 0.5*h)) # Right Top
- boxes.append((0.6*w, 0.5*h, w, h)) # Right Bottom
- for box in boxes:
- draw.rectangle(box, fill=None, outline="blue")
- img.show()
-
-
- print("I think this is a " + str(d[filled]))
+ if (filled in d) == False:
+ img = Image.new("RGB", (r[2]-r[0], r[3]-r[1]), "white")
+ draw = ImageDraw.Draw(img)
+ for x in range(r[0], r[2]):
+ for y in range(r[1], r[3]):
+ draw.rectangle((x-r[0], y-r[1], x-r[0], y-r[1]), fill=pix[x, y], outline=None)
+
+ boxes = []
+ boxes.append((0, 0, w, 0.15*h)) # Top
+ boxes.append((0, 0.45*h, w, 0.55*h)) # Middle
+ boxes.append((0, 0.9*h, w, h)) # Bottom
+ boxes.append((0, 0, 0.4*w, 0.5*h)) # Left Top
+ boxes.append((0, 0.5*h, 0.4*w, h)) # Left Bottom
+ boxes.append((0.6*w, 0, w, 0.5*h)) # Right Top
+ boxes.append((0.6*w, 0.5*h, w, h)) # Right Bottom
+ for box in boxes:
+ 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 = []
#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):
#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)