1

I am statically linking to the Tesseract OCR engine on Windows from a command line program written in C++. I would like to initialize Tesseract such that if it is not a Debug build Tesseract does not output text to the console window.

There is an existing question about running the tesseract command line program (not using it as a library) in quiet mode on Linux, link, with an answer stating that what you need to do is set the variable "debug_file" to "/dev/null" which clearly only makes sense on Linux but implies that the idea is to pipe Tesseract's verbosity to a log file. But even setting this variable to an arbitrary file does nothing under Windows. Below I try to do it at initialization time:

GenericVector<STRING> vars;
GenericVector<STRING> vals;
vars.push_back("debug_file");
vals.push_back("C:\\test\\tess.log");
std::string data_path = "garbage data path that will cause Init to issue errors";
auto result = ocr_->Init(data_path.c_str(), "eng", tesseract::OEM_TESSERACT_ONLY, NULL, 0, &vars, &vals, false);

and still see

Error opening data file 
garbage_path_that_will_cause_init_to_issue_errors_to_the_cmd_line/eng.traineddata
Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory.
Failed loading language 'eng'
Tesseract couldn't load any languages!

whether "tess.log" exists or doesn't exist. When I search for documentation of the variables you can pass to Tesseract I see people citing the following as the definitive list: link, which does indeed contain "debug_file" as a variable but has no variable about "quiet mode" or verbosity.

jwezorek
  • 8,592
  • 1
  • 29
  • 46
  • `Init` should not really fail, unless there's something wrong with your setup. On your example, Tesseract is trying to tell you what's wrong on your environment. After initializing properly, you should be able to use `SetVariable` to set `debug_file` to an appropriate location. – Not a real meerkat Sep 16 '20 at 18:33
  • I dont want to see error messages on the command line if Init fails though that is why I am trying to make it quiet in the call to Init. – jwezorek Sep 16 '20 at 18:36
  • So your question really is "how to silence initialization errors". I'm sorry, I know this sounds like a technicality, but that is a different issue from just enabling quiet mode. Bad news is I don't think Tesseract really supports that, though as I'm not sure about this, I can't really post this as an answer. Good luck, I hope you find a more definitive answer. – Not a real meerkat Sep 16 '20 at 18:41
  • and also the equivalent of /dev/null on windows but that I have solved it is "NUL" – jwezorek Sep 16 '20 at 21:16

0 Answers0