5

Tesseract.js seems to print to the console with every call to .recognize(), even with no option parameters attached.

It seems possible to quiet the output with the Tesseract CLI by using the "quiet" flag, but I can't find anything like that for Tesseract.js.

I've scanned through the parameters that could be passed to "options" as found on the Tesseract.js repository: https://github.com/naptha/tesseract.js/blob/master/docs/tesseract_parameters.md

I've tried setting everything that has to do with "DEBUG" to 0, and I've tried sending the output to a "debug_file" parameter, but nothing I do seems to change the console output.

Here's a basic example with no parameters on the "options" object:

const fs = require('fs');
const Tesseract = require('tesseract.js');

const image = fs.readFileSync('path/to/image.jpg');
const options = {};

Tesseract.recognize(image, options)
         .finally((resultOrError) => {
             Tesseract.terminate();
         }
);

I would expect there to be no output at all here, but instead this gets printed:

pre-main prep time: 76 ms
{ text: '',
  html: '<div class=\'ocr_page\' id=\'page_1\' title=\'image ""; bbox 0 0 600 80; ppageno 0\'>\n</div>\n',
  confidence: 0,
  blocks: [],
  psm: 'SINGLE_BLOCK',
  oem: 'DEFAULT',
  version: '3.04.00',
  paragraphs: [],
  lines: [],
  words: [],
  symbols: [] }

UPDATE

Okay, okay. It's early in the morning, I could have tried a little harder here. It looks like Tesseract.js automatically dumps everything to the console if you don't make calls to .catch() and .then(). With the example below, most of the console output disappears.

const fs = require('fs');
const Tesseract = require('tesseract.js');

const image = fs.readFileSync('path/to/image.jpg');
const options = {};

const doSomethingWithResult = (result) => { result };
const doSomethingWithError = (error) => { error };

Tesseract.recognize(image, options)
         .then(result => doSomethingWithResult(result))
         .catch(err => doSomethingWithError(err))
         .finally((resultOrError) => {
             Tesseract.terminate();
         }
);

Now, only this gets printed to the console:

pre-main prep time: 66 ms

I'd still like a way to suppress this, so I'm going to leave the question unanswered for now. I hope someone can chime in with a suggestion.

0 Answers0