Remove jtol

pull/2/head
Vinayak Mehta 2016-09-13 17:28:21 +05:30 committed by GitHub
parent 439059817d
commit 757ba0444a
3 changed files with 5 additions and 15 deletions

View File

@ -44,10 +44,6 @@ class Lattice:
Scaling factor. Large scaling factor leads to smaller lines Scaling factor. Large scaling factor leads to smaller lines
being detected. (optional, default: 15) being detected. (optional, default: 15)
jtol : int
Tolerance to account for when comparing joint and line
coordinates. (optional, default: 2)
mtol : int mtol : int
Tolerance to account for when merging lines which are Tolerance to account for when merging lines which are
very close. (optional, default: 2) very close. (optional, default: 2)
@ -66,13 +62,12 @@ class Lattice:
Dictionary with page number as key and list of tables on that Dictionary with page number as key and list of tables on that
page as value. page as value.
""" """
def __init__(self, table_area=None, fill=None, jtol=[2], mtol=[2], scale=15, def __init__(self, table_area=None, fill=None, mtol=[2], scale=15,
invert=False, margins=(2.0, 0.5, 0.1), debug=None): invert=False, margins=(2.0, 0.5, 0.1), debug=None):
self.method = 'lattice' self.method = 'lattice'
self.table_area = table_area self.table_area = table_area
self.fill = fill self.fill = fill
self.jtol = jtol
self.mtol = mtol self.mtol = mtol
self.scale = scale self.scale = scale
self.invert = invert self.invert = invert
@ -135,8 +130,6 @@ class Lattice:
contours = find_table_contours(vmask, hmask) contours = find_table_contours(vmask, hmask)
table_bbox = find_table_joints(contours, vmask, hmask) table_bbox = find_table_joints(contours, vmask, hmask)
if len(self.jtol) == 1 and self.jtol[0] == 2:
self.jtol = self.jtol * len(table_bbox)
if len(self.mtol) == 1 and self.mtol[0] == 2: if len(self.mtol) == 1 and self.mtol[0] == 2:
self.mtol = self.mtol * len(table_bbox) self.mtol = self.mtol * len(table_bbox)
@ -176,7 +169,7 @@ class Lattice:
for i in range(0, len(rows) - 1)] for i in range(0, len(rows) - 1)]
table = Table(cols, rows) table = Table(cols, rows)
# set table edges to True using ver+hor lines # set table edges to True using ver+hor lines
table = table.set_edges(v_s, h_s, jtol=self.jtol[table_no]) table = table.set_edges(v_s, h_s)
nouse = table.nocont_ / (len(v_s) + len(h_s)) nouse = table.nocont_ / (len(v_s) + len(h_s))
table_data['line_p'] = 100 * (1 - nouse) table_data['line_p'] = 100 * (1 - nouse)
# set spanning cells to True # set spanning cells to True

View File

@ -126,7 +126,7 @@ class Pdf:
def debug_plot(self): def debug_plot(self):
"""Plots all text objects and various pdf geometries so that """Plots all text objects and various pdf geometries so that
user can choose number of columns, columns x-coordinates for user can choose number of columns, columns x-coordinates for
Stream or tweak Lattice parameters (scale, jtol, mtol). Stream or tweak Lattice parameters (mtol, scale).
""" """
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import matplotlib.patches as patches import matplotlib.patches as patches

View File

@ -55,15 +55,13 @@ lattice_doc = """
Lattice method looks for lines between text to form a table. Lattice method looks for lines between text to form a table.
usage: usage:
camelot lattice [-t <tarea>...] [-F <fill>...] [-j <jtol>...] camelot lattice [-t <tarea>...] [-F <fill>...]
[-m <mtol>...] [options] [--] <file> [-m <mtol>...] [options] [--] <file>
options: options:
-t, --tarea <tarea> Specific table areas to analyze. -t, --tarea <tarea> Specific table areas to analyze.
-F, --fill <fill> Fill data in horizontal and/or vertical spanning -F, --fill <fill> Fill data in horizontal and/or vertical spanning
cells. Example: -F h, -F v, -F hv cells. Example: -F h, -F v, -F hv
-j, --jtol <jtol> Tolerance to account for when comparing joint
and line coordinates. [default: 2]
-m, --mtol <mtol> Tolerance to account for when merging lines -m, --mtol <mtol> Tolerance to account for when merging lines
which are very close. [default: 2] which are very close. [default: 2]
-s, --scale <scale> Scaling factor. Large scaling factor leads to -s, --scale <scale> Scaling factor. Large scaling factor leads to
@ -341,9 +339,8 @@ if __name__ == '__main__':
try: try:
tarea = args['--tarea'] if args['--tarea'] else None tarea = args['--tarea'] if args['--tarea'] else None
fill = args['--fill'] if args['--fill'] else None fill = args['--fill'] if args['--fill'] else None
jtol = [int(j) for j in args['--jtol']]
mtol = [int(m) for m in args['--mtol']] mtol = [int(m) for m in args['--mtol']]
manager = Pdf(Lattice(table_area=tarea, fill=fill, jtol=jtol, manager = Pdf(Lattice(table_area=tarea, fill=fill,
mtol=mtol, scale=int(args['--scale']), mtol=mtol, scale=int(args['--scale']),
invert=args['--invert'], margins=margins, invert=args['--invert'], margins=margins,
debug=args['--debug']), debug=args['--debug']),