Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Christoph Wick
ocropy
Commits
40273c2d
Commit
40273c2d
authored
Oct 23, 2016
by
Konstantin Baierer
Committed by
GitHub
Oct 23, 2016
Browse files
Merge pull request #123 from kba/deprecation-warning
nlbin: fix VisibleDeprecationWarning about non-integers
parents
75f57fd3
556a041c
Changes
1
Hide whitespace changes
Inline
Side-by-side
ocropus-nlbin
View file @
40273c2d
...
...
@@ -8,7 +8,6 @@ from scipy.ndimage import filters,interpolation,morphology,measurements
from
scipy
import
stats
import
multiprocessing
import
ocrolib
import
warnings
...
...
@@ -26,7 +25,7 @@ parser.add_argument('-z','--zoom',type=float,default=0.5,help='zoom for page bac
parser
.
add_argument
(
'-e'
,
'--escale'
,
type
=
float
,
default
=
1.0
,
help
=
'scale for estimating a mask over the text region, default: %(default)s'
)
parser
.
add_argument
(
'-b'
,
'--bignore'
,
type
=
float
,
default
=
0.1
,
help
=
'ignore this much of the border for threshold estimation, default: %(default)s'
)
parser
.
add_argument
(
'-p'
,
'--perc'
,
type
=
float
,
default
=
80
,
help
=
'percentage for filters, default: %(default)s'
)
parser
.
add_argument
(
'-r'
,
'--range'
,
type
=
floa
t
,
default
=
20
,
help
=
'range for filters, default: %(default)s'
)
parser
.
add_argument
(
'-r'
,
'--range'
,
type
=
in
t
,
default
=
20
,
help
=
'range for filters, default: %(default)s'
)
parser
.
add_argument
(
'-m'
,
'--maxskew'
,
type
=
float
,
default
=
2
,
help
=
'skew angle estimation parameters (degrees), default: %(default)s'
)
parser
.
add_argument
(
'-g'
,
'--gray'
,
action
=
'store_true'
,
help
=
'force grayscale processing even if image seems binary'
)
parser
.
add_argument
(
'--lo'
,
type
=
float
,
default
=
5
,
help
=
'percentile for black estimation, default: %(default)s'
)
...
...
@@ -135,7 +134,6 @@ def process1(job):
comment
=
""
# if not, we need to flatten it by estimating the local whitelevel
if
args
.
parallel
<
2
:
print_info
(
"flattening"
)
warnings
.
filterwarnings
(
"ignore"
,
category
=
UserWarning
)
m
=
interpolation
.
zoom
(
image
,
args
.
zoom
)
m
=
filters
.
percentile_filter
(
m
,
args
.
perc
,
size
=
(
args
.
range
,
2
))
m
=
filters
.
percentile_filter
(
m
,
args
.
perc
,
size
=
(
2
,
args
.
range
))
...
...
@@ -143,7 +141,6 @@ def process1(job):
if
args
.
debug
>
0
:
clf
();
imshow
(
m
,
vmin
=
0
,
vmax
=
1
);
ginput
(
1
,
args
.
debug
)
w
,
h
=
minimum
(
array
(
image
.
shape
),
array
(
m
.
shape
))
flat
=
clip
(
image
[:
w
,:
h
]
-
m
[:
w
,:
h
]
+
1
,
0
,
1
)
warnings
.
resetwarnings
()
if
args
.
debug
>
0
:
clf
();
imshow
(
flat
,
vmin
=
0
,
vmax
=
1
);
ginput
(
1
,
args
.
debug
)
# estimate skew angle and rotate
...
...
@@ -164,7 +161,6 @@ def process1(job):
# estimate low and high thresholds
if
args
.
parallel
<
2
:
print_info
(
"estimating thresholds"
)
warnings
.
filterwarnings
(
"ignore"
,
category
=
DeprecationWarning
)
d0
,
d1
=
flat
.
shape
o0
,
o1
=
int
(
args
.
bignore
*
d0
),
int
(
args
.
bignore
*
d1
)
est
=
flat
[
o0
:
d0
-
o0
,
o1
:
d1
-
o1
]
...
...
@@ -176,13 +172,12 @@ def process1(job):
v
=
est
-
filters
.
gaussian_filter
(
est
,
e
*
20.0
)
v
=
filters
.
gaussian_filter
(
v
**
2
,
e
*
20.0
)
**
0.5
v
=
(
v
>
0.3
*
amax
(
v
))
v
=
morphology
.
binary_dilation
(
v
,
structure
=
ones
((
e
*
50
,
1
)))
v
=
morphology
.
binary_dilation
(
v
,
structure
=
ones
((
1
,
e
*
50
)))
v
=
morphology
.
binary_dilation
(
v
,
structure
=
ones
((
int
(
e
*
50
)
,
1
)))
v
=
morphology
.
binary_dilation
(
v
,
structure
=
ones
((
1
,
int
(
e
*
50
)))
)
if
args
.
debug
>
0
:
imshow
(
v
);
ginput
(
1
,
args
.
debug
)
est
=
est
[
v
]
lo
=
stats
.
scoreatpercentile
(
est
.
ravel
(),
args
.
lo
)
hi
=
stats
.
scoreatpercentile
(
est
.
ravel
(),
args
.
hi
)
warnings
.
resetwarnings
()
# rescale the image to get the gray scale image
if
args
.
parallel
<
2
:
print_info
(
"rescaling"
)
flat
-=
lo
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment