一个选项是否被填涂,可以从判断一个像素的颜色开始,像素的填涂情况是通过RGB的值来判断 ,灰度值低于132的表示该点被填涂;一个信息点64%的像素被填涂,则认为该区域已填涂,返回值为“1”。区域未填涂时返回值为“0”;各选项的编码为:A→“1000”,B→“0100”,C→“0010”,D→“0001”;输入标准答案,程序进行对比并返回结果。答题卡相关信息如下:
from PIL import Image
#输入起始点坐标(xs,ys),信息点宽度高度(fw, fh),间隔宽度高度(sw, sh),代码略
num = 5 # 判分个数
def bw_judge(R, G, B): # bw_judge用于判断一个像素的填涂情况,代码略
def fill_judge(x, y): # fill_judge用于判断信息点的填涂情况
count = 0
for i in range(x, x + fw + 1):
for j in range(y, y + fh + 1):
R, G, B = pixels[i, j]
if bw_judge(R, G, B) = = True:
count = count + 1
return
total_width = fw+ sw
total_height = fh + sh
image = Image.open("t2.bmp")
pixels = image.load()
number = ""
bz=[""]*num
df=0
bzd=input('请输入标准答案:')
da={"A":"1000","B":"0100","C":"0010","D":"0001"}
for i in range(len(bzd)):
bz[i]=
for row in range(num): #分数判定
for col in range(4):
y = ys + total_height * row
if fill_judge(x, y) == True :
number = number + '1'
else:
number = number + '0'
if number = = bz[row]:
df+=2
number=""
print("得分为:",df)