前言
#案例来源Fu Xianjun. All Rights Reserved,对银行卡字符识别
一、原图
二、识别
import cv2
import numpy as np
def sort_contours(cnts, method = "left-to-right"):
reverse = False
i = 0
if method == "left-to-right" 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))
return cnts,boundingBoxes
def cv_show(name,img):
cv2.imshow(name,img)
cv2.waitKey(0)
cv2.destroyAllWindows()
template = cv2.imread("ocr_a_reference.png")
# cv_show("template