OpenCV+Python识别机读卡

devtools/2024/11/9 14:59:10/

背景介绍

正常机读卡是通过读卡机读取识别结果的,目前OpenCV已经这么强大了,尝试着用OpenCV+Python来识别机读卡。要识别的机读卡长这样:

我们做以下操作:

1.识别答题卡中每题选中项结果。

不做以下操作:

1.不识别101-106题(这些题实际情况下经常用不到,如果要识别原理也一样)

实现思路

通过分析答题卡特征:

1.答题区域为整张图片最大轮廓,先找出答题区域。

2.答题区域分为6行,每行4组,第6行只有1组,我们暂不处理第6行,只处理前面5行。

3.给定每一行第一个选项中心点坐标,该行其余选项的中心点坐标可以推算出来。

4.通过找到每个选项中心点坐标,再加上选项宽高,就可以在答题区域绘出每个选项的范围。

5.通过计算每个选项范围图像里非0像素点个数:

   单选题非0像素点最少的既是答案。

   多选题结合阈值判断该选项是否选中。

6.输出完整答案。

实现步骤

1.图像预处理

将图片转灰度图、黑帽运算:移除干扰项、二值化突出轮廓、查找轮廓、找出答题区域。

python">import cv2
import numpy as np# 1.读取图片并缩放
orginImg = cv2.imread("1.jpg")
size = ((int)(650*1.8), (int)(930*1.8))  # 尽可能将图片弄大一点,下面好处理
img = cv2.resize(orginImg, size)#显示图像
def imshow(name,image):scale_percent = 50  # 缩放比例width = int(image.shape[1] * scale_percent / 100)height = int(image.shape[0] * scale_percent / 100)dim = (width, height)resized_image = cv2.resize(image, dim, interpolation=cv2.INTER_AREA)cv2.imshow(name, resized_image)imshow("1.orgin", img)# 2.转灰度图
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
imshow("2.gray", gray)# 3.黑帽运算:移除干扰项
cvblackhat = cv2.morphologyEx(gray, cv2.MORPH_BLACKHAT, cv2.getStructuringElement(cv2.MORPH_RECT, (15, 15)))
imshow("3.black", cvblackhat)# 4.二值化突出轮廓,自动阈值范围 cv2.THRESH_BINARY|cv2.THRESH_OTSU
thresh = cv2.threshold(cvblackhat, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
imshow("4.thresh", thresh)# 5.提取轮廓,并在图上标记轮廓
cnts, hierarchy = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
mark = img.copy()
cv2.drawContours(mark, cnts, -1, (0, 0, 255), 2)
imshow("5.contours", mark)# 6.提取我们感兴趣的部分(这里我们只需要答题部分) img[y:y+h, x:x+w]
roi = None
for (i, c) in enumerate(cnts):(x, y, w, h) = cv2.boundingRect(c)ar = w/float(h)if w > 500 and h > 500 and ar > 0.9 and ar < 1.1:roi = img[y:y+h, x:x+w]break
imshow("5.roi", roi)

运行结果

2.查找每个选项的中心点坐标

这里每行起始点坐标和每个选项宽高,都是写的固定值(手动量出来的,本来想通过图像提取轮廓来取每个选项中心坐标点的,可是由于机读卡填图不规范,可能会影响轮廓提取,不是很靠谱,暂时没想到更好的办法)

python">
# 7.查找每个选项的中心点坐标
# 思路:
# 通过分析:
# 1.答题区域分为6行,每行4组,第6行只有1组,我们暂不处理第6行,只处理前面5行。
# 2.只要给定每一行第一个选项中心坐标,该行其余选项的中心坐标可以推算出来。
# 3.通过找到每个选项中心点坐标,再加上选项宽高,就可以在答题区域绘出每个选项的范围。
# 4.通过计算每个选项范围图像里非0像素点个数,结合阈值判断该选项是否选中。
# 5.结合题目个数,遍历每个选项,构造出最终答案。
item = [34, 20]  # 每个选项宽度(跟图形缩放有关系)
x_step = 44  # x方向行距(两个选项水平方向距离)
y_step = 28  # y方向行距(两个选项垂直方向距离)
blank = 92  # 每组间距(5个一组)水平方向距离
centers = []  # 每个选项的中心点坐标,用来框选选项
# 答题区域有5行多1组,这里只处理前面5行,最后一组暂不处理
startPonits = [(25, 44), (25, 216), (26, 392), (26, 566), (28, 744)]
for (i, p) in enumerate(startPonits):temp = []  # 暂存该组选项坐标start = list(p)  # 该行起始点坐标for g in range(0, 4, 1):  # 每行有4组if len(temp) > 0:startx = temp[len(temp)-1][0] + blank  # 最后一个选项的x坐标+每组间距else:startx = start[0]start[0] = startxfor i in range(start[0], start[0]+5*x_step, x_step):  # 水平5个选项for j in range(start[1], start[1]+4*y_step, y_step):  # 垂直4个选项temp.append((i, j))for (i, c) in enumerate(temp):centers.append(c)# 8.将选项绘制到答题区域
show = roi.copy()
for (i, (x, y)) in enumerate(centers):left = x-(int)(item[0]/2)top = y-(int)(item[1]/2)# 绘选项区域矩形cv2.rectangle(show, (left, top), (left +item[0], top + item[1]), (0, 0, 255), -1)# 绘制序号标签cv2.putText(show, str(i+1), (left, top+10),cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 0, 0), 2)
imshow("5.show", show)

运行结果

3.遍历每个选项,计算非0像素点个数

python"># 9.截取每个答题选项,并计算非0像素点个数
map = roi.copy()
map = cv2.cvtColor(map, cv2.COLOR_BGR2GRAY)
map = cv2.threshold(map, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
points = []
for (i, (x, y)) in enumerate(centers):left = x-(int)(item[0]/2)top = y-(int)(item[1]/2)# 截取每个选项小图item_img = map[top:top+item[1], left:left+item[0]]count = cv2.countNonZero(item_img)points.append(count)cv2.imwrite("item/"+str(i+1)+"-"+str(count)+".jpg", item_img)

这里为了方便观看,将每个选项截取另存为成图像了,以索“引号+非0像素点个数”命名。实际过程中可以不另存为图像。

大概像这样:

4.整理答案

python"># 10.整理答案
answer = []  # 二维数组:保存每个题ABCD4个选项值
group = []  # 将点分组,每4个1组,对应每题的4个选项
for i in range(0, len(points), 1):if len(group) > 0 and group.count(points[i]) > 0:group.append(points[i]+1)else:group.append(points[i])if (i+1) % 4 == 0:answer.append(group)group = []def printItem(i, optoins):question = {0: "A", 1: "B", 2: "C", 3: "D"}index = 0if i < 80:# 单选题(非0像素点最少的既是答案)an = min(optoins)index = optoins.index(an)print("第"+str(i+1)+"题"+question.get(index))else:# 多选题(根据阈值来判断是否选中)ans = ""for (j, p) in enumerate(options):if p < 400:index = optoins.index(p)ans += question.get(index)print("第"+str(i+1)+"题"+ans)# 打印题目答案
for (i, options) in enumerate(answer):printItem(i, options)

输出结果:

完整代码

python">import cv2
import numpy as np# 1.读取图片并缩放
orginImg = cv2.imread("1.jpg")
size = ((int)(650*1.8), (int)(930*1.8))  # 尽可能将图片弄大一点,下面好处理
img = cv2.resize(orginImg, size)# 显示图像
def imshow(name, image):scale_percent = 50  # 缩放比例width = int(image.shape[1] * scale_percent / 100)height = int(image.shape[0] * scale_percent / 100)dim = (width, height)resized_image = cv2.resize(image, dim, interpolation=cv2.INTER_AREA)cv2.imshow(name, resized_image)imshow("1.orgin", img)# 2.转灰度图
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
imshow("2.gray", gray)# 3.黑帽运算:移除干扰项
cvblackhat = cv2.morphologyEx(gray, cv2.MORPH_BLACKHAT, cv2.getStructuringElement(cv2.MORPH_RECT, (15, 15)))
imshow("3.black", cvblackhat)# 4.二值化突出轮廓,自动阈值范围 cv2.THRESH_BINARY|cv2.THRESH_OTSU
thresh = cv2.threshold(cvblackhat, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
imshow("4.thresh", thresh)# 5.提取轮廓,并在图上标记轮廓
cnts, hierarchy = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
mark = img.copy()
cv2.drawContours(mark, cnts, -1, (0, 0, 255), 2)
imshow("5.contours", mark)# 6.提取我们感兴趣的部分(这里我们只需要答题部分) img[y:y+h, x:x+w]
roi = None
for (i, c) in enumerate(cnts):(x, y, w, h) = cv2.boundingRect(c)ar = w/float(h)if w > 500 and h > 500 and ar > 0.9 and ar < 1.1:roi = img[y:y+h, x:x+w]break
imshow("5.roi", roi)# 7.查找每个选项的中心点坐标
# 思路:
# 通过分析:
# 1.答题区域分为6行,每行4组,第6行只有1组,我们暂不处理第6行,只处理前面5行。
# 2.只要给定每一行第一个选项中心坐标,该行其余选项的中心坐标可以推算出来。
# 3.通过找到每个选项中心点坐标,再加上选项宽高,就可以在答题区域绘出每个选项的范围。
# 4.通过计算每个选项范围图像里非0像素点个数,结合阈值判断该选项是否选中。
# 5.结合题目个数,遍历每个选项,构造出最终答案。
item = [34, 20]  # 每个选项宽度(跟图形缩放有关系)
x_step = 44  # x方向行距(两个选项水平方向距离)
y_step = 28  # y方向行距(两个选项垂直方向距离)
blank = 92  # 每组间距(5个一组)水平方向距离
centers = []  # 每个选项的中心点坐标,用来框选选项
# 答题区域有5行多1组,这里只处理前面5行,最后一组暂不处理
startPonits = [(25, 44), (25, 216), (26, 392), (26, 566), (28, 744)]
for (i, p) in enumerate(startPonits):temp = []  # 暂存该组选项坐标start = list(p)  # 该行起始点坐标for g in range(0, 4, 1):  # 每行有4组if len(temp) > 0:startx = temp[len(temp)-1][0] + blank  # 最后一个选项的x坐标+每组间距else:startx = start[0]start[0] = startxfor i in range(start[0], start[0]+5*x_step, x_step):  # 水平5个选项for j in range(start[1], start[1]+4*y_step, y_step):  # 垂直4个选项temp.append((i, j))for (i, c) in enumerate(temp):centers.append(c)# 8.将选项绘制到答题区域
show = roi.copy()
for (i, (x, y)) in enumerate(centers):left = x-(int)(item[0]/2)top = y-(int)(item[1]/2)# 绘选项区域矩形cv2.rectangle(show, (left, top), (left +item[0], top + item[1]), (0, 0, 255), -1)# 绘制序号标签cv2.putText(show, str(i+1), (left, top+10),cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 0, 0), 2)
cv2.imshow("5.show", show)# 9.截取每个答题选项,并计算非0像素点个数
map = roi.copy()
map = cv2.cvtColor(map, cv2.COLOR_BGR2GRAY)
map = cv2.threshold(map, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
points = []
for (i, (x, y)) in enumerate(centers):left = x-(int)(item[0]/2)top = y-(int)(item[1]/2)# 截取每个选项小图item_img = map[top:top+item[1], left:left+item[0]]count = cv2.countNonZero(item_img)points.append(count)cv2.imwrite("item/"+str(i+1)+"-"+str(count)+".jpg", item_img)# 10.整理答案
answer = []  # 二维数组:保存每个题ABCD4个选项值
group = []  # 将点分组,每4个1组,对应每题的4个选项
for i in range(0, len(points), 1):if len(group) > 0 and group.count(points[i]) > 0:group.append(points[i]+1)else:group.append(points[i])if (i+1) % 4 == 0:answer.append(group)group = []def printItem(i, optoins):question = {0: "A", 1: "B", 2: "C", 3: "D"}index = 0if i < 80:# 单选题(非0像素点最少的既是答案)an = min(optoins)index = optoins.index(an)print("第"+str(i+1)+"题"+question.get(index))else:# 多选题(根据阈值来判断是否选中)ans = ""for (j, p) in enumerate(options):if p < 400:index = optoins.index(p)ans += question.get(index)print("第"+str(i+1)+"题"+ans)# 打印题目答案
for (i, options) in enumerate(answer):printItem(i, options)cv2.waitKey(0)
cv2.destroyAllWindows()

2024-8-26 补充:识别准考证区域

在轮廓检测时,将准考证区域也选出来。然后用同样的方法,将准考证号每个选项标记出来,根据非0像素点来识别。

完整代码(包含与标准答案比对出成绩)

python">import cv2# 1.读取图片并缩放
orginImg = cv2.imread("111.jpg")
size = ((int)(650*1.8), (int)(930*1.8))  # 尽可能将图片弄大一点,下面好处理
img = cv2.resize(orginImg, size)# 显示图像
def imshow(name, image):scale_percent = 50  # 缩放比例width = int(image.shape[1] * scale_percent / 100)height = int(image.shape[0] * scale_percent / 100)dim = (width, height)resized_image = cv2.resize(image, dim, interpolation=cv2.INTER_AREA)cv2.imshow(name, resized_image)# 图像预处理:灰度化、二值化、提取轮廓、提取答题区域
def prepare(img):# 1.原图imshow("1.orgin", img)# 2.转灰度图gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)imshow("2.gray", gray)# 3.黑帽运算:移除干扰项cvblackhat = cv2.morphologyEx(gray, cv2.MORPH_BLACKHAT, cv2.getStructuringElement(cv2.MORPH_RECT, (15, 15)))imshow("3.black", cvblackhat)# 4.二值化突出轮廓,自动阈值范围 cv2.THRESH_BINARY|cv2.THRESH_OTSUthresh = cv2.threshold(cvblackhat, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]imshow("4.thresh", thresh)# 5.提取轮廓,并在图上标记轮廓cnts, hierarchy = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)mark = img.copy()cv2.drawContours(mark, cnts, -1, (0, 0, 255), 2)imshow("5.contours", mark)return cnts# 提取我们感兴趣的部分(这里我们只需要准考证部分和答题部分) img[y:y+h, x:x+w]
cnts = prepare(img)
answer_area = None  # 答题区域
zkzh_area = None    # 准考证号区域
for (i, c) in enumerate(cnts):(x, y, w, h) = cv2.boundingRect(c)ar = w/float(h)if w > 500 and h > 500 and ar > 0.9 and ar < 1.1:if answer_area is None:answer_area = img[y:y+h, x:x+w]elif w > 200 and h > 100 and ar > 1.2 and ar < 1.4:if zkzh_area is None:zkzh_area = img[y:y+h, x:x+w]if answer_area is not None and zkzh_area is not None:breakimshow("5.answer_area", answer_area)
cv2.imshow("6.zkzh_area", zkzh_area)# 解析准考证号def get_zkzh(zkzh_area):zkzh_item = [34, 20]  # 每个选项宽度(跟图形缩放有关系)zkzh_x_step = 45  # x方向行距(两个选项水平方向距离)zkzh_y_step = 30  # y方向行距(两个选项垂直方向距离)zkzh_centers = []  # 每个选项的中心点坐标,用来框选选项zkzh_start_ponits = (28, 112)for i in range(0, 11, 1):  # 11位准考证号startx = zkzh_start_ponits[0]+i*zkzh_x_stepfor j in range(0, 10, 1):  # 每位准考证号有10位数starty = zkzh_start_ponits[1]+j*zkzh_y_stepzkzh_centers.append((startx, starty))# 将选项绘制到准考证号zkzh_show = zkzh_area.copy()for (i, (x, y)) in enumerate(zkzh_centers):left = x-(int)(zkzh_item[0]/2)top = y-(int)(zkzh_item[1]/2)# 绘选项区域矩形cv2.rectangle(zkzh_show, (left, top), (left +zkzh_item[0], top + zkzh_item[1]), (0, 0, 255), -1)# 绘制序号标签cv2.putText(zkzh_show, str(i+1), (left, top+10),cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 0, 0), 2)cv2.imshow("7.zkzh_show", zkzh_show)# 截取每个准考证号项,并计算非0像素点个数zkzh_map = zkzh_area.copy()zkzh_map = cv2.cvtColor(zkzh_map, cv2.COLOR_BGR2GRAY)zkzh_map = cv2.threshold(zkzh_map, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]zkzh_points = []for (i, (x, y)) in enumerate(zkzh_centers):left = x-(int)(zkzh_item[0]/2)top = y-(int)(zkzh_item[1]/2)# 截取每个选项小图item_img = zkzh_map[top:top+zkzh_item[1], left:left+zkzh_item[0]]count = cv2.countNonZero(item_img)zkzh_points.append(count)# 10.整理准考证号zkzh_nums = []  # 二维数组:保存每个题ABCD4个选项值zkzh_group = []  # 将点分组,每4个1组,对应每题的4个选项for i in range(0, len(zkzh_points), 1):zkzh_group.append(zkzh_points[i])if (i+1) % 10 == 0:zkzh_nums.append(zkzh_group)zkzh_group = []zkzh_num = ""for (i, zkzh_area) in enumerate(zkzh_nums):an = min(zkzh_area)index = zkzh_area.index(an)zkzh_num += str(index)return zkzh_numprint("准考证号:", get_zkzh(zkzh_area))# ============================解析答题区域=================================#
# 7.查找每个选项的中心点坐标
# 思路:
# 通过分析:
# 1.答题区域分为6行,每行4组,第6行只有1组,我们暂不处理第6行,只处理前面5行。
# 2.只要给定每一行第一个选项中心坐标,该行其余选项的中心坐标可以推算出来。
# 3.通过找到每个选项中心点坐标,再加上选项宽高,就可以在答题区域绘出每个选项的范围。
# 4.通过计算每个选项范围图像里非0像素点个数,结合阈值判断该选项是否选中。
# 5.结合题目个数,遍历每个选项,构造出最终答案。
answer_item = [34, 20]  # 每个选项宽度(跟图形缩放有关系)
answer_x_step = 44  # x方向行距(两个选项水平方向距离)
answer_y_step = 28  # y方向行距(两个选项垂直方向距离)
answer_blank = 92  # 每组间距(5个一组)水平方向距离
answer_centers = []  # 每个选项的中心点坐标,用来框选选项
# 答题区域有5行多1组,这里只处理前面5行,最后一组暂不处理
answer_start_ponits = [(25, 44), (25, 216), (26, 392), (26, 566), (28, 744)]
for (i, p) in enumerate(answer_start_ponits):temp = []  # 暂存该组选项坐标start = list(p)  # 该行起始点坐标for g in range(0, 4, 1):  # 每行有4组if len(temp) > 0:startx = temp[len(temp)-1][0] + answer_blank  # 最后一个选项的x坐标+每组间距else:startx = start[0]start[0] = startxfor i in range(start[0], start[0]+5*answer_x_step, answer_x_step):  # 水平5个选项for j in range(start[1], start[1]+4*answer_y_step, answer_y_step):  # 垂直4个选项temp.append((i, j))for (i, c) in enumerate(temp):answer_centers.append(c)# 8.将选项绘制到答题区域
answer_show = answer_area.copy()
for (i, (x, y)) in enumerate(answer_centers):left = x-(int)(answer_item[0]/2)top = y-(int)(answer_item[1]/2)# 绘选项区域矩形cv2.rectangle(answer_show, (left, top), (left +answer_item[0], top + answer_item[1]), (0, 0, 255), -1)# 绘制序号标签cv2.putText(answer_show, str(i+1), (left, top+10),cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 0, 0), 2)
cv2.imshow("7.answer_show", answer_show)# 9.截取每个答题选项,并计算非0像素点个数
answer_map = answer_area.copy()
answer_map = cv2.cvtColor(answer_map, cv2.COLOR_BGR2GRAY)
answer_map = cv2.threshold(answer_map, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
answer_points = []
for (i, (x, y)) in enumerate(answer_centers):left = x-(int)(answer_item[0]/2)top = y-(int)(answer_item[1]/2)# 截取每个选项小图item_img = answer_map[top:top+answer_item[1], left:left+answer_item[0]]count = cv2.countNonZero(item_img)answer_points.append(count)# cv2.imwrite("item/"+str(i+1)+"-"+str(count)+".jpg", item_img)# 9.截取每个答题选项,并计算非0像素点个数
answer_map = answer_area.copy()
answer_map = cv2.cvtColor(answer_map, cv2.COLOR_BGR2GRAY)
answer_map = cv2.threshold(answer_map, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
answer_points = []
for (i, (x, y)) in enumerate(answer_centers):left = x-(int)(answer_item[0]/2)top = y-(int)(answer_item[1]/2)# 截取每个选项小图item_img = answer_map[top:top+answer_item[1], left:left+answer_item[0]]count = cv2.countNonZero(item_img)answer_points.append(count)# 10.整理答案
answer = []  # 二维数组:保存每个题ABCD4个选项值
group = []  # 将点分组,每4个1组,对应每题的4个选项
for i in range(0, len(answer_points), 1):if len(group) > 0 and group.count(answer_points[i]) > 0:group.append(answer_points[i]+1)else:group.append(answer_points[i])if (i+1) % 4 == 0:answer.append(group)group = []# 最终结果
score_dic = {}def printItem(i, optoins):question = {0: "A", 1: "B", 2: "C", 3: "D"}index = 0if i < 80:# 单选题(非0像素点最少的既是答案)an = min(optoins)index = optoins.index(an)score_dic[i+1] = question.get(index)# print("第"+str(i+1)+"题"+question.get(index))else:# 多选题(根据阈值来判断是否选中)ans = ""for (j, p) in enumerate(options):if p < 400:index = optoins.index(p)ans += question.get(index)score_dic[i+1] = ans# print("第"+str(i+1)+"题"+ans)# 打印题目答案
for (i, options) in enumerate(answer):printItem(i, options)print("填涂结果:")
print(score_dic)# 与标准答案比较,得到最终得分
score = 0
answers = {1: "B", 2: "B", 3: "A", 4: "B", 5: "B", 6: "A", 7: "B", 8: "B", 9: "A", 10: "B", 11: "B", 12: "A", 13: "A", 14: "B", 15: "B", 16: "A", 17: "A", 18: "B", 19: "B", 20: "A", 21: "C", 22: "C", 23: "B", 24: "D", 25: "C", 26: "D", 27: "A", 28: "D", 29: "C", 30: "B", 31: "C", 32: "D", 33: "B", 34: "A", 35: "D", 36: "C", 37: "B", 38: "B", 39: "D", 40: "D", 41: "B", 42: "C", 43: "B", 44: "D", 45: "B", 46: "A", 47: "D", 48: "D", 49: "C", 50: "D", 51: "B", 52: "D", 53: "A", 54: "A", 55: "D", 56: "D", 57: "C", 58: "D", 59: "B", 60: "D", 61: "A", 62: "B", 63: "D", 64: "B", 65: "C", 66: "D", 67: "B", 68: "C", 69: "D", 70: "A", 71: "ABCD", 72: "ABCD", 73: "AC", 74: "BCD", 75: "BC", 76: "BD", 77: "ABCD", 78: "ABCD", 79: "ACD", 80: "ABD"}
print("标准答案:")
print(answers)
for (i, a) in enumerate(score_dic):s = 0  # 每题得分if i > 0 and i < 20:s = 1.25  # 1-20题每题1.25分elif i > 20 and i < 70:s = 1     # 21-70题每题1分elif i > 70 and i < 80:s = 2.5   # 71-80题每题2.5分if answers.get(i+1) == score_dic.get(i+1):score += sprint("最终成绩:")
print(score)cv2.waitKey(0)
cv2.destroyAllWindows()

运行效果


http://www.ppmy.cn/devtools/102462.html

相关文章

电脑丢失dll文件一键修复之dll确实损坏影响电脑运行

在使用电脑过程中&#xff0c;DLL文件丢失或损坏是一个常见的问题&#xff0c;它可能导致程序无法正常运行&#xff0c;甚至影响整个系统的稳定性。本文将详细介绍如何一键修复丢失的DLL文件&#xff0c;探讨常见的DLL丢失报错原因&#xff0c;并提供详细的修复步骤和预防措施。…

编程学习之路上的挫折:如何在Bug迷宫中找到出口

在编程学习的道路上&#xff0c;每个程序员都会经历挫折。那些无法调试的错误、复杂的算法题、永远跑不通的代码&#xff0c;都像一道道难以逾越的高墙&#xff0c;阻挡着我们的前进。面对这些挫折&#xff0c;很多人感到迷茫、沮丧&#xff0c;甚至产生了放弃的念头。然而&…

WPF判断窗口是否已经关闭

在WPF中&#xff0c;可以使用Window类的IsVisible属性来判断窗口是否关闭。当窗口关闭时&#xff0c;IsVisible属性的值将为false。以下是一个示例&#xff1a; private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) {// 判断窗口是否关闭if…

OpenCV(第二关--读取图片和摄像头)实例+代码

以下内容&#xff0c;皆为原创&#xff0c;制作不易&#xff0c;感谢大家的关注和点赞。 一.读取图片 我们来读取图片&#xff0c;当你用代码读取后&#xff0c;可能会发现。怎么跟上传的图片颜色有些许的不一样。因为OpenCV的颜色通道是BGR&#xff0c;而我们平常用的matplotl…

海山数据库(He3DB)+AI(二)大模型架构Transformer

文章目录 0 引言1 总体框架2 输入编码2.1 分词2.2 词嵌入2.3 位置编码 3 模型3.1 自注意力机制3.2 Encoder3.3 Decoder3.4 Encoder-Decoder架构 0 引言 2022年被称为大模型元年&#xff0c;ChatGPT4的横空出世引起了国内外的研究热潮&#xff0c;而GPT4正是基于Transformer这一…

续:MySQL的gtid模式

为什么要启用gtid? master端和slave端有延迟 ##设置gtid master slave1 slave2 [rootmysql1 ~]# vim /etc/my.cnf [rootmysql1 ~]# cat /etc/my.cnf [mysqld] datadir/data/mysql socket/data/mysql/mysql.sock symbolic-links0 log-binmysql-bin server-id1 slow_query_lo…

免费分享:2021-2100中国多情景逐年干燥度模拟数据(附下载方法)

AI是表征一个地区干湿程度的指标&#xff0c;一般来说&#xff0c;根据AI分类可以概括地把区域分为湿润&#xff08;AI<1&#xff0c;相当于森林&#xff09;、半湿润&#xff08;AI在1-1.5&#xff0c;相当于森林草原&#xff09;、半干旱&#xff08;AI在1.5-4&#xff0c…

线性代数:如何由AB=E 推出 BA=AB?

最近在二刷线性代数&#xff0c;在看逆矩阵定义的时候发现了这个问题。于是决定写一写&#xff0c;给出一种证明方式。 一、由逆矩阵的定义出发 这是我在mooc-山东大学-线性代数&#xff08;秦静老师&#xff09;第一章第十讲的ppt上截取的定义。 看到这个定义我就在想&#xf…