数字图像处理(图像分割--简单识别银行卡号)

不断学习中......

读取自己拍摄的银行卡号,并显示出来

通过高斯模糊以及设置阈值将图像二值化

import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt


def image_process(file_path):
    img = cv.imread(file_path, 0)
    blur = cv.GaussianBlur(img, (9, 9), 0)     #高斯模糊

#设定阈值60到255,将图像二值化
    ret, binary = cv.threshold(blur, 60, 255, cv.THRESH_BINARY)       

    kernel = np.ones((2, 50), np.uint8)
    erosion = cv.erode(binary, kernel)         
    dilation = cv.dilate(erosion, kernel)      

    contours, hierarchy = cv.findContours(dilation, cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
    sp = dilation.shape
    for i in range(0, len(contours)):
        x, y, w, h = cv.boundingRect(contours[i])
        if h > sp[0]*0.05 and w > sp[1]*0.5 and y > sp[0]*0.2 and y < sp[0]*0.8 and w/h > 5:
            img = binary[y:y + h, x:x + w]
            cv.imshow("haoma", img)
            break

读取图像并且输出卡号:


src = cv.imread("./hm2.png")
cv.namedWindow("input image", cv.WINDOW_AUTOSIZE)
cv.imshow("input iamge",src)
image=cv.imread("./yhk.png")
image_process("./yhk1.png")
cv.waitKey(0)

cv.destroyAllWindows()

效果图如下:

上面的一个图为识别过后的图,下面的为参考图,在拍摄银行卡的时候,可能因为拍摄出来太模糊而识别不出,可以多拍摄几张。 

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值