From 20159d8bf4a624627110283202a46aad3d5d2973 Mon Sep 17 00:00:00 2001 From: Jesper Zedlitz Date: Mon, 16 Oct 2017 09:00:42 +0200 Subject: [PATCH 1/2] fixed https://github.com/tmbdev/ocropy/issues/251 --- ocropus-gpageseg | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ocropus-gpageseg b/ocropus-gpageseg index 3b61ad4f..9943a21a 100755 --- a/ocropus-gpageseg +++ b/ocropus-gpageseg @@ -13,6 +13,8 @@ from __future__ import print_function +from pylab import find + import argparse import glob import os @@ -302,7 +304,7 @@ def compute_line_seeds(binary,bottom,top,colseps,scale): seeds = np.zeros(binary.shape,'i') delta = max(3,int(scale/2)) for x in range(bmarked.shape[1]): - transitions = sorted([(y,1) for y in np.where(bmarked[:,x])[0]]+[(y,0) for y in np.where(tmarked[:,x][0])])[::-1] + transitions = sorted([(y,1) for y in find(bmarked[:,x])]+[(y,0) for y in find(tmarked[:,x])])[::-1] transitions += [(0,0)] for l in range(len(transitions)-1): y0,s0 = transitions[l] From c74d2be3f41aa7d997122b10d5d55c25622dfd41 Mon Sep 17 00:00:00 2001 From: Jesper Zedlitz Date: Mon, 16 Oct 2017 12:52:20 +0200 Subject: [PATCH 2/2] also works with out pylab --- ocropus-gpageseg | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ocropus-gpageseg b/ocropus-gpageseg index 9943a21a..88d069a8 100755 --- a/ocropus-gpageseg +++ b/ocropus-gpageseg @@ -13,8 +13,6 @@ from __future__ import print_function -from pylab import find - import argparse import glob import os @@ -108,7 +106,11 @@ parser.add_argument('files',nargs='+') args = parser.parse_args() args.files = ocrolib.glob_all(args.files) - +def find(condition): + "Return the indices where ravel(condition) is true" + res, = np.nonzero(np.ravel(condition)) + return res + def norm_max(v): return v/np.amax(v)