【发布时间】:2015-08-04 09:55:46
【问题描述】:
result = check_output(['ocrad', fn + '.ppm']).strip().replace(' ', '')
有问题..
File "coding.ch17.py", line 55, in <module>
ch17()
File "coding.ch17.py", line 48, in ch17
result = solve_ch17(fn)
File "coding.ch17.py", line 35, in solve_ch17
result = check_output(['ocrad', fn + '.ppm']).strip().replace(' ', '')
File "/usr/lib/python2.7/subprocess.py", line 566, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
你能帮帮我吗?
源代码
def solve_ch17(fn):
black, white = (0, 0, 0), (255, 255, 255)
bg, fg = white, black
# open image
img = Image.open(fn)
mx, my = img.size
pix = img.load()
# remove background
for x in range(mx):
for y in range(my):
if pix[x,y] == white:
pix[x,y] = fg
else:
pix[x,y] = bg
# split text
lx, ly = 70, 23
for c in range(6):
for xi in range(9):
for yi in range(12):
x, y = lx + c*9 + xi, ly + yi
if pix[x, y] == fg:
nx = 15 + c*20 + xi
pix[x, y], pix[nx, y] = bg, fg
# scale up
r = 3
img = img.resize((int(round(mx * r, 2)), int(round(my * r, 2))), Image.BICUBIC) # NEAREST, BILINEAR, BICUBIC
img.save(fn + '.ppm')
result = check_output(['ocrad', fn, + '.ppm']).strip().replace(' ', '')
return result
【问题讨论】:
-
你能告诉我们什么是 check_Output 函数吗?
-
fn的值是多少?您能否在result =行之前显示更多代码
标签: python python-2.7 subprocess