Merge pull request #1479 from stweil/version

training: Add initial support for --version argument and check library version
This commit is contained in:
zdenop 2018-04-15 12:59:58 +02:00 committed by GitHub
commit a07ee5c40b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 66 additions and 29 deletions

View File

@ -18,6 +18,10 @@
#ifndef API_CAPI_H_
#define API_CAPI_H_
#if defined(TESSERACT_API_BASEAPI_H_) && !defined(TESS_CAPI_INCLUDE_BASEAPI)
# define TESS_CAPI_INCLUDE_BASEAPI
#endif
#ifdef TESS_CAPI_INCLUDE_BASEAPI
# include "baseapi.h"
# include "pageiterator.h"

View File

@ -24,12 +24,14 @@
#include <stdio.h>
#include "baseapi.h"
#include "commontraining.h" // CheckSharedLibraryVersion
#include "helpers.h"
#include "strngs.h"
#include "dict.h"
#include "tesseractclass.h"
int main(int argc, char** argv) {
tesseract::CheckSharedLibraryVersion();
// Parse input arguments.
if (argc != 4 && (argc != 6 || strcmp(argv[1], "-l") != 0)) {

View File

@ -111,6 +111,7 @@ static tesseract::ShapeClassifier* InitializeClassifier(
// full : Tesseract full classifier.
// with an input trainer.)
int main(int argc, char **argv) {
tesseract::CheckSharedLibraryVersion();
ParseArguments(&argc, &argv);
STRING file_prefix;
tesseract::MasterTrainer* trainer =

View File

@ -41,13 +41,6 @@
DECLARE_STRING_PARAM_FLAG(D);
/*----------------------------------------------------------------------------
Public Function Prototypes
----------------------------------------------------------------------------*/
int main (
int argc,
char **argv);
/*----------------------------------------------------------------------------
Private Function Prototypes
----------------------------------------------------------------------------*/
@ -131,6 +124,8 @@ CLUSTERCONFIG CNConfig =
* @note History: Fri Aug 18 08:56:17 1989, DSJ, Created.
*/
int main(int argc, char *argv[]) {
tesseract::CheckSharedLibraryVersion();
// Set the global Config parameters before parsing the command line.
Config = CNConfig;

View File

@ -15,7 +15,9 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "commandlineflags.h"
#include "commontraining.h" // CheckSharedLibraryVersion
#include "lang_model_helpers.h"
#include "tprintf.h"
#include "unicharset_training_utils.h"
@ -38,6 +40,7 @@ BOOL_PARAM_FLAG(pass_through_recoder, false,
" unicharset. Otherwise, potentially a compression of it");
int main(int argc, char** argv) {
tesseract::CheckSharedLibraryVersion();
tesseract::ParseCommandLineFlags(argv[0], &argc, &argv, true);
// Check validity of input flags.

View File

@ -18,6 +18,7 @@
//
///////////////////////////////////////////////////////////////////////
#include "commontraining.h" // CheckSharedLibraryVersion
#include "lstmrecognizer.h"
#include "tessdatamanager.h"
@ -65,6 +66,8 @@
// components from tessdata/eng.traineddata.
//
int main(int argc, char **argv) {
tesseract::CheckSharedLibraryVersion();
int i;
tesseract::TessdataManager tm;
if (argc == 2) {

View File

@ -7,6 +7,8 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "baseapi.h" // TessBaseAPI::Version
#include "commandlineflags.h"
#ifndef GOOGLE_TESSERACT
@ -55,7 +57,6 @@ bool StringFlagExists(const char* flag_name, const char** value) {
return p != nullptr;
}
void SetIntFlagValue(const char* flag_name, const int32_t new_val) {
STRING full_flag_name("FLAGS_");
full_flag_name += flag_name;
@ -149,7 +150,6 @@ void PrintCommandLineFlags() {
}
}
void ParseCommandLineFlags(const char* usage,
int* argc, char*** argv,
const bool remove_flags) {
@ -157,6 +157,9 @@ void ParseCommandLineFlags(const char* usage,
printf("USAGE: %s\n", usage);
PrintCommandLineFlags();
exit(0);
} else if (*argc > 1 && !strcmp((*argv)[1], "--version")) {
printf("%s\n", TessBaseAPI::Version());
exit(0);
}
unsigned int i = 1;
@ -174,7 +177,7 @@ void ParseCommandLineFlags(const char* usage,
// If this is asking for usage, print the help message and abort.
if (!strcmp(current_arg, "help") ||
!strcmp(current_arg, "helpshort")) {
tprintf("USAGE: %s\n", usage);
printf("USAGE: %s\n", usage);
PrintCommandLineFlags();
exit(0);
}

View File

@ -87,6 +87,8 @@ void ParseArguments(int* argc, char ***argv) {
STRING usage;
if (*argc) {
usage += (*argv)[0];
usage += " --version | ";
usage += (*argv)[0];
}
usage += " [.tr files ...]";
tesseract::ParseCommandLineFlags(usage.c_str(), argc, argv, true);

View File

@ -14,6 +14,10 @@
#ifndef TESSERACT_TRAINING_COMMONTRAINING_H_
#define TESSERACT_TRAINING_COMMONTRAINING_H_
#ifdef HAVE_CONFIG_H
#include "config_auto.h"
#include "baseapi.h"
#endif
#include "cluster.h"
#include "commandlineflags.h"
#include "featdefs.h"
@ -63,6 +67,21 @@ void ParseArguments(int* argc, char*** argv);
namespace tesseract {
// Check whether the shared tesseract library is the right one.
// This function must be inline because otherwise it would be part of
// the shared library, so it could not compare the versions.
static inline void CheckSharedLibraryVersion()
{
#ifdef HAVE_CONFIG_H
if (!!strcmp(TESSERACT_VERSION_STR, TessBaseAPI::Version())) {
tprintf("ERROR: shared library version mismatch (was %s, expected %s\n"
"Did you use a wrong shared tesseract library?\n",
TessBaseAPI::Version(), TESSERACT_VERSION_STR);
exit(1);
}
#endif
}
// Helper loads shape table from the given file.
ShapeTable* LoadShapeTable(const STRING& file_prefix);
// Helper to write the shape_table.

View File

@ -17,6 +17,7 @@
//
///////////////////////////////////////////////////////////////////////
#include "commontraining.h" // CheckSharedLibraryVersion
#include "dawg.h"
#include "host.h"
#include "serialis.h"
@ -72,6 +73,8 @@ int WriteDawgAsWordlist(const UNICHARSET &unicharset,
}
int main(int argc, char *argv[]) {
tesseract::CheckSharedLibraryVersion();
if (argc != 4) {
tprintf("Print all the words in a given dawg.\n");
tprintf("Usage: %s <unicharset> <dawgfile> <wordlistfile>\n",

View File

@ -36,6 +36,7 @@ INT_PARAM_FLAG(verbosity, 1,
"Amount of diagnosting information to output (0-2).");
int main(int argc, char **argv) {
tesseract::CheckSharedLibraryVersion();
ParseArguments(&argc, &argv);
if (FLAGS_model.empty()) {
tprintf("Must provide a --model!\n");

View File

@ -71,6 +71,7 @@ const int kNumPagesPerBatch = 100;
// The program iterates over the inputs, feeding the data to the network,
// until the error rate reaches a specified target or max_iterations is reached.
int main(int argc, char **argv) {
tesseract::CheckSharedLibraryVersion();
ParseArguments(&argc, &argv);
// Purify the model name in case it is based on the network string.
if (FLAGS_model_output.empty()) {

View File

@ -17,10 +17,12 @@
//
///////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include "commontraining.h" // CheckSharedLibraryVersion
#include "unicharset.h"
int main(int argc, char** argv) {
tesseract::CheckSharedLibraryVersion();
// Print usage
if (argc < 4) {
printf("Usage: %s unicharset-in-1 ... unicharset-in-n unicharset-out\n",

View File

@ -76,14 +76,6 @@ const int kMaxShapeLabelLength = 10;
DECLARE_STRING_PARAM_FLAG(test_ch);
/*----------------------------------------------------------------------------
Public Function Prototypes
----------------------------------------------------------------------------*/
int main (
int argc,
char **argv);
/*----------------------------------------------------------------------------
Public Code
-----------------------------------------------------------------------------*/
@ -236,6 +228,8 @@ static void SetupConfigMap(ShapeTable* shape_table, IndexMapBiDi* config_map) {
* @note History: Mon May 18 1998, Christy Russson, Revistion started.
*/
int main (int argc, char **argv) {
tesseract::CheckSharedLibraryVersion();
ParseArguments(&argc, &argv);
ShapeTable* shape_table = nullptr;

View File

@ -12,11 +12,8 @@
// object, fills it with properties about the unichars it contains and writes
// the result back to a file.
#include <stdlib.h>
#include <string.h>
#include <string>
#include "commandlineflags.h"
#include "commontraining.h" // CheckSharedLibraryVersion
#include "tprintf.h"
#include "unicharset_training_utils.h"
@ -30,6 +27,7 @@ DECLARE_STRING_PARAM_FLAG(O);
DECLARE_STRING_PARAM_FLAG(X);
int main(int argc, char** argv) {
tesseract::CheckSharedLibraryVersion();
tesseract::ParseCommandLineFlags(argv[0], &argc, &argv, true);
// Check validity of input flags.

View File

@ -45,6 +45,8 @@ STRING_PARAM_FLAG(canonical_class2, "", "Class to show ambigs for");
// Otherwise, if FLAGS_canonical_class1 is set, prints a table of font-wise
// cluster distances between FLAGS_canonical_class1 and FLAGS_canonical_class2.
int main(int argc, char **argv) {
tesseract::CheckSharedLibraryVersion();
ParseArguments(&argc, &argv);
STRING file_prefix;

View File

@ -40,6 +40,7 @@
#include "allheaders.h" // from leptonica
#include "boxchar.h"
#include "commandlineflags.h"
#include "commontraining.h" // CheckSharedLibraryVersion
#include "degradeimage.h"
#include "errcode.h"
#include "fileio.h"
@ -412,7 +413,7 @@ using tesseract::SpanUTF8NotWhitespace;
using tesseract::SpanUTF8Whitespace;
using tesseract::StringRenderer;
int Main() {
static int Main() {
if (FLAGS_list_available_fonts) {
const std::vector<std::string>& all_fonts = FontUtils::ListAvailableFonts();
for (unsigned int i = 0; i < all_fonts.size(); ++i) {
@ -672,6 +673,7 @@ int Main() {
}
int main(int argc, char** argv) {
tesseract::CheckSharedLibraryVersion();
tesseract::ParseCommandLineFlags(argv[0], &argc, &argv, true);
Main();
return Main();
}

View File

@ -24,11 +24,11 @@
#include <cstdlib>
#include "boxread.h"
#include "commandlineflags.h"
#include "commontraining.h" // CheckSharedLibraryVersion
#include "genericvector.h"
#include "lang_model_helpers.h"
#include "normstrngs.h"
#include "strngs.h"
#include "tprintf.h"
#include "unicharset.h"
#include "unicharset_training_utils.h"
@ -61,7 +61,7 @@ static void AddStringsToUnicharset(const GenericVector<STRING>& strings,
}
}
int Main(int argc, char** argv) {
static int Main(int argc, char** argv) {
UNICHARSET unicharset;
// Load input files
for (int arg = 1; arg < argc; ++arg) {
@ -95,6 +95,7 @@ int Main(int argc, char** argv) {
} // namespace tesseract
int main(int argc, char** argv) {
tesseract::CheckSharedLibraryVersion();
if (argc > 1) {
tesseract::ParseCommandLineFlags(argv[0], &argc, &argv, true);
}

View File

@ -20,9 +20,8 @@
// Given a file that contains a list of words (one word per line) this program
// generates the corresponding squished DAWG file.
#include <stdio.h>
#include "classify.h"
#include "commontraining.h" // CheckSharedLibraryVersion
#include "dawg.h"
#include "dict.h"
#include "emalloc.h"
@ -32,6 +31,8 @@
#include "unicharset.h"
int main(int argc, char** argv) {
tesseract::CheckSharedLibraryVersion();
if (!(argc == 4 || (argc == 5 && strcmp(argv[1], "-t") == 0) ||
(argc == 6 && strcmp(argv[1], "-r") == 0))) {
printf("Usage: %s [-t | -r [reverse policy] ] word_list_file"