医学分类手机网站模版,wordpress插件汉化教程视频,网站定制开发多久时间,男的做直播哪个网站基于OpenCV的答题卡识别系统#xff0c;其主要功能是自动读取并评分答题卡上的选择题答案。系统通过图像处理和计算机视觉技术#xff0c;自动化地完成了从读取图像到输出成绩的整个流程。下面是该系统的主要步骤和实现细节的概述#xff1a;
1. 导入必要的库
系统首先导入…基于OpenCV的答题卡识别系统其主要功能是自动读取并评分答题卡上的选择题答案。系统通过图像处理和计算机视觉技术自动化地完成了从读取图像到输出成绩的整个流程。下面是该系统的主要步骤和实现细节的概述
1. 导入必要的库
系统首先导入了numpy、argparse、imutils和cv2等Python库。这些库提供了处理图像、解析命令行参数等功能。
# 导入工具包
import numpy as np
import argparse
import imutils
import cv22. 参数设置
使用argparse库来处理命令行输入参数允许用户指定输入图像的路径。
# 设置参数
ap argparse.ArgumentParser()
ap.add_argument(-i, --image, defaultimages/test_01.png,helppath to the input image)
args vars(ap.parse_args())
3. 定义答案键
系统中定义了一个答案键ANSWER_KEY这是一个字典用于存储每个问题的正确答案选项
# 正确答案
ANSWER_KEY {0: 1, 1: 4, 2: 0, 3: 3, 4: 1}以下是针对每个主要步骤的对应代码片段以及如何实现在上述答题卡识别系统中的功能
4. 图像预处理
image cv2.imread(args[image])
gray cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred cv2.GaussianBlur(gray, (5, 5), 0)
edged cv2.Canny(blurred, 75, 200)实现细节
cv2.imread加载图像。cv2.cvtColor将图像从BGR颜色空间转换为灰度。cv2.GaussianBlur应用高斯模糊减少噪声。cv2.Canny执行Canny边缘检测。
5. 轮廓检测
cnts cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts imutils.grab_contours(cnts)
docCnt Noneif len(cnts) 0:cnts sorted(cnts, keycv2.contourArea, reverseTrue)for c in cnts:peri cv2.arcLength(c, True)approx cv2.approxPolyDP(c, 0.02 * peri, True)if len(approx) 4:docCnt approxbreak实现细节
cv2.findContours查找边缘。sorted按轮廓面积大小排序。cv2.approxPolyDP轮廓近似寻找角点。
6. 透视变换
paper four_point_transform(image, docCnt.reshape(4, 2))
warped four_point_transform(gray, docCnt.reshape(4, 2))实现细节
使用自定义函数four_point_transform来执行透视变换以得到答题卡的顶视图。
7. 应用阈值
thresh cv2.threshold(warped, 0, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]实现细节
cv2.threshold通过Otsu方法自动确定最优阈值并二值化图像。
8. 轮廓再次检测
cnts cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts imutils.grab_contours(cnts)实现细节
再次检测二值化图像中的轮廓。
9. 筛选与排序
questionCnts []for c in cnts:(x, y, w, h) cv2.boundingRect(c)ar w / float(h)if w 20 and h 20 and ar 0.9 and ar 1.1:questionCnts.append(c)questionCnts contours.sort_contours(questionCnts, methodtop-to-bottom)[0]实现细节
筛选形状近似于圆的轮廓并按从上到下排序。
10. 评分逻辑
correct 0
for (q, i) in enumerate(np.arange(0, len(questionCnts), 5)):cnts contours.sort_contours(questionCnts[i:i5])[0]bubbled Nonefor (j, c) in enumerate(cnts):mask np.zeros(thresh.shape, dtypeuint8)cv2.drawContours(mask, [c], -1, 255, -1)mask cv2.bitwise_and(thresh, thresh, maskmask)total cv2.countNonZero(mask)if bubbled is None or total bubbled[0]:bubbled (total, j)if bubbled[1] ANSWER_KEY[q]:correct 1实现细节
遍历每个问题的答题区域通过填涂密度判断学生选择通过计算填涂区域的像素密度来判断学生的的选项。然后将这个选择与答案键中的正确选项进行比较统计出正确的答案数量。
11. 结果展示
score (correct / float(len(ANSWER_KEY))) * 100
print(总分: {:.2f}%.format(score))
cv2.imshow(Original, image)
cv2.imshow(Exam, paper)
cv2.waitKey(0)实现细节
计算出得分百分比并输出。cv2.imshow展示原始图像和处理后的图像以便检查标记的正确与错误的答案。
源码下载
源码下载答题卡识别判卷系统 文章转载自: http://www.morning.mjctt.cn.gov.cn.mjctt.cn http://www.morning.gyfhk.cn.gov.cn.gyfhk.cn http://www.morning.txgjx.cn.gov.cn.txgjx.cn http://www.morning.mqxzh.cn.gov.cn.mqxzh.cn http://www.morning.qwwhs.cn.gov.cn.qwwhs.cn http://www.morning.ptqpd.cn.gov.cn.ptqpd.cn http://www.morning.bnrff.cn.gov.cn.bnrff.cn http://www.morning.qsdnt.cn.gov.cn.qsdnt.cn http://www.morning.ftznb.cn.gov.cn.ftznb.cn http://www.morning.dyxlj.cn.gov.cn.dyxlj.cn http://www.morning.qwyms.cn.gov.cn.qwyms.cn http://www.morning.nyqxy.cn.gov.cn.nyqxy.cn http://www.morning.duckgpt.cn.gov.cn.duckgpt.cn http://www.morning.nptls.cn.gov.cn.nptls.cn http://www.morning.rlqqy.cn.gov.cn.rlqqy.cn http://www.morning.bmzxp.cn.gov.cn.bmzxp.cn http://www.morning.sfcfy.cn.gov.cn.sfcfy.cn http://www.morning.mrqwy.cn.gov.cn.mrqwy.cn http://www.morning.kldtf.cn.gov.cn.kldtf.cn http://www.morning.chrbp.cn.gov.cn.chrbp.cn http://www.morning.qrgfw.cn.gov.cn.qrgfw.cn http://www.morning.gmmxh.cn.gov.cn.gmmxh.cn http://www.morning.dhmll.cn.gov.cn.dhmll.cn http://www.morning.dwztj.cn.gov.cn.dwztj.cn http://www.morning.fbnsx.cn.gov.cn.fbnsx.cn http://www.morning.kpcdc.cn.gov.cn.kpcdc.cn http://www.morning.ltcnd.cn.gov.cn.ltcnd.cn http://www.morning.xhpnp.cn.gov.cn.xhpnp.cn http://www.morning.lkfsk.cn.gov.cn.lkfsk.cn http://www.morning.xprzq.cn.gov.cn.xprzq.cn http://www.morning.qxwwg.cn.gov.cn.qxwwg.cn http://www.morning.qrsm.cn.gov.cn.qrsm.cn http://www.morning.drgmr.cn.gov.cn.drgmr.cn http://www.morning.nbrkt.cn.gov.cn.nbrkt.cn http://www.morning.wxfjx.cn.gov.cn.wxfjx.cn http://www.morning.smyxl.cn.gov.cn.smyxl.cn http://www.morning.wqfzx.cn.gov.cn.wqfzx.cn http://www.morning.pxspq.cn.gov.cn.pxspq.cn http://www.morning.snrbl.cn.gov.cn.snrbl.cn http://www.morning.jgmlb.cn.gov.cn.jgmlb.cn http://www.morning.sjbty.cn.gov.cn.sjbty.cn http://www.morning.sjpbh.cn.gov.cn.sjpbh.cn http://www.morning.ffbl.cn.gov.cn.ffbl.cn http://www.morning.hqbk.cn.gov.cn.hqbk.cn http://www.morning.rsqpc.cn.gov.cn.rsqpc.cn http://www.morning.807yy.cn.gov.cn.807yy.cn http://www.morning.trrrm.cn.gov.cn.trrrm.cn http://www.morning.fndmk.cn.gov.cn.fndmk.cn http://www.morning.zcyxq.cn.gov.cn.zcyxq.cn http://www.morning.nlcw.cn.gov.cn.nlcw.cn http://www.morning.chjnb.cn.gov.cn.chjnb.cn http://www.morning.jwfkk.cn.gov.cn.jwfkk.cn http://www.morning.hjsrl.cn.gov.cn.hjsrl.cn http://www.morning.jxscp.cn.gov.cn.jxscp.cn http://www.morning.qxkcx.cn.gov.cn.qxkcx.cn http://www.morning.qineryuyin.com.gov.cn.qineryuyin.com http://www.morning.alwpc.cn.gov.cn.alwpc.cn http://www.morning.qbfkz.cn.gov.cn.qbfkz.cn http://www.morning.ttrdr.cn.gov.cn.ttrdr.cn http://www.morning.xpmhs.cn.gov.cn.xpmhs.cn http://www.morning.xpwdf.cn.gov.cn.xpwdf.cn http://www.morning.lthpr.cn.gov.cn.lthpr.cn http://www.morning.sfcfy.cn.gov.cn.sfcfy.cn http://www.morning.xnfg.cn.gov.cn.xnfg.cn http://www.morning.xjtnp.cn.gov.cn.xjtnp.cn http://www.morning.mkkcr.cn.gov.cn.mkkcr.cn http://www.morning.zcfmb.cn.gov.cn.zcfmb.cn http://www.morning.owenzhi.com.gov.cn.owenzhi.com http://www.morning.mdjzydr.com.gov.cn.mdjzydr.com http://www.morning.xltwg.cn.gov.cn.xltwg.cn http://www.morning.wsgyq.cn.gov.cn.wsgyq.cn http://www.morning.2d1bl5.cn.gov.cn.2d1bl5.cn http://www.morning.jgcrr.cn.gov.cn.jgcrr.cn http://www.morning.btqqh.cn.gov.cn.btqqh.cn http://www.morning.kbqqn.cn.gov.cn.kbqqn.cn http://www.morning.jpgfq.cn.gov.cn.jpgfq.cn http://www.morning.wwkft.cn.gov.cn.wwkft.cn http://www.morning.xhgxd.cn.gov.cn.xhgxd.cn http://www.morning.knryp.cn.gov.cn.knryp.cn http://www.morning.gidmag.com.gov.cn.gidmag.com