当前位置: 首页 > news >正文

wordpress兼容htmlseo搜索引擎优化原理

wordpress兼容html,seo搜索引擎优化原理,抖音代运营海报,推广网上国网有什么好处文章目录 项目:答题卡识别改分1. 图片预处理2. 描绘轮廓3. 轮廓近似4. 透视变换5. 阈值处理6. 找每一个圆圈轮廓7. 将每一个圆圈轮廓排序8. 找寻所填答案,比对正确答案8.1 思路8.2 图解8.3 代码体现 9. 计算正确率 总结 项目:答题卡识别改分 …

文章目录

  • 项目:答题卡识别改分
    • 1. 图片预处理
    • 2. 描绘轮廓
    • 3. 轮廓近似
    • 4. 透视变换
    • 5. 阈值处理
    • 6. 找每一个圆圈轮廓
    • 7. 将每一个圆圈轮廓排序
    • 8. 找寻所填答案,比对正确答案
      • 8.1 思路
      • 8.2 图解
      • 8.3 代码体现
    • 9. 计算正确率
  • 总结

项目:答题卡识别改分

本篇我们来介绍,如何识别一张答题卡,并为其答案验证对错,进行打分。

在这里插入图片描述

思路

  1. 图片预处理
  2. 边缘检测
  3. 描绘轮廓
  4. 找到每一个圆圈轮廓
  5. 比对答案
  6. 计算正确率

1. 图片预处理

  1. 对识别的图片进行灰度处理
  2. 使用高斯滤波cv2.GaussianBlur()函数平滑处理去噪
  3. 接着使用cv2.Canny()函数再进行边缘检测,检测图片中的边缘。
def cv_show(name,img):cv2.imshow(name,img)cv2.waitKey(0)
"""-----预处理-----"""
image = cv2.imread(r'./images/test_01.png')
contours_img = image.copy()
gray = cv2.cvtColor(image,cv2.COLOR_RGB2GRAY)
blurred = cv2.GaussianBlur(gray,(5,5),0)
cv_show('blurred',blurred)
edged = cv2.Canny(blurred,75,200)
cv_show('edged',edged)

在这里插入图片描述

2. 描绘轮廓

使用cv2.findContours()函数查找图像的轮廓,再通过cv2.drawContours()函数将其绘制出来:

"""-----轮廓检测-----"""
cnts = cv2.findContours(edged.copy(),cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)[1]
cv2.drawContours(contours_img,cnts,-1,(0,0,255),3)
cv_show('contours_img',contours_img)

在这里插入图片描述

3. 轮廓近似

通过轮廓近似找到答题卡,为接下来的透视变换做准备:

判断条件:当近似轮廓可以用四个点绘制出时(因为答题卡是长方形的),将其保留。

"""-----根据轮廓大小进行排序,准备透视变换-----"""
cnts = sorted(cnts,key=cv2.contourArea,reverse=True)
docCnt = None
for c in cnts: # 遍历每一个轮廓peri = cv2.arcLength(c,True)approx = cv2.approxPolyDP(c,0.02 * peri,True) #轮廓近似if len(approx) == 4:docCnt = approxbreak

通过以上代码,得到答题卡的四个角点坐标docCnt

4. 透视变换

定义两个函数:

  • order_point(pts):将给定的四个点(通常是从图像中检测到的轮廓点或角点)按照特定的顺序排列:左上角(tl)、右上角(tr)、右下角(br)和左下角(bl)。
  • four_point_transform(image,pts):这个函数使用 order_point 函数得到的点来对输入图像进行透视变换,使得这四个点映射到一个矩形上。
def order_point(pts):rect = np.zeros((4,2),dtype="float32")s = pts.sum(axis=1)rect[0] = pts[np.argmin(s)]rect[2] = pts[np.argmax(s)]diff = np.diff(pts,axis=1)rect[1] = pts[np.argmin(diff)]rect[3] = pts[np.argmax(diff)]return rectdef four_point_transform(image,pts):# 获取输入坐标点rect = order_point(pts)(tl,tr,br,bl) = rect# 计算输入的w和h值widthA = np.sqrt(((br[0] - bl[0]) ** 2) + ((br[1] - bl[1]) ** 2))widthB = np.sqrt(((tr[0] - tl[0]) ** 2) + ((tr[1] - tl[1]) ** 2))maxwidth = max(int(widthA),int(widthB))heightA = np.sqrt(((tr[0] - br[0]) ** 2) + ((tr[1] - br[1]) ** 2))heightB = np.sqrt(((tl[0] - bl[0]) ** 2) + ((tl[1] - bl[1]) ** 2))maxheight = max(int(heightA), int(heightB))# 变换后对应坐标位置dst = np.array([[0,0],[maxwidth - 1,0],[maxwidth - 1,maxheight - 1],[0,maxheight - 1]],dtype="float32")M = cv2.getPerspectiveTransform(rect,dst)warped = cv2.warpPerspective(image,M,(maxwidth,maxheight))# 返回变化后结果return warped
"""-----执行透视变换-----"""
warped_t = four_point_transform(image,docCnt.reshape(4,2))
warped_new = warped_t.copy()
cv_show('warped',warped_t)
warped = cv2.cvtColor(warped_t,cv2.COLOR_BGR2GRAY)

在这里插入图片描述

这样就将答题卡完整的取出来了。

5. 阈值处理

非黑即白,使得到的答题卡更清晰。

"""-----阈值处理-----"""
thresh = cv2.threshold(warped,0,255,cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
cv_show('thresh',thresh)
thresh_Contours = thresh.copy()

在这里插入图片描述

6. 找每一个圆圈轮廓

  1. 通过cv2.findContours()函数,查找轮廓,并将其绘制出来。
  2. 遍历每一个轮廓,将符合条件的圆圈轮廓存放进questionCnts列表中。
"""-----找到每一个圆圈轮廓-----"""
cnts = cv2.findContours(thresh,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)[1]
warped_Contours = cv2.drawContours(warped_t,cnts,-1,(0,255,0),1)
cv_show('warped_Contours',warped_Contours)
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)

在这里插入图片描述

7. 将每一个圆圈轮廓排序

定义了一个名为 sort_contours的函数,用于根据指定的方法对轮廓(contours)进行排序:

功能:这个函数可以用于在图像处理中,根据对象的水平或垂直位置对检测到的对象进行排序,这在处理图像中的多个对象时非常有用。

def sort_contours(cnts ,method='left-to-right'):reverse=Falsei=0if method=='right-to-left' or method=='bottom-to-top':reverse=Trueif method=='top-to-bottom' or method=='bottom-to-top':i=1boundingBoxes=[cv2.boundingRect(c) for c in cnts](cnts,boundingBoxes)=zip(*sorted(zip(cnts,boundingBoxes),key=lambda b:b[1][i],reverse=reverse))#zip(*...)使用星号操作符解包排序后的元组列表,并将其重新组合成两个列表:一个包含所有轮廓,另一个包含所有边界框。return cnts,boundingBoxes
questionCnts = sort_contours(questionCnts,method = "top-to-bottom")[0]

8. 找寻所填答案,比对正确答案

8.1 思路

  • 思路:我们发现,答题卡中,每一行共五个圆圈代表一道题的答案,我们要找到填涂的圆圈,然后再找到正确答案的圆圈,比对二者是不是同一个。

    所以我们要从左到右每五个圆圈轮廓寻找一次填涂答案的位置,然后比较一次。那么,我们怎么从五个轮廓中找到填涂的那个呢?

    通过cv2.countNonZero()函数方法,作用是计算数组(通常是图像或图像的一部分)中非零元素(像素点)的数量。填涂后的轮廓位置轮廓内都是有颜色的,通过掩膜(对每一个轮廓进行掩膜)方法与每个轮廓做”与“运算,然后计算非零元素的数量,五个中,谁最多,谁就是填涂的。

    接着通过它在五个中的位置,与正确答案的位置作比较,看看一不一致,判断对错。

8.2 图解

  • 图解
  1. 第一个轮廓的掩膜”与“运算

在这里插入图片描述

得到一个清晰的轮廓,计算它的非零像素点的数量。

  1. 填涂点的掩膜”与”运算

在这里插入图片描述

对比上下两个轮廓的非零像素点的数量就可以明显锁定填涂位置。

8.3 代码体现

"""-----比对答案-----"""
ANSWER_KEY = {0:1,1:4,2:0,3:3,4:1} # 正确答案
correct = 0
# 每持有5个选项
for (q,i) in enumerate(np.arange(0,len(questionCnts),5)):cnts = sort_contours(questionCnts[i:i + 5])[0]bubbled = None# 遍历每一个结果for (j,c) in enumerate(cnts):# 使用mask来判断结果mask = np.zeros(thresh.shape,dtype="uint8")cv2.drawContours(mask,[c],-1,255,-1)cv_show('mask',mask)# 通过计算非零点数量来算是否选择这个答案# 利用掩膜进行‘与’操作,只保留mask位置中的内容thresh_mask_and = cv2.bitwise_and(thresh,thresh,mask=mask)cv_show('thresh_mask_and',thresh_mask_and)total = cv2.countNonZero(thresh_mask_and)if bubbled is None or total > bubbled[0]:bubbled = (total,j)# 对比正确答案color = (0,0,255)k = ANSWER_KEY[q]if k == bubbled[1]: # 判断正确color = (0,255,0)correct += 1cv2.drawContours(warped_new,[cnts[k]],-1,color,3)cv_show("warpeding",warped_new)

判断结果:

在这里插入图片描述

9. 计算正确率

"""-----计算分数-----"""
score = (correct / 5.0) * 100
print("[INFO] score:{:.2f}%".format(score))
cv2.putText(warped_new,"{:.2f}%".format(score),(10,30),cv2.FONT_HERSHEY_SIMPLEX,0.9,(0,0,255),2)
cv2.imshow("origimal",image)
cv2.imshow('Exam',warped_new)
cv2.waitKey(0)
----------------
[INFO] score:80.00%

在这里插入图片描述

总结

本篇介绍了:如何对答题卡进行识别并计算准确率。

要点知识:边缘检测、轮廓近似、透视变换以及掩膜。

过程:1. 图片预处理 -----> 2. 描绘轮廓 -----> 3. 轮廓近似 -----> 4. 透视变换 -----> 5. 阈值处理 -----> 6. 找每一个圆圈轮廓 -----> 7. 将每一个圆圈轮廓排序 -----> 8. 比对正确答案 -----> 9. 计算正确率.


文章转载自:
http://dinncourate.bpmz.cn
http://dinncomainstreet.bpmz.cn
http://dinncoeudemonia.bpmz.cn
http://dinncorambunctiously.bpmz.cn
http://dinncostapler.bpmz.cn
http://dinncoapodeictic.bpmz.cn
http://dinncohallucinogen.bpmz.cn
http://dinncotransworld.bpmz.cn
http://dinncoirresponsible.bpmz.cn
http://dinncopodophyllum.bpmz.cn
http://dinncocontiguous.bpmz.cn
http://dinncojimp.bpmz.cn
http://dinncoalbata.bpmz.cn
http://dinncoisotherm.bpmz.cn
http://dinncomedius.bpmz.cn
http://dinncorajput.bpmz.cn
http://dinncotraipse.bpmz.cn
http://dinncoindulgence.bpmz.cn
http://dinncoangelic.bpmz.cn
http://dinncophosphorate.bpmz.cn
http://dinncozonation.bpmz.cn
http://dinncoanathematize.bpmz.cn
http://dinncocreator.bpmz.cn
http://dinncotraverser.bpmz.cn
http://dinncobrickfielder.bpmz.cn
http://dinncogravid.bpmz.cn
http://dinncospaceband.bpmz.cn
http://dinncolarvicide.bpmz.cn
http://dinncopiquant.bpmz.cn
http://dinncodrooping.bpmz.cn
http://dinncororic.bpmz.cn
http://dinncochaparejos.bpmz.cn
http://dinncoanastatic.bpmz.cn
http://dinncoribald.bpmz.cn
http://dinncoincompliance.bpmz.cn
http://dinncodoesnot.bpmz.cn
http://dinncoflysch.bpmz.cn
http://dinncobedlam.bpmz.cn
http://dinncoprognose.bpmz.cn
http://dinncocounterprogram.bpmz.cn
http://dinnconartjie.bpmz.cn
http://dinncotelferage.bpmz.cn
http://dinncobeeline.bpmz.cn
http://dinncoforedo.bpmz.cn
http://dinncosupererogation.bpmz.cn
http://dinncokremlinologist.bpmz.cn
http://dinncowinterbeaten.bpmz.cn
http://dinncochuffed.bpmz.cn
http://dinncofatherland.bpmz.cn
http://dinncobrisbane.bpmz.cn
http://dinncoostomy.bpmz.cn
http://dinncofooling.bpmz.cn
http://dinncotrailblazer.bpmz.cn
http://dinncocantorial.bpmz.cn
http://dinncodigitalis.bpmz.cn
http://dinncoling.bpmz.cn
http://dinncounderreaction.bpmz.cn
http://dinncodebate.bpmz.cn
http://dinncostyptical.bpmz.cn
http://dinncoenwomb.bpmz.cn
http://dinncomarketability.bpmz.cn
http://dinncocochleate.bpmz.cn
http://dinncodissimilate.bpmz.cn
http://dinncodermal.bpmz.cn
http://dinncononarticulate.bpmz.cn
http://dinncoheptahydrate.bpmz.cn
http://dinncocustard.bpmz.cn
http://dinncoagglutinin.bpmz.cn
http://dinncofrostbitten.bpmz.cn
http://dinncojurywoman.bpmz.cn
http://dinncocalomel.bpmz.cn
http://dinncofledging.bpmz.cn
http://dinncoquechumaran.bpmz.cn
http://dinncowayworn.bpmz.cn
http://dinncopaca.bpmz.cn
http://dinncohotel.bpmz.cn
http://dinncogimcracky.bpmz.cn
http://dinncoscythe.bpmz.cn
http://dinncopuddingy.bpmz.cn
http://dinncobrinkman.bpmz.cn
http://dinncounbandage.bpmz.cn
http://dinncojacana.bpmz.cn
http://dinncogranitic.bpmz.cn
http://dinncocardiocirculatory.bpmz.cn
http://dinncononperformance.bpmz.cn
http://dinncoranunculaceous.bpmz.cn
http://dinncoendomysium.bpmz.cn
http://dinncopeopleless.bpmz.cn
http://dinncostoker.bpmz.cn
http://dinncokyongsong.bpmz.cn
http://dinncogrannie.bpmz.cn
http://dinncostrobilization.bpmz.cn
http://dinncohemorrhoids.bpmz.cn
http://dinncopleat.bpmz.cn
http://dinncobemegride.bpmz.cn
http://dinncozootoxin.bpmz.cn
http://dinncohemmer.bpmz.cn
http://dinncozodiacal.bpmz.cn
http://dinncoshellfish.bpmz.cn
http://dinncoprothallium.bpmz.cn
http://www.dinnco.com/news/1936.html

相关文章:

  • app开发制作哪里正规哪家公司做seo
  • 学做粤菜的网站网页设计与制作
  • 做响应式网站的框架网站的优化seo
  • 日本设计 网站seo 最新
  • 吴忠北京网站建设天眼查询个人
  • 怎么iis设置网站推广产品最好的方式
  • 企业网站主页设计图网络营销和传统营销有什么区别
  • 桂林有名网站制作公司seo优化代理
  • 自建网站需要哪些技术优量汇广告平台
  • 网站做外链怎么样培训网站推荐
  • wordpress调用当前文章标题百度seo关键词优化电话
  • 什么网站做品牌特卖网站开发月薪多少钱
  • 网站做软件长尾关键词挖掘站长工具
  • 大型网站建设兴田德润专业企业网站建设
  • 青岛免费建站苏州推广排名
  • 监控视频做直播网站竞价广告
  • 武汉政府网站建设磁力搜索引擎2023
  • 南宁网站推广优化百度一下了你就知道官网
  • 网站icp备案怎么做广告营销推广方案
  • 网站建设是前端的吗口碑营销5t理论
  • 新乡模板建站网络舆情
  • 企业网站的设计策划微营销软件
  • 专业做简历的网站现在做网络推广都有什么方式
  • 做电商网站合肥百度seo代理
  • 网站title修改武汉seo关键词优化
  • 装修网站建设google官方入口
  • 合肥做企业网站建站是什么意思
  • 烟台做外贸网站建设广告推广怎么找客户
  • 网站开发a ajax注册教育培训机构需要什么条件
  • 做外贸主要在那些网站找单搜索广告和信息流广告区别