How to set and get a variable in tesseract using C

2019-07-20 20:10发布

问题:

I have a quick question: How to I get the variable in tesseract using C++.

For example I want to set "load_system_dawg" to false

`tesseract.setVariable("load_system_dawg",?);`

Is ? = 0 and 1, or "true" and "false"?

And also how to check the settings of a variable?

`tesseract.getBoolVariable("load_system_dawg");`
or 
`tesseract.getVariableAsString("load_system_dawg");`

In all my cases and attempts the code breaks.

Documentation Tesseract GetBoolVariable

EDIT

I am able to get a variable, but why is get after set not possible.

tess.SetVariable("load_punc_dawg", "0");
tess.SetVariable("load_punc_dawg", "false");
bool result = false;
tess.GetBoolVariable("load_punc_dawg", &result);

But the result = true. bool thisOne = tess.GetBoolVariable("load_punc_dawg", &result);

returns `"thisOne" = true`, and `"result" = true"`

And To check the results I am debugging through the code.

回答1:

I do not know ocr, but simply by reading the doc I found out, that....

The function to get the bool variable has this signature:

bool GetBoolVariable (const char * name,bool * value) const

So you have to call it like this:

bool result;
tesseract.GetBoolVariable("name",&result);

The setVariable takes a const char * as second argument. Thus your ? should be either "0"/"1" or "true"/"false" (but not 0/1 or true/false and I am pretty sure that both variants will work).



回答2:

Ok, that seems to be very interesting. Set the parameter at the tesseract initialization works for me at the moment.

GenericVector<STRING> pars_vec;
pars_vec.push_back("load_punc_dawg");

GenericVector<STRING> pars_values;
pars_values.push_back("0"); //"false"

tesseract::TessBaseAPI tess;
tess.Init(NULL, "eng", tesseract::OEM_TESSERACT_ONLY, NULL, 0, &pars_vec,
            &pars_values, false);

bool result = false;
bool thisOne = tess.GetBoolVariable("load_punc_dawg", &result);

returns "thisOne" = true and "result" = false

Source found here