List variables / languages via API

39 views
Skip to first unread message

Jeroen Ooms

unread,
Dec 8, 2016, 9:51:49 AM12/8/16
to tesseract-ocr

Would it be possible to add to the APIexample wiki on how to accomplish the equivalent of tesseract --list-langs and tesseract --print-parameters via the API?


To list languages I currently use something like the following. However the problem is that I first need to initialize the english engine which might not be available. Is there a way to list languages without initializing any engine?


  tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
  if (api->Init(NULL, "eng"))
    throw std::runtime_error(std::string("Unable to find training data for"));
  api->GetAvailableLanguagesAsVector(langs);
  std::vector<std::string> available;
  for(int i = 0; i < langs->length(); i++)
    available.push_back(langs->get(i).c_str());


The only method I can find in the base API to list supported parameters is:


api->PrintVariables(stdout);


However this prints a text dump which is difficult to read by machines. Is there an api to iterate over the supported variables strings and stick them into a std::vector<std::string> ?

Zdenko Podobný

unread,
Dec 8, 2016, 1:35:05 PM12/8/16
to tesser...@googlegroups.com

On Thu, Dec 8, 2016 at 3:27 PM, Jeroen Ooms <jeroe...@gmail.com> wrote:

Is there a way to list languages without initializing any engine?


No. This functions needs to know tesseract tessdata path (datadir[1]) which is available only after initialization of engine (user can modified during tesseract initialization)


Of course you can implement similar function by yourself - just by guessing tesseract tessdata path.   

Zdenko

Zdenko Podobný

unread,
Dec 8, 2016, 1:52:40 PM12/8/16
to tesser...@googlegroups.com
On Thu, Dec 8, 2016 at 3:27 PM, Jeroen Ooms <jeroe...@gmail.com> wrote:

The only method I can find in the base API to list supported parameters is:


api->PrintVariables(stdout);


However this prints a text dump which is difficult to read by machines. Is there an api to iterate over the supported variables strings and stick them into a std::vector<std::string> ?

Output is tab separated so it should be easy to read by machines ;-) 
On other hand I understand that some developers do not want to use temporary files... IMO it should be easy to create new function by modifying ParamUtils::PrintParams[1].

Reply all
Reply to author
Forward
0 new messages