mittagessen / kraken

OCR engine for all the languages
http://kraken.re
Apache License 2.0
724 stars 130 forks source link

recognition on external segmentation: numpy warnings #370

Closed bertsky closed 2 years ago

bertsky commented 2 years ago

When doing kraken.rpred on page images with external line bboxes, I sometimes get this:

kraken/lib/lineest.py:84: RuntimeWarning: invalid value encountered in true_divide
  temp = temp*1.0/np.amax(temp)
WARNING kraken.rpred - Empty run. Skipping.

So, does that mean the recognizer does a CenterNormalizer dewarping implicitly?

Also, should I check the segmentation for plausibility myself, or can we get rid of these warnings on Kraken side?

(Context: https://github.com/OCR-D/ocrd_kraken/pull/33 recognize.py)

mittagessen commented 2 years ago

Yes, on line image files that can be normalized (b/w or grayscale, bbox format) the line dewarping will be run on. If you're extracting/dewarping baseline-type lines manually it is important to circumvent that logic (reformulate the box as a baseline+bounding polygon) as re-dewarping causes quite a significant accuracy drop.

The warning is because the line is empty (RuntimeWarning because of divide-by-zero, the other one because of an explicit check).

bertsky commented 2 years ago

If you're extracting/dewarping baseline-type lines manually it is important to circumvent that logic (reformulate the box as a baseline+bounding polygon) as re-dewarping causes quite a significant accuracy drop.

I don't understand. If I have a baseline-segmented textline, which I have dewarped already, then I should not just pass its line image to Kraken, but ... ?

The warning is because the line is empty (RuntimeWarning because of divide-by-zero, the other one because of an explicit check).

Yes, that's why I asked whether I need to check segment plausibility externally. (Ocropy had check_line etc for that.) The Numpy message is not properly log-formatted, so I'd like to get rid of it entirely.

mittagessen commented 2 years ago

I don't understand. If I have a baseline-segmented textline, which I have dewarped already, then I should not just pass its line image to Kraken, but ... ?

You can just pass it but you've got to make sure that it is run through the baseline code path which doesn't apply the centerline normalization. For example you've got an already dewarped line image of size (50, 750) you'd give the segmentation as:

'lines': [{'baseline': [(10, 0), (10, 750)], 'boundary': [(0, 0), (0, 50), (750, 50), (0, 750)]}]

instead of

'boxes': [[0, 0, 50, 750]]

to ensure the centerline normalization isn't applied. Hope that makes sense.

bertsky commented 2 years ago

Hope that makes sense.

It does – thanks!