-
Notifications
You must be signed in to change notification settings - Fork 591
/
ocropus-dewarp
executable file
·52 lines (38 loc) · 1.3 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
#!/usr/bin/env python
from __future__ import print_function
import re
import argparse
import sys
import numpy as np
from scipy.misc import imsave
import ocrolib
from ocrolib import lineest
np.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(np.amax(line)-line)
line = lnorm.normalize(line,cval=np.amax(line))
imsave(base+".dew.png",line)
except Exception as e:
print("ERROR", e)
continue