OPENCV图片数字识别

这个非常麻烦,麻烦到我真的不想做

但是我也没有办法的呢

好了开始这个图片数字识别

  • 例如把下面的信用卡上的数字识别出来
    在这里插入图片描述

  • 因为这次的代码分段比较多,所以把重复操作的过程打包成函数提前运行了

import cv2
import numpy as np
def cv_show(name,img):
    cv2.imshow(name,img)
    cv2.waitKey()
    cv2.destroyAllWindows()
    
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]
    (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_gary = cv2.cvtColor(template,cv2.COLOR_BGR2GRAY)
ret,template_binary = cv2.threshold(template_gary,0,255,1)
cv_show("template_binary",template_binary)

在这里插入图片描述

  • 使用上面的函数把图片框选出来之后一个一个切分出来,并进行排序赋值
cnts,h = cv2.findContours(template_binary
  • 3
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值