| 282 | self.pixels = pixels |
| 283 | |
| 284 | def split_captcha_letters(self): |
| 285 | captcha = self.img |
| 286 | started = False |
| 287 | letters = [] |
| 288 | width, height = captcha.size |
| 289 | bottomY, topY = 0, height |
| 290 | pixels = captcha.load() |
| 291 | |
| 292 | for x in range(width): |
| 293 | black_pixel_in_col = False |
| 294 | for y in range(height): |
| 295 | if pixels[x, y] != 255: |
| 296 | if not started: |
| 297 | started = True |
| 298 | firstX = x |
| 299 | lastX = x |
| 300 | |
| 301 | if y > bottomY: |
| 302 | bottomY = y |
| 303 | if y < topY: |
| 304 | topY = y |
| 305 | if x > lastX: |
| 306 | lastX = x |
| 307 | |
| 308 | black_pixel_in_col = True |
| 309 | |
| 310 | if black_pixel_in_col is False and started is True: |
| 311 | rect = (firstX, topY, lastX, bottomY) |
| 312 | new_captcha = captcha.crop(rect) |
| 313 | |
| 314 | w, h = new_captcha.size |
| 315 | if w > 5 and h > 5: |
| 316 | letters.append(new_captcha) |
| 317 | |
| 318 | started = False |
| 319 | bottomY, topY = 0, height |
| 320 | |
| 321 | return letters |
| 322 | |
| 323 | def correct(self, values, var=None): |
| 324 | if var: |