OpenCv 入门
OpenCv 入门 -- 如何识别信用卡上的数字 @ Fu Xianjun. All Rights Reserved.\
前言
一、对数字的识别
1、导入库
处理图片,获得每个图片的模板
import cv2
import numpy as np
def sort_contours(cnts,method = "left-to-right"):
reverse = False
i = 0
if method == "right-to-left" or method == "bottom-to-top":
reverse = True
if method == "top-to-bottom" or method == "bottom-to-top":
i = 1
boundingBoxes = [cv2.boundingRect(cnt) for cnt in cnts]
(cnts,boundingBoxes) = zip(*sorted(zip(cnts,boundingBoxes),\
key=lambda b: b[1][i],\
reverse=reverse))
2、读入数据
def cv_show(name,img):#显示图片
cv2.imshow(name,img)
cv2.waitKey()
cv2.destroyAllWindows()
template = cv2.imread("ocr_a_reference.png")#读取图片
#cv_show("template",template)#显示图片
template_gray = cv2.cvtColor(template,cv2.COLOR_BGR2GRAY)#转换为灰度图
#cv_show("template_gray",template_gray)
ret