日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python信用卡识别_python opencv实现信用卡的数字识别

發布時間:2024/9/19 python 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python信用卡识别_python opencv实现信用卡的数字识别 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本項目利用python以及opencv實現信用卡的數字識別

前期準備

導入工具包

定義功能函數

模板圖像處理

讀取模板圖像 cv2.imread(img)

灰度化處理 cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

二值化 cv2.threshold()

輪廓 - 輪廓

信用卡圖像處理

讀取信用卡圖像 cv2.imread(img)

灰度化處理 cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

禮帽處理 cv2.morphologyEx(gray,cv2.MORPH_TOPHAT,rectKernel)

Sobel邊緣檢測 cv2.Sobel(tophat, ddepth=cv2.CV_32F, dx=1, dy=0, ksize=-1)

閉操作 cv2.morphologyEx(gradX, cv2.MORPH_CLOSE, rectKernel)

計算輪廓 cv2.findContours

模板檢測 cv2.matchTemplate(roi, digitROI,cv2.TM_CCOEFF)

原始數據展示

結果展示

1 前期準備

# 導入工具包

# opencv讀取圖片的格式為b g r

# matplotlib圖片的格式為 r g b

import numpy as np

import cv2

from imutils import contours

import matplotlib.pyplot as plt

%matplotlib inline

# 信用卡的位置

predict_card = "images/credit_card_01.png"

# 模板的位置

template = "images/ocr_a_reference.png"

# 指定信用卡類型

FIRST_NUMBER = {

"3": "American Express",

"4": "Visa",

"5": "MasterCard",

"6": "Discover Card"

}

# 定義一些功能函數

# 對框進行排序

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

# 調整圖片尺寸大小

def resize(image, width=None, height=None, inter=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)

return resized

# 定義cv2展示函數

def cv_show(name,img):

cv2.imshow(name,img)

cv2.waitKey(0)

cv2.destroyAllWindows()

2 對模板圖像進行預處理操作

讀取模板圖像

# 讀取模板圖像

img = cv2.imread(template)

cv_show("img",img)

plt.imshow(img)

總結

以上是生活随笔為你收集整理的python信用卡识别_python opencv实现信用卡的数字识别的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。