tesseract  3.05.01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mftraining.cpp File Reference
#include <string.h>
#include <stdio.h>
#include <math.h>
#include "classify.h"
#include "cluster.h"
#include "clusttool.h"
#include "commontraining.h"
#include "danerror.h"
#include "efio.h"
#include "emalloc.h"
#include "featdefs.h"
#include "fontinfo.h"
#include "genericvector.h"
#include "indexmapbidi.h"
#include "intproto.h"
#include "mastertrainer.h"
#include "mergenf.h"
#include "mf.h"
#include "ndminx.h"
#include "ocrfeatures.h"
#include "oldlist.h"
#include "protos.h"
#include "shapetable.h"
#include "tessopt.h"
#include "tprintf.h"
#include "unicity_table.h"

Go to the source code of this file.

Macros

#define _USE_MATH_DEFINES
 
#define PROGRAM_FEATURE_TYPE   "mf"
 

Functions

 DECLARE_STRING_PARAM_FLAG (test_ch)
 
int main (int argc, char **argv)
 

Variables

const int kMaxShapeLabelLength = 10
 

Macro Definition Documentation

#define _USE_MATH_DEFINES

Definition at line 35 of file mftraining.cpp.

#define PROGRAM_FEATURE_TYPE   "mf"

Definition at line 72 of file mftraining.cpp.

Function Documentation

DECLARE_STRING_PARAM_FLAG ( test_ch  )
int main ( int  argc,
char **  argv 
)

This program reads in a text file consisting of feature samples from a training page in the following format:

   FontName UTF8-char-str xmin ymin xmax ymax page-number
    NumberOfFeatureTypes(N)
      FeatureTypeName1 NumberOfFeatures(M)
         Feature1
         ...
         FeatureM
      FeatureTypeName2 NumberOfFeatures(M)
         Feature1
         ...
         FeatureM
      ...
      FeatureTypeNameN NumberOfFeatures(M)
         Feature1
         ...
         FeatureM
   FontName CharName ...

The result of this program is a binary inttemp file used by the OCR engine.

Parameters
argcnumber of command line arguments
argvarray of command line arguments
Returns
none
Note
Exceptions: none
History: Fri Aug 18 08:56:17 1989, DSJ, Created.
History: Mon May 18 1998, Christy Russson, Revistion started.

Definition at line 388 of file tesseractmain.cpp.

388  {
389  const char* lang = "eng";
390  const char* image = NULL;
391  const char* outputbase = NULL;
392  const char* datapath = NULL;
393  bool list_langs = false;
394  bool print_parameters = false;
395  int arg_i = 1;
398  /* main() calls functions like ParseArgs which call exit().
399  * This results in memory leaks if vars_vec and vars_values are
400  * declared as auto variables (destructor is not called then). */
401  static GenericVector<STRING> vars_vec;
402  static GenericVector<STRING> vars_values;
403 
404 #ifdef NDEBUG
405  // Disable debugging and informational messages from Leptonica.
406  setMsgSeverity(L_SEVERITY_ERROR);
407 #endif
408 
409 #if defined(HAVE_TIFFIO_H) && defined(_WIN32)
410  /* Show libtiff warnings on console (not in GUI). */
411  TIFFSetWarningHandler(Win32WarningHandler);
412 #endif /* HAVE_TIFFIO_H && _WIN32 */
413 
414  ParseArgs(argc, argv, &lang, &image, &outputbase, &datapath, &list_langs,
415  &print_parameters, &vars_vec, &vars_values, &arg_i, &pagesegmode,
416  &enginemode);
417 
418  bool banner = false;
419  if (outputbase != NULL && strcmp(outputbase, "-") &&
420  strcmp(outputbase, "stdout")) {
421  banner = true;
422  }
423 
424  PERF_COUNT_START("Tesseract:main")
425 
426  // Call GlobalDawgCache here to create the global DawgCache object before
427  // the TessBaseAPI object. This fixes the order of destructor calls:
428  // first TessBaseAPI must be destructed, DawgCache must be the last object.
429  tesseract::Dict::GlobalDawgCache();
430 
431  // Avoid memory leak caused by auto variable when exit() is called.
432  static tesseract::TessBaseAPI api;
433 
434  api.SetOutputName(outputbase);
435 
436  int init_failed = api.Init(datapath, lang, enginemode, &(argv[arg_i]),
437  argc - arg_i, &vars_vec, &vars_values, false);
438  if (init_failed) {
439  fprintf(stderr, "Could not initialize tesseract.\n");
440  return EXIT_FAILURE;
441  }
442 
443  SetVariablesFromCLArgs(&api, argc, argv);
444 
445  if (list_langs) {
447  return EXIT_SUCCESS;
448  }
449 
450  if (print_parameters) {
451  FILE* fout = stdout;
452  fprintf(stdout, "Tesseract parameters:\n");
453  api.PrintVariables(fout);
454  api.End();
455  return EXIT_SUCCESS;
456  }
457 
458  FixPageSegMode(&api, pagesegmode);
459 
460  if (pagesegmode == tesseract::PSM_AUTO_ONLY) {
461  int ret_val = EXIT_SUCCESS;
462 
463  Pix* pixs = pixRead(image);
464  if (!pixs) {
465  fprintf(stderr, "Cannot open input file: %s\n", image);
466  return 2;
467  }
468 
469  api.SetImage(pixs);
470 
471  tesseract::Orientation orientation;
474  float deskew_angle;
475 
476  tesseract::PageIterator* it = api.AnalyseLayout();
477  if (it) {
478  it->Orientation(&orientation, &direction, &order, &deskew_angle);
479  tprintf(
480  "Orientation: %d\nWritingDirection: %d\nTextlineOrder: %d\n"
481  "Deskew angle: %.4f\n",
482  orientation, direction, order, deskew_angle);
483  } else {
484  ret_val = EXIT_FAILURE;
485  }
486 
487  delete it;
488 
489  pixDestroy(&pixs);
490  return ret_val;
491  }
492 
493  // set in_training_mode to true when using one of these configs:
494  // ambigs.train, box.train, box.train.stderr, linebox, rebox
495  bool b = false;
496  bool in_training_mode =
497  (api.GetBoolVariable("tessedit_ambigs_training", &b) && b) ||
498  (api.GetBoolVariable("tessedit_resegment_from_boxes", &b) && b) ||
499  (api.GetBoolVariable("tessedit_make_boxes_from_boxes", &b) && b);
500 
501  // Avoid memory leak caused by auto variable when exit() is called.
503 
504  if (in_training_mode) {
505  renderers.push_back(NULL);
506  } else {
507  PreloadRenderers(&api, &renderers, pagesegmode, outputbase);
508  }
509 
510  if (!renderers.empty()) {
511  if (banner) PrintBanner();
512  bool succeed = api.ProcessPages(image, NULL, 0, renderers[0]);
513  if (!succeed) {
514  fprintf(stderr, "Error during processing.\n");
515  return EXIT_FAILURE;
516  }
517  }
518 
520 
521  return EXIT_SUCCESS;
522 }
void PrintLangsList(tesseract::TessBaseAPI *api)
void SetVariablesFromCLArgs(tesseract::TessBaseAPI *api, int argc, char **argv)
struct TessBaseAPI TessBaseAPI
Definition: capi.h:86
void PreloadRenderers(tesseract::TessBaseAPI *api, tesseract::PointerVector< tesseract::TessResultRenderer > *renderers, tesseract::PageSegMode pagesegmode, const char *outputbase)
#define PERF_COUNT_END
bool empty() const
Definition: genericvector.h:84
void PrintBanner()
#define tprintf(...)
Definition: tprintf.h:31
void ParseArgs(const int argc, char **argv, const char **lang, const char **image, const char **outputbase, const char **datapath, bool *list_langs, bool *print_parameters, GenericVector< STRING > *vars_vec, GenericVector< STRING > *vars_values, int *arg_i, tesseract::PageSegMode *pagesegmode, tesseract::OcrEngineMode *enginemode)
int direction(EDGEPT *point)
Definition: vecfuncs.cpp:43
#define PERF_COUNT_START(FUNCT_NAME)
Automatic page segmentation, but no OSD, or OCR.
Definition: publictypes.h:155
int push_back(T *object)
void Orientation(tesseract::Orientation *orientation, tesseract::WritingDirection *writing_direction, tesseract::TextlineOrder *textline_order, float *deskew_angle) const
void FixPageSegMode(tesseract::TessBaseAPI *api, tesseract::PageSegMode pagesegmode)
if(OldChiSquared==NULL)
Definition: cluster.cpp:1897
Fully automatic page segmentation, but no OSD.
Definition: publictypes.h:156

Variable Documentation

const int kMaxShapeLabelLength = 10

Definition at line 75 of file mftraining.cpp.