Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tesseract::ErrorCounter Class Reference

#include <errorcounter.h>

Static Public Member Functions

static double ComputeErrorRate (ShapeClassifier *classifier, int report_level, CountTypes boosting_mode, const UnicityTable< FontInfo > &fontinfo_table, const GenericVector< Pix * > &page_images, SampleIterator *it, double *unichar_error, double *scaled_error, STRING *fonts_report)
 

Detailed Description

Definition at line 88 of file errorcounter.h.

Member Function Documentation

double tesseract::ErrorCounter::ComputeErrorRate ( ShapeClassifier classifier,
int  report_level,
CountTypes  boosting_mode,
const UnicityTable< FontInfo > &  fontinfo_table,
const GenericVector< Pix * > &  page_images,
SampleIterator it,
double *  unichar_error,
double *  scaled_error,
STRING fonts_report 
)
static

Definition at line 36 of file errorcounter.cpp.

40  {
41  int charsetsize = it->shape_table()->unicharset().size();
42  int shapesize = it->CompactCharsetSize();
43  int fontsize = it->sample_set()->NumFonts();
44  ErrorCounter counter(charsetsize, shapesize, fontsize);
46 
47  clock_t start = clock();
48  int total_samples = 0;
49  double unscaled_error = 0.0;
50  // Set a number of samples on which to run the classify debug mode.
51  int error_samples = report_level > 3 ? report_level * report_level : 0;
52  // Iterate over all the samples, accumulating errors.
53  for (it->Begin(); !it->AtEnd(); it->Next()) {
54  TrainingSample* mutable_sample = it->MutableSample();
55  int page_index = mutable_sample->page_num();
56  Pix* page_pix = 0 <= page_index && page_index < page_images.size()
57  ? page_images[page_index] : NULL;
58  // No debug, no keep this.
59  classifier->ClassifySample(*mutable_sample, page_pix, 0, INVALID_UNICHAR_ID,
60  &results);
61  if (mutable_sample->class_id() == 0) {
62  // This is junk so use the special counter.
63  counter.AccumulateJunk(*it->shape_table(), results, mutable_sample);
64  } else if (counter.AccumulateErrors(report_level > 3, boosting_mode,
65  fontinfo_table, *it->shape_table(),
66  results, mutable_sample) &&
67  error_samples > 0) {
68  // Running debug, keep the correct answer, and debug the classifier.
69  tprintf("Error on sample %d: Classifier debug output:\n",
70  it->GlobalSampleIndex());
71  int keep_this = it->GetSparseClassID();
72  classifier->ClassifySample(*mutable_sample, page_pix, 1, keep_this,
73  &results);
74  --error_samples;
75  }
76  ++total_samples;
77  }
78  double total_time = 1.0 * (clock() - start) / CLOCKS_PER_SEC;
79  // Create the appropriate error report.
80  unscaled_error = counter.ReportErrors(report_level, boosting_mode,
81  fontinfo_table,
82  *it, unichar_error, fonts_report);
83  if (scaled_error != NULL) *scaled_error = counter.scaled_error_;
84  if (report_level > 1) {
85  // It is useful to know the time in microseconds/char.
86  tprintf("Errors computed in %.2fs at %.1f μs/char\n",
87  total_time, 1000000.0 * total_time / total_samples);
88  }
89  return unscaled_error;
90 }
#define NULL
Definition: host.h:144
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
int size() const
Definition: genericvector.h:59

The documentation for this class was generated from the following files: