Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The semantics of TessBaseAPI::Clear()

Tags:

c++

ocr

tesseract

Suppose I've created two objects of TessBaseAPIxapi and yapi — initialized by calling the following overload of Init() function:

int Init(const char * datapath,
         const char * language,
         OcrEngineMode  oem,
         char **    configs,
         int    configs_size,
         const GenericVector< STRING > *    vars_vec,
         const GenericVector< STRING > *    vars_values,
         bool   set_only_non_debug_params 
);

passing exactly identical arguments.

Since the objects are initialized with identical arguments, at this point xapi and yapi are assumed to be identical from behavioral1 perspective. Is my assumption correct? I hope so, as I don't find any reason for the objects to be non-identical.


Now I'm going to use xapi to extract information from an image but before that I call SetVariable() a number of times, to set few more configurations.

bool SetVariable(const char * name, const char * value);

and then I used xapi to extract some text from an image. Once I'm done with the extraction, I did this:

 xapi.Clear(); //what exactly happens here?

After the call to Clear(), can I use xapi and yapi interchangeably? In other words, can I assume that xapi and yapi are identical at this point from behavioral1 perspective? Can I say Clear() is actually a reset functionality?

1. By "behavioral", I meant performance in terms of accuracy, not speed/latency.

like image 896
Nawaz Avatar asked Jun 27 '18 18:06

Nawaz


1 Answers

According to the void tesseract::TessBaseAPI::Clear() documentation, the call to this function will free up the image data and the recognition results. It says nothing about configuration data. Moreover, if the authors consider the configuration data as being time-consuming to load, it's going to be kept intact: without actually freeing any recognition data that would be time-consuming to reload.

Answering your other questions:

  1. "After the call to Clear(), can I use xapi and yapi interchangeably?" -- yes, you may, but results might differ because of different settings you have applied to xapi via SetVariable(), but not to yapi.

  2. "In other words, can I assume that xapi and yapi are identical at this point from behavioral1 perspective?" -- depending on what settings you have changed with SetVariable(), the results may be or may be not the same.

  3. "Can I say Clear() is actually a reset functionality?" -- only the recognition results and the image data is discarded, everything else is kept intact. Depending on your definition of reset, you may call it a reset or not, it's a free country after all =)

You may check the difference between Clear() and the full teardown using End(). It's around line 1400 of baseapi.cpp.

like image 109
lenik Avatar answered Oct 04 '22 20:10

lenik