赞
踩
OpenCV图像处理技术(Python)——答题卡识别
© Fu Xianjun. All Rights Reserved.
家人们好,我又又又来讲解知识了。
1.能够灵活运用平滑处理、边缘检测、轮廓检测、透视变换、坐标点处理
2.能够学会轮廓对比方法,并得到统计分析结果
3.能够综合应用数字图像处理知识解决实际问题
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)
def order_points(pts):
# 一共4个坐标点
rect = np.zeros((4, 2), dtype = "float32")
# 按顺序找到对应坐标0123分别是 左上,右上,右下,左下
# 计算左上,右下
s = pts.sum(axis = 1)
rect[0] = pts[np
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。