Created
October 6, 2015 11:35
-
-
Save dafeiroc/e1c0a647cbef3f05d78f to your computer and use it in GitHub Desktop.
What does it do here ?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
split_position = [] | |
for i in xrange(1, img.size[0]): | |
if black_pix[i] != 0 and black_pix[i - 1] == 0: | |
if len(split_position) % 2 == 0: | |
split_position.append(i) | |
elif black_pix[i] == 0 and black_pix[i - 1] != 0: | |
if i - 1 - split_position[-1] >= 6: | |
split_position.append(i - 1) | |
if split_position[1] > 17: | |
insert_index(1, 10, 16, black_pix, split_position) | |
if split_position[3] > 27: | |
insert_index(3, 20, 26, black_pix, split_position) | |
if split_position[5] > 37: | |
insert_index(5, 30, 36, black_pix, split_position) | |
if split_position[7] > 47: | |
insert_index(7, 40, 46, black_pix, split_position) | |
if len(split_position) != 8: | |
return "alreadfail" | |
region = img.crop((split_position[0], 0, split_position[1] + 1, img.size[1])) | |
region.save("%s%s%02d.png" % (target_dir, f[0 : -4], 1)) | |
region = img.crop((split_position[2], 0, split_position[3] + 1, img.size[1])) | |
region.save("%s%s%02d.png" % (target_dir, f[0 : -4], 2)) | |
region = img.crop((split_position[4], 0, split_position[5] + 1, img.size[1])) | |
region.save("%s%s%02d.png" % (target_dir, f[0 : -4], 3)) | |
region = img.crop((split_position[6], 0, split_position[7] + 1, img.size[1])) | |
region.save("%s%s%02d.png" % (target_dir, f[0 : -4], 4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
我在代码上加了注释,你可以看一下。我觉得你的验证码似乎更加容易切一点,因为两个字符之间分得很开,而且也没有什么明显的扭曲,你可以直接估算一下每个字符出现和结束的位置,然后切割。也可以像我这里一下写一个循环,根据前一个像素点是白色的后一个像素点是黑色的判定字符出现;根据前一个像素点是黑色的后一个像素点是白色的判定字符借宿,然后根据判定的位置进行切割。
果如还有哪儿不懂的话再问我吧~