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

ocropus-gpageseg: Enable usage of masks to specify column separators/ ignore areas of scan #236

Merged
merged 6 commits into from
Feb 19, 2018
Merged
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
13 changes: 12 additions & 1 deletion ocropus-gpageseg
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def DSAVE(title,image):
### This attempts to find column separators, either as extended
### vertical black lines or extended vertical whitespace.
### It will work fairly well in simple cases, but for unusual
### documents, you need to tune the parameters.
### documents, you need to tune the parameters or use a mask.
################################################################

def compute_separators_morph(binary,scale):
Expand Down Expand Up @@ -262,8 +262,19 @@ def compute_colseps(binary,scale):
#colseps = compute_colseps_morph(binary,scale)
colseps = np.maximum(colseps,seps)
binary = np.minimum(binary,1-seps)
binary,colseps = apply_mask(binary,colseps)
return colseps,binary

def apply_mask(binary,colseps):
try:
mask = ocrolib.read_image_binary(base+".mask.png")
except IOError:
return binary,colseps
masked_seps = np.maximum(colseps,mask)
binary = np.minimum(binary,1-masked_seps)
DSAVE("masked_seps", masked_seps)
return binary,masked_seps


################################################################
### Text Line Finding.
Expand Down
2 changes: 2 additions & 0 deletions run-test-ci
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ test_gpageseg() {
$RUNNER $BASE/ocropus-gpageseg temp/$TESTIMAGE -n --maxseps 3
$RUNNER $BASE/ocropus-gpageseg temp/$TESTIMAGE -n -b
$RUNNER $BASE/ocropus-gpageseg temp/$TESTIMAGE -n --usegauss
cp $BASE/tests/table.bin.png $BASE/tests/table.mask.png temp
$RUNNER $BASE/ocropus-gpageseg temp/table.bin.png --debug -n --minscale 7 --maxcolseps 0
}

test_rpred() {
Expand Down
Binary file added tests/table.bin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/table.mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.