当前位置:   article > 正文

OpenCV图像处理技术(Python)——答题卡识别_python矩形答题卡

python矩形答题卡

OpenCV图像处理技术(Python)——答题卡识别
© Fu Xianjun. All Rights Reserved.


前言

家人们好,我又又又来讲解知识了。


学习目标

1.能够灵活运用平滑处理、边缘检测、轮廓检测、透视变换、坐标点处理
2.能够学会轮廓对比方法,并得到统计分析结果
3.能够综合应用数字图像处理知识解决实际问题

学习内容

1.预处理、轮廓检测

import cv2
import numpy as np
# 正确答案
ANSWER_KEY = {
   0: 1, 1: 4, 2: 0, 3: 3, 4: 1}
def cv_show(name,img):
        cv2.imshow(name, img)
        cv2.waitKey(0)
        cv2.destroyAllWindows()  
# 读取输入
image = cv2.imread("test_01.png")
contours_img = image.copy()
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
cv_show('blurred',blurred)
edged = cv2.Canny(blurred, 75, 200)
cv_show('edged',edged)
# 轮廓检测
cnts = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL,\
                        cv2.CHAIN_APPROX_SIMPLE)[0]
cv2.drawContours(contours_img,cnts,-1,(0,0,255),3) 
cv_show('contours_img',contours_img)

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

2.轮廓排序,透视变换

def order_points(pts):
    # 一共4个坐标点
    rect = np.zeros((4, 2), dtype = "float32")

    # 按顺序找到对应坐标0123分别是 左上,右上,右下,左下
    # 计算左上,右下
    s = pts.sum(axis = 1)
    rect[0] = pts[np
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/768267
推荐阅读
相关标签
  

闽ICP备14008679号