© Fu Xianjun. All Rights Reserved
重点:
模板匹配、轮廓检测、阈值处理、边缘检测
原图:

1.导包:
import cv2
import numpy as np
def cv_show(name, img):
cv2.imshow(name, img)
cv2.waitKey(0)
cv2.destroyAllWindows()
2.框选图像中的数字部分
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(c) for c in cnts] #用一个最小的矩形,把找到的形状包起来x,y,h,w
(cnts, boundingBoxes) = zip(*sorted(zip(cnts, boundingBoxes),
key=lambda b: b[1][i], reverse=reverse))
return cnts, boundingBoxes
# 读取模板图片
template = cv2.imread('ocr_a_reference.png')
cv_show('template', template)
# 模板图片灰度化。这里的模板图片本身就是二值化的因此没有明显区别。
template_gray = cv2.cvtColor(template, cv2.COLOR_BGR2GRAY)
cv_show('templage_gray', template_gray)
# 二值化,转化

本文介绍了使用OpenCV进行数字图像处理,实现信用卡数字识别的过程。通过模板匹配、轮廓检测、阈值处理和边缘检测等技术,逐步筛选并识别出信用卡上的数字,最终成功划分并识别出卡号。
最低0.47元/天 解锁文章

941

被折叠的 条评论
为什么被折叠?



