© Fu Xianjun. All Rights Reserved.
提示:以下是本篇文章正文内容,下面案例可供参考
一、答题卡识别
二、使用步骤
检测轮廓
代码如下(示例):
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):
rect = np.zeros((4, 2), dtype = "float32")
s = pts.sum(axis = 1)
rect[0] = pts[np.argmin(s)]
rect[2] = pts[np.argmax</