open CV——识别银行卡号

本文介绍了通过open CV进行银行卡号识别的过程,包括定义识别模板、导入图片、检测数字区域、分割并匹配模板,最后绘制识别结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


前言

© Fu Xianjun. All Rights Reserved.
随着人工智能的不断发展,open CV这门技术也越来越重要,很多人都开启了学习open CV,本文介绍了利用open CV识别银行卡的数字。


一、识别的逻辑是什么

  • 对模板操作
  • 导入图片
  • 检测出银行卡数字区域
  • 分割数字区域
  • 利用模板经行匹配
  • 绘制数字

二、使用步骤

1.定义函数识别模板

代码如下:

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=="right-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("muban.png")#读模板
# cv_show("template",template)
template_gray= cv2.cvtColor(template,cv2.COLOR_BGR2GRAY)
#色彩空间转换,变为灰度图
# cv_show("template_gray",template_gray)
ret,template_binary= cv2.threshold(template_gray,127,255,1)
#二值化
cv_show("template_binary",template_binary)

cnts,he= cv2.findContours(template_binary,cv2.RETR_EXTERNAL,\
                         cv2.CHAIN_APPROX_SIMPLE)
# 查找轮廓
template_rect= cv2.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值