open CV项目实战(一)——信用卡数字识别

参考教程:唐宇迪老师: https://www.bilibili.com/video/BV1tb4y1C7j7

1.参数配置:

在这里插入图片描述
step1:
在这里插入图片描述
step2:找到Edit Configurations…
在这里插入图片描述
step3:找到Parameters一栏
在这里插入图片描述
step4:编辑图片、模板的路径(不要有中文,不要有空格)
在这里插入图片描述

2.程序代码:

myutils模块部分:

import cv2

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
    #左上角横坐标的大小
    #cv2.boundingRect(c)返回四个值,x,y,h,w
    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)) #reverse = True 降序 , reverse = False 升序(默认),b[1][0]按x坐标排序

    return cnts, boundingBoxes
def resize(image, width=None, height=None, inter=cv2.INTER_AREA): #cv2.INTER_AREA 基于局部像素的重采样
    dim = None
    (h, w) = image.shape[:2]
    if width is None and height is None:
        return image
    if width is None:
        r = height / float(h)
        dim = (int(w * r), height)
    else:
        r = width / float(w)
        dim = (width, int(h * r))
    resized = cv2.resize(image, dim, interpolation=inter)  #resize函数的参数dsize的形状是(w,h)
    return resized

工作程序部分:

# 导入工具包
from imutils import contours
import numpy as np
import argparse
import cv2
import myutils

# 设置参数
ap = argparse.ArgumentParser()  #argparse 模块可以让人轻松编写用户友好的命令行接口
ap.add_argument("-i", "--image", required=True,
	help="path to input image")
ap.add_argument("-t", "--template", required=True,
	help="path to template OCR-A image")
args = vars
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值