Skip to content

Commit 44148c8

Browse files
committed
final
1 parent 6dcec4b commit 44148c8

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
http://www.pyimagesearch.com/2017/07/17/credit-card-ocr-with-opencv-and-python/
22

33

4+
5+
当比较数字时,模板匹配也是一种非常快速的方法。
6+
7+
不幸的是,我们无法将OCR图像应用于真实的信用卡图像,所以如果这种方法在实际的真实世界图像上是可靠的,那么肯定会提出这个问题。鉴于照明条件,视角和其他一般噪声的变化,我们可能需要采取更多以**机器学习**为导向的方法。
8+
9+
无论如何,至少对于这些示例图像,我们能够成功应用模板匹配作为OCR的一种形式。
10+
11+
12+

my01-OCR文字识别/使用-模板匹配-识别信用卡号码/matchTemplate_credit_card_num1.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
thresh = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, sqKernel)
142142

143143
# find contours in the thresholded image, then initialize the
144-
# list of digit locations
144+
# list of digit locations找到轮廓并初始化数字分组位置列表。
145145
cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
146146
cv2.CHAIN_APPROX_SIMPLE)
147147
cnts = cnts[0] if imutils.is_cv2() else cnts[1]
@@ -156,10 +156,10 @@
156156

157157
# since credit cards used a fixed size fonts with 4 groups
158158
# of 4 digits, we can prune potential contours based on the
159-
# aspect ratio
159+
# aspect ratio根据每个轮廓的宽高比进行过滤
160160
if ar > 2.5 and ar < 4.0:
161161
# contours can further be pruned on minimum/maximum width
162-
# and height
162+
# and height使用纵横比,我们分析每个轮廓的形状。如果 ar 在2.5到4.0之间(比它高),以及 40到55个像素之间的 w以及 10到20像素之间的h,我们将一个方便的元组的边界矩形参数附加到 locs
163163
if (w > 40 and w < 55) and (h > 10 and h < 20):
164164
# append the bounding box region of the digits group
165165
# to our locations list
@@ -184,9 +184,11 @@
184184

185185
# detect the contours of each individual digit in the group,
186186
# then sort the digit contours from left to right
187-
digitCnts = cv2.findContours(group.copy(), cv2.RETR_EXTERNAL,
188-
cv2.CHAIN_APPROX_SIMPLE)
189-
digitCnts = digitCnts[0] if imutils.is_cv2() else digitCnts[1]
187+
digitCnts = cv2.findContours(group.copy(), cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
188+
cv2.imshow('digitCnts',digitCnts[0])
189+
cv2.waitKey(1000)
190+
# digitCnts = digitCnts[0] if imutils.is_cv2() else digitCnts[1]
191+
digitCnts =digitCnts[1]
190192
# digitCnts = contours.sort_contours(digitCnts,method="left-to-right")[0]
191193

192194
# loop over the digit contours

0 commit comments

Comments
 (0)