MCPcopy Index your code
hub / github.com/lining0806/PythonSpiderNotes / binary

Function binary

Captcha1/tess_test.py:13–26  ·  view source on GitHub ↗
(image_name, binary_image_name)

Source from the content-addressed store, hash-verified

11
12# 二值化并转格式
13def binary(image_name, binary_image_name):
14 # 白底黑字
15 args = "convert -monochrome "+image_name+" "+binary_image_name
16 # print args
17 proc = subprocess.Popen(args, shell=True)
18 proc.wait()
19 im = Image.open(binary_image_name)
20 w, h = im.size
21 data = list(im.getdata())
22 if (data[0], data[w-1], data[(h-1)*w], data[h*w-1]) == (0, 0, 0, 0): # 0-黑色,255-白色
23 # 若非白底黑字则灰度反转
24 args1 = "convert -negate "+binary_image_name+" "+binary_image_name
25 proc1 = subprocess.Popen(args1, shell=True)
26 proc1.wait()
27
28# 计算范围内点的个数
29def numpoint(im):

Callers 1

tess_test.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected