Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust reading order when there are no columns #190

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ocrolib/psegutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def extract_masked(image,linedesc,pad=5,expand=0):
line = where(mask,line,amax(line))
return line

def reading_order(lines,highlight=None,debug=0):
def reading_order(lines,nocolumns=False,highlight=None,debug=0):
"""Given the list of lines (a list of 2D slices), computes
the partial reading order. The output is a binary 2D array
such that order[i,j] is true if line i comes before line j
Expand All @@ -141,7 +141,7 @@ def separates(w,u,v):
clf(); title("highlight"); imshow(binary); ginput(1,debug)
for i,u in enumerate(lines):
for j,v in enumerate(lines):
if x_overlaps(u,v):
if x_overlaps(u,v) or nocolumns:
if above(u,v):
order[i,j] = 1
else:
Expand Down
5 changes: 4 additions & 1 deletion ocropus-gpageseg
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,10 @@ def process1(job):

if not args.quiet: print_info("finding reading order")
lines = psegutils.compute_lines(segmentation,scale)
order = psegutils.reading_order([l.bounds for l in lines])
if args.maxcolseps>0 or args.blackseps:
order = psegutils.reading_order([l.bounds for l in lines])
else:
order = psegutils.reading_order([l.bounds for l in lines], nocolumns=True)
lsort = psegutils.topsort(order)

# renumber the labels so that they conform to the specs
Expand Down