How to validate parameter names in C++

63 views
Skip to first unread message

Jeroen Ooms

unread,
Feb 22, 2018, 1:24:34 PM2/22/18
to tesseract-ocr
For the R bindings for Tesseract, we would like the user to be able to set custom tesseract parameters to api->Init() at runtime. However due to the way tesseract is implemented, tesseract crashes the R process if the user passes an unsupported parameter (see GH issue #1334). This is very bad.

As a workaround, I would like to first validate each user parameter before passing them to api->Init(). Currently my code looks like below, where 'names' and 'values' are string vectors, and 'out' is a boolean vector:

  tesseract::ParamsVectors p;
  for(size_t i = 0; i < names.size(); i++){
    out[i] = tesseract::ParamUtils::SetParam(names.at(i), values.at(i), tesseract::SET_PARAM_CONSTRAINT_NONE, &p);
  }

This code works, however it actually returns FALSE for some parameters. To be precise, from the 680 parameters returned by api->PrintVariables() in Tesseract 3.05, only the first 222 (until classify_pico_feature_length) are marked as valid this way.

I don't understand why this happens. Maybe some parameters are init-only and others are not? What would be a method to validate a tesseract parameter in C++ that would return TRUE for any supported tesseract parameter? Such that we can be sure that it is safe to pass these parameters to base->Init() ?

Reply all
Reply to author
Forward
0 new messages