File tree Expand file tree Collapse file tree 1 file changed +42
-1
lines changed Expand file tree Collapse file tree 1 file changed +42
-1
lines changed Original file line number Diff line number Diff line change
1
+ #coding=gbk
1
2
3
+ from __future__ import unicode_literals
4
+ import Image
5
+ import urllib
2
6
3
7
class Binaryzation (object ):
4
- pass
8
+ """
9
+ 将图像进行二值化处理
10
+ """
11
+
12
+ image = None
13
+
14
+ def __init__ (self ,img ):
15
+ self .image = img
16
+
17
+ def __ConvertToGray (self ):
18
+ """
19
+ 将图片灰度化处理
20
+ """
21
+ if self .image :
22
+ return self .image .convert ('L' )
23
+ return None
24
+
25
+ def ConvertToBinaryzation (self ,b ):
26
+ """
27
+ 二值化
28
+ b: 可以理解为亮度,大于这个亮度的全部变为纯白色
29
+ """
30
+ if self .image :
31
+ self .image = self .__ConvertToGray ()
32
+ return self .image .point (lambda i :i > b and 255 )
33
+ return None
34
+
35
+
36
+ if __name__ == '__main__' :
37
+ url = 'http://regcheckcode.taobao.com/auction/checkcode?sessionID=f06c56ea0e0bda9a9d71832422b68f29'
38
+ s = urllib .urlopen (url ).read ()
39
+ f = open ('v.jpg' ,'wb' )
40
+ f .write (s )
41
+ f .close ()
42
+ im = Image .open ('v.jpg' )
43
+ b = Binaryzation (im )
44
+ im = b .ConvertToBinaryzation (160 )
45
+ im .show ()
You can’t perform that action at this time.
0 commit comments