|
tesseract 3.04.01
|
#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.
Defines | |
| #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 |
| #define _USE_MATH_DEFINES |
Definition at line 35 of file mftraining.cpp.
| #define PROGRAM_FEATURE_TYPE "mf" |
Definition at line 75 of file mftraining.cpp.
| 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.
| argc | number of command line arguments |
| argv | array of command line arguments |
Definition at line 338 of file tesseractmain.cpp.
{
const char* lang = "eng";
const char* image = NULL;
const char* outputbase = NULL;
const char* datapath = NULL;
bool list_langs = false;
bool print_parameters = false;
GenericVector<STRING> vars_vec, vars_values;
int arg_i = 1;
tesseract::PageSegMode pagesegmode = tesseract::PSM_AUTO;
ParseArgs(argc, argv,
&lang, &image, &outputbase, &datapath,
&list_langs, &print_parameters,
&vars_vec, &vars_values, &arg_i, &pagesegmode);
PERF_COUNT_START("Tesseract:main")
tesseract::TessBaseAPI api;
api.SetOutputName(outputbase);
int init_failed = api.Init(datapath, lang, tesseract::OEM_DEFAULT,
&(argv[arg_i]), argc - arg_i, &vars_vec, &vars_values, false);
if (init_failed) {
fprintf(stderr, "Could not initialize tesseract.\n");
exit(1);
}
SetVariablesFromCLArgs(&api, argc, argv);
if (list_langs) {
PrintLangsList(&api);
exit(0);
}
if (print_parameters) {
FILE* fout = stdout;
fprintf(stdout, "Tesseract parameters:\n");
api.PrintVariables(fout);
api.End();
exit(0);
}
FixPageSegMode(&api, pagesegmode);
if (pagesegmode == tesseract::PSM_AUTO_ONLY) {
int ret_val = 0;
Pix* pixs = pixRead(image);
if (!pixs) {
fprintf(stderr, "Cannot open input file: %s\n", image);
exit(2);
}
api.SetImage(pixs);
tesseract::Orientation orientation;
tesseract::WritingDirection direction;
tesseract::TextlineOrder order;
float deskew_angle;
tesseract::PageIterator* it = api.AnalyseLayout();
if (it) {
it->Orientation(&orientation, &direction, &order, &deskew_angle);
tprintf("Orientation: %d\nWritingDirection: %d\nTextlineOrder: %d\n" \
"Deskew angle: %.4f\n",
orientation, direction, order, deskew_angle);
} else {
ret_val = 1;
}
delete it;
pixDestroy(&pixs);
exit(ret_val);
}
// set in_training_mode to true when using one of these configs:
// ambigs.train, box.train, box.train.stderr, linebox, rebox
bool b = false;
bool in_training_mode =
(api.GetBoolVariable("tessedit_ambigs_training", &b) && b) ||
(api.GetBoolVariable("tessedit_resegment_from_boxes", &b) && b) ||
(api.GetBoolVariable("tessedit_make_boxes_from_boxes", &b) && b);
tesseract::PointerVector<tesseract::TessResultRenderer> renderers;
if (in_training_mode) {
renderers.push_back(NULL);
} else {
PreloadRenderers(&api, &renderers, pagesegmode, outputbase);
}
if (!renderers.empty()) {
bool succeed = api.ProcessPages(image, NULL, 0, renderers[0]);
if (!succeed) {
fprintf(stderr, "Error during processing.\n");
exit(1);
}
}
PERF_COUNT_END
return 0; // Normal exit
}
| const int kMaxShapeLabelLength = 10 |
Definition at line 78 of file mftraining.cpp.