Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: ParamUtils::ReportParamsUsageStatistics(): report the tesseract variables actually used during the current run. #4021

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions include/tesseract/baseapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@ class TESS_API TessBaseAPI {
*/
void PrintVariables(FILE *fp) const;

/*
* Report parameters' usage statistics, i.e. report which params have been
* set, modified and read/checked until now during this run-time's lifetime.
*
* Use this method for run-time 'discovery' about which tesseract parameters
* are actually *used* during your particular usage of the library, ergo
* answering the question:
* "Which of all those parameters are actually *relevant* to my use case today?"
*/
void ReportParamsUsageStatistics() const;

/**
* Get value of named variable as a string, if it exists.
*/
Expand Down
29 changes: 21 additions & 8 deletions src/api/baseapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ bool TessBaseAPI::SetDebugVariable(const char *name, const char *value) {
}

bool TessBaseAPI::GetIntVariable(const char *name, int *value) const {
auto *p = ParamUtils::FindParam<IntParam>(name, GlobalParams()->int_params,
tesseract_->params()->int_params);
auto *p = ParamUtils::FindParam<IntParam>(name, GlobalParams()->int_params(),
tesseract_->params()->int_params());
if (p == nullptr) {
return false;
}
Expand All @@ -302,8 +302,8 @@ bool TessBaseAPI::GetIntVariable(const char *name, int *value) const {
}

bool TessBaseAPI::GetBoolVariable(const char *name, bool *value) const {
auto *p = ParamUtils::FindParam<BoolParam>(name, GlobalParams()->bool_params,
tesseract_->params()->bool_params);
auto *p = ParamUtils::FindParam<BoolParam>(name, GlobalParams()->bool_params(),
tesseract_->params()->bool_params());
if (p == nullptr) {
return false;
}
Expand All @@ -312,14 +312,14 @@ bool TessBaseAPI::GetBoolVariable(const char *name, bool *value) const {
}

const char *TessBaseAPI::GetStringVariable(const char *name) const {
auto *p = ParamUtils::FindParam<StringParam>(name, GlobalParams()->string_params,
tesseract_->params()->string_params);
auto *p = ParamUtils::FindParam<StringParam>(name, GlobalParams()->string_params(),
tesseract_->params()->string_params());
return (p != nullptr) ? p->c_str() : nullptr;
}

bool TessBaseAPI::GetDoubleVariable(const char *name, double *value) const {
auto *p = ParamUtils::FindParam<DoubleParam>(name, GlobalParams()->double_params,
tesseract_->params()->double_params);
auto *p = ParamUtils::FindParam<DoubleParam>(name, GlobalParams()->double_params(),
tesseract_->params()->double_params());
if (p == nullptr) {
return false;
}
Expand Down Expand Up @@ -357,6 +357,19 @@ void TessBaseAPI::PrintVariables(FILE *fp) const {
ParamUtils::PrintParams(fp, tesseract_->params());
}

// Report parameters' usage statistics, i.e. report which params have been
// set, modified and read/checked until now during this run-time's lifetime.
//
// Use this method for run-time 'discovery' about which tesseract parameters
// are actually *used* during your particular usage of the library, ergo
// answering the question:
// "Which of all those parameters are actually *relevant* to my use case today?"
void TessBaseAPI::ReportParamsUsageStatistics() const {
tesseract::ParamsVectors *vec = tesseract_->params();

ParamUtils::ReportParamsUsageStatistics(vec);
}

/**
* The datapath must be the name of the data directory or
* some other file in which the data directory resides (for instance argv[0].)
Expand Down
8 changes: 4 additions & 4 deletions src/ccmain/paramsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,16 @@ SVMenuNode *ParamsEditor::BuildListOfAllLeaves(tesseract::Tesseract *tess) {
int num_iterations = (tess->params() == nullptr) ? 1 : 2;
for (int v = 0; v < num_iterations; ++v) {
tesseract::ParamsVectors *vec = (v == 0) ? GlobalParams() : tess->params();
for (auto &param : vec->int_params) {
for (auto &param : vec->int_params()) {
vc_it.add_after_then_move(new ParamContent(param));
}
for (auto &param : vec->bool_params) {
for (auto &param : vec->bool_params()) {
vc_it.add_after_then_move(new ParamContent(param));
}
for (auto &param : vec->string_params) {
for (auto &param : vec->string_params()) {
vc_it.add_after_then_move(new ParamContent(param));
}
for (auto &param : vec->double_params) {
for (auto &param : vec->double_params()) {
vc_it.add_after_then_move(new ParamContent(param));
}
}
Expand Down
Loading