|
55 | 55 | ref = cv2.cvtColor(ref, cv2.COLOR_BGR2GRAY)
|
56 | 56 | ref = cv2.threshold(ref, 10, 255, cv2.THRESH_BINARY_INV)[1]
|
57 | 57 |
|
58 |
| -cv2.imshow('ref',ref) |
| 58 | +cv2.imshow('ref', ref) |
59 | 59 | cv2.waitKey(0)
|
60 | 60 |
|
61 | 61 | '''
|
|
88 | 88 | print('digits:',digits.keys())
|
89 | 89 | '''
|
90 | 90 |
|
91 |
| -#try1 |
| 91 | +# try1 |
92 | 92 | digits = {}
|
93 |
| -rows,cols=ref.shape |
94 |
| -per=int(cols/10) |
| 93 | +rows, cols = ref.shape |
| 94 | +per = int(cols / 10) |
95 | 95 | for x in range(10):
|
96 |
| - roi = ref[:, x*per:(x+1)*per] |
| 96 | + roi = ref[:, x * per:(x + 1) * per] |
97 | 97 | roi = cv2.resize(roi, (57, 88))
|
98 | 98 | cv2.imshow('roi', roi)
|
99 | 99 | cv2.waitKey(500)
|
100 | 100 |
|
101 | 101 | # update the digits dictionary, mapping the digit name to the ROI
|
102 | 102 | digits[x] = roi
|
103 | 103 | # 从参考图像中提取数字,并将其与相应的数字名称相关联
|
104 |
| -print('digits:',digits.keys()) |
| 104 | +print('digits:', digits.keys()) |
105 | 105 |
|
106 | 106 | # 初始化一对结构化的内核:
|
107 |
| -#您可以将内核看作是一个小矩阵,我们在图像上滑动以进行(卷积)操作,例如模糊,锐化,边缘检测或其他图像处理操作。 |
| 107 | +# 您可以将内核看作是一个小矩阵,我们在图像上滑动以进行(卷积)操作,例如模糊,锐化,边缘检测或其他图像处理操作。 |
108 | 108 | # initialize a rectangular (wider than it is tall) and square
|
109 | 109 | # structuring kernel
|
110 | 110 | rectKernel = cv2.getStructuringElement(cv2.MORPH_RECT, (9, 3))
|
|
184 | 184 |
|
185 | 185 | # detect the contours of each individual digit in the group,
|
186 | 186 | # then sort the digit contours from left to right
|
187 |
| - digitCnts = cv2.findContours(group.copy(), cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE) |
188 |
| - cv2.imshow('digitCnts',digitCnts[0]) |
| 187 | + digitCnts = cv2.findContours(group.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) |
| 188 | + cv2.imshow('digitCnts', digitCnts[0]) |
189 | 189 | cv2.waitKey(1000)
|
190 | 190 | # digitCnts = digitCnts[0] if imutils.is_cv2() else digitCnts[1]
|
191 |
| - digitCnts =digitCnts[1] |
| 191 | + digitCnts = digitCnts[1] |
192 | 192 | # digitCnts = contours.sort_contours(digitCnts,method="left-to-right")[0]
|
193 | 193 |
|
194 | 194 | # loop over the digit contours
|
|
224 | 224 | output.extend(groupOutput)
|
225 | 225 |
|
226 | 226 | # display the output credit card information to the screen
|
227 |
| -print("Credit Card Type: {}".format(FIRST_NUMBER.get(output[0],'None'))) |
| 227 | +print("Credit Card Type: {}".format(FIRST_NUMBER.get(output[0], 'None'))) |
228 | 228 | print("Credit Card #: {}".format("".join(output)))
|
229 |
| -cv2.imshow("Image", image) |
| 229 | +cv2.imshow("Image", image) # TODO 效果不是很好,需要改进 |
230 | 230 | cv2.waitKey(0)
|
0 commit comments