from PIL import Image
x_start = 11 # 起始点坐标
y_start = 92
fill_width= 24 信息点宽度
fill_height= 10 # 信息点高度
space_width = 15 间隔宽度
space_height = 12 # 间隔高度
ans_cnt = 5 # 题目个数
def bw_judge(R, G, B): # bw_judge用于判断一个像素的填涂情况
Gray_scale = 0.299 * R + 0.587 * G + 0.114 * B
return Gray_scale < 132
def fill_judge(x, y): # fill_judge 用于判断信息点的填涂情况
count = 0
for i in range(x, x + fill_width):
for j in range( ):
R, G, B = pixels[i, j]
if bw_judge(R, G, B) == True:
count = count + 1
if count >= fill_width * fill_height * 0.64:
return True
total_width = fill_width + space_width
total_height = fill_height + space_height
image = Image.open ("card.bmp")
pixels = image.load()
ans = ""
item=[‘A’,’B’,’C’,’D’]
list=[]
for col in range(ans_cnt):
x =
for row in range(4):
y = y_start + total_height * row
if fill_judge(x, y) == True:
list.append(ans)
ans=""
print(list)