|
141 | 141 | thresh = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, sqKernel)
|
142 | 142 |
|
143 | 143 | # find contours in the thresholded image, then initialize the
|
144 |
| -# list of digit locations |
| 144 | +# list of digit locations找到轮廓并初始化数字分组位置列表。 |
145 | 145 | cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
|
146 | 146 | cv2.CHAIN_APPROX_SIMPLE)
|
147 | 147 | cnts = cnts[0] if imutils.is_cv2() else cnts[1]
|
|
156 | 156 |
|
157 | 157 | # since credit cards used a fixed size fonts with 4 groups
|
158 | 158 | # of 4 digits, we can prune potential contours based on the
|
159 |
| - # aspect ratio |
| 159 | + # aspect ratio根据每个轮廓的宽高比进行过滤 |
160 | 160 | if ar > 2.5 and ar < 4.0:
|
161 | 161 | # 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 |
163 | 163 | if (w > 40 and w < 55) and (h > 10 and h < 20):
|
164 | 164 | # append the bounding box region of the digits group
|
165 | 165 | # to our locations list
|
|
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, |
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] |
190 | 192 | # digitCnts = contours.sort_contours(digitCnts,method="left-to-right")[0]
|
191 | 193 |
|
192 | 194 | # loop over the digit contours
|
|
0 commit comments