-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d28fa6
commit 49da060
Showing
5 changed files
with
95 additions
and
11 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
*~ | ||
.ropeproject/ | ||
*.jpg | ||
Images/ |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.png |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/env python | ||
# author: Hua Liang [ Stupid ET ] | ||
# email: [email protected] | ||
# website: http://EverET.org | ||
# | ||
# This is a tools that generate each image of character | ||
|
||
import random, string, md5, time | ||
import Image, ImageDraw, ImageFont | ||
import StringIO, string | ||
|
||
def get_vertical_map(img): | ||
img = img.convert('L') | ||
# segmentation | ||
m = [0] * width | ||
for x in range(width): | ||
for y in range(height): | ||
if img.getpixel((x, y)) != 255: | ||
m[x] += 1 | ||
return m | ||
|
||
def get_character_region(iterator): | ||
'''get character region | ||
''' | ||
state = "empty" | ||
|
||
i, lbd, rbd = 0, -1, -1 | ||
while True: | ||
data = iterator.next() | ||
if state == "empty": | ||
if data != 0: | ||
# enter | ||
state = "collect" | ||
lbd = i | ||
elif state == "collect": | ||
if data == 0: | ||
# leave | ||
rbd = i | ||
state = "empty" | ||
yield (lbd, rbd) | ||
i += 1 | ||
|
||
width, height = 1200, 40 | ||
|
||
characters = string.letters + string.digits | ||
|
||
# draw img | ||
img = Image.new("RGBA", (width, height), (255, 255, 255, 0)) | ||
font = ImageFont.truetype("../UbuntuMono-R.ttf", 33) | ||
draw = ImageDraw.Draw(img) | ||
draw.setfont(font) | ||
draw.text((10, 0), characters, (0, 0, 0, 255)) | ||
del draw | ||
|
||
m = get_vertical_map(img) | ||
|
||
for index, bd in enumerate(get_character_region(iter(m))): | ||
ch = characters[index] | ||
|
||
img.crop((bd[0], 0, bd[1], height)).save('../Images/%s.png' % ch) | ||
|