0

I am trying to intercept the red Empty page!! message that gets printed to my screen when using Tess4J. I wrote a short interceptor class that overrides print and println and replaced stdout and stderr to check for this string:

private static class Interceptor extends PrintStream {
    public Interceptor(OutputStream out) {
        super(out, true);
    }
    @Override
    public void print(String s) {
        if ( !s.contains("Empty page!!") )
            super.print(s);
    }
    @Override
    public void println(String s) {
        if ( !s.contains("Empty page!!") )
            super.println(s);
    }
}

I tested the class: It works and suppresses any Empty page!! that I write to stdout and stderr. I do not succeed in catching the Empty page!! message from Tess4J that gets printed to my console in red though. My question: How can I intercept and suppress this message?

Thanks a bunch.

Screenshot Eclipse

Community
  • 1
  • 1
dotwin
  • 1,302
  • 2
  • 11
  • 31

1 Answers1

3

You may want to emulate Tesseract's quiet command-line option, which has debug_file /dev/null.

api.setVariable("debug_file", "/dev/null");

or

instance.setTessVariable("debug_file", "/dev/null");
nguyenq
  • 8,212
  • 1
  • 16
  • 16
  • Hello nguyenq: Firstly, thanks a bunch for `Tess4J`. It is an awesome program. Secondly, could you please tell me a little more about the variable `api` you are referring to here? Thanks! – dotwin Nov 13 '14 at 03:49
  • It refers to the low-level `TessAPI`. You can also use the high-level one. More info about the [`quiet`](https://code.google.com/p/tesseract-ocr/wiki/FAQ#How_can_I_supress_tesseract_info_line?) option. – nguyenq Nov 14 '14 at 04:57
  • Thank you, nguyenq. I am still confused, however. I tried implementing it and it did not change anything for the output. Could you please provide me a short code snippet of how to implement it? Thanks a bunch. – dotwin Nov 16 '14 at 15:23
  • Can you attach a sample image that outputs "Empty page!!", so I can try out? Tks. – nguyenq Nov 20 '14 at 02:17
  • I am looping over a bunch of image files and some of them are empty. I would like to avoid all that "Empty Page!!" output. This is an example file that creates "Empty Page!!": https://www.dropbox.com/s/njppgbn5bwbnaui/193_351.jpg?dl=0 Thank you very much for your help. – dotwin Nov 20 '14 at 06:04
  • Try the code above -- it will suppress the warning messages. – nguyenq Nov 21 '14 at 01:23