forked from ocropus-archive/DUP-ocropy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ocropus-dewarp
executable file
·53 lines (42 loc) · 1.35 KB
/
ocropus-dewarp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
import random as pyrandom
import re
from pylab import *
import os.path
import ocrolib
import argparse
import matplotlib
import numpy
from ocrolib import lineest
import ocrolib.lstm as lstm
import traceback
import scipy
numpy.seterr(divide='raise',over='raise',invalid='raise',under='ignore')
parser = argparse.ArgumentParser("dewarp lines as used for the recognizer")
parser.add_argument("-e","--lineest",default="center",
help="type of text line estimator, default: %(default)s")
parser.add_argument("-l","--height",default=48,type=int,
help="set the default height for line estimation, default: %(default)s")
parser.add_argument("files",nargs="*")
args = parser.parse_args()
inputs = ocrolib.glob_all(args.files)
if len(inputs)==0:
parser.print_help()
sys.exit(0)
print "# inputs",len(inputs)
if args.lineest=="center":
lnorm = lineest.CenterNormalizer()
else:
raise Exception(args.lineest+": unknown line normalizer")
lnorm.setHeight(args.height)
for fname in inputs:
print "#",fname
base,_ = ocrolib.allsplitext(fname)
try:
line = ocrolib.read_image_gray(fname)
lnorm.measure(amax(line)-line)
line = lnorm.normalize(line,cval=amax(line))
scipy.misc.imsave(base+".dew.png",line)
except Exception as e:
print "ERROR",e
continue