CHAR_SAMPLE Class Reference

#include <charsample.h>

Inheritance diagram for CHAR_SAMPLE:

ELIST_LINK List of all members.

Detailed Description

Class manages character sample and match scores, used during adaption.

Definition at line 56 of file charsample.h.

Public Member Functions

Public Attributes


Constructor & Destructor Documentation

CHAR_SAMPLE::CHAR_SAMPLE (  ) 

CHAR_SAMPLE::CHAR_SAMPLE ( PBLOB blob,
DENORM denorm,
char  c 
)

Definition at line 55 of file charsample.cpp.

References blob(), ch, denorm(), n_samples_matched, NULL, sample_blob, sample_denorm, sumsq_match_scores, and total_match_scores.

00055                                                             { 
00056   sample_blob = blob;
00057   sample_denorm = denorm;
00058   sample_image = NULL;
00059   ch = c;
00060   n_samples_matched = 0;
00061   total_match_scores = 0.0;
00062   sumsq_match_scores = 0.0;
00063 }

CHAR_SAMPLE::CHAR_SAMPLE ( IMAGE image,
char  c 
)

Definition at line 66 of file charsample.cpp.

References ch, image(), n_samples_matched, NULL, sample_blob, sample_denorm, sumsq_match_scores, and total_match_scores.

00066                                              { 
00067   sample_blob = NULL;
00068   sample_denorm = NULL;
00069   sample_image = image;
00070   ch = c;
00071   n_samples_matched = 0;
00072   total_match_scores = 0.0;
00073   sumsq_match_scores = 0.0;
00074 }

CHAR_SAMPLE::~CHAR_SAMPLE (  )  [inline]

Definition at line 70 of file charsample.h.

References NULL.

00070                     {
00071       // We own the image, so it has to be deleted.
00072       if (sample_image != NULL)
00073         delete sample_image;
00074     }


Member Function Documentation

PBLOB* CHAR_SAMPLE::blob (  )  [inline]

Definition at line 86 of file charsample.h.

References sample_blob.

Referenced by apply_seam(), attempt_blob_chop(), CHAR_SAMPLE(), CHAR_SAMPLES::CHAR_SAMPLES(), check_blob(), check_seam_order(), choose_best_seam(), chop_word_main(), constrained_split(), divide_blobs(), form_two_blobs(), improve_one_blob(), make_double_split(), make_split_blobs(), make_triple_split(), match_sample(), pick_good_seam(), start_seam_list(), try_point_pairs(), try_vertical_splits(), undo_seam(), and undo_single_split().

00086                   {
00087       return sample_blob;
00088     }

char CHAR_SAMPLE::character (  )  [inline]

Definition at line 98 of file charsample.h.

References ch.

Referenced by adapt_to_good_ems(), CHAR_PROTO::CHAR_PROTO(), CHAR_SAMPLES::CHAR_SAMPLES(), and CHAR_SAMPLES::match_score().

00098                      {
00099       return ch;
00100     }

void ELIST_LINK::de_serialise_asc ( FILE *  f  )  [inherited]

Reimplemented in ICOORDELT.

Definition at line 39 of file elst.cpp.

References ABORT, ERRCODE::error(), and SERIALISE_LINKS.

00040                                            {
00041   SERIALISE_LINKS.error ("ELIST_LINK::de_serialise_asc", ABORT,
00042     "Don't call this, override!");
00043 }

DENORM* CHAR_SAMPLE::denorm (  )  [inline]

Definition at line 90 of file charsample.h.

References sample_denorm.

Referenced by CHAR_SAMPLE(), and match_sample().

00090                      {
00091       return sample_denorm;
00092     }

IMAGE* CHAR_SAMPLE::image (  )  [inline]

Definition at line 82 of file charsample.h.

Referenced by CHAR_PROTO::add_sample(), CHAR_SAMPLES::add_sample_to_prototype(), CHAR_SAMPLES::build_prototype(), CHAR_PROTO::CHAR_PROTO(), CHAR_SAMPLE(), CHAR_SAMPLES::CHAR_SAMPLES(), CHAR_PROTO::match_sample(), and match_sample().

00082                    {
00083       return sample_image;
00084     }

float CHAR_SAMPLE::match_sample ( CHAR_SAMPLE test_sample,
BOOL8  updating 
)

Compare test_sample with sample_image and return degree of match (match score).

Parameters:
test_sample 
updating 
Note:
Global: sample_image
Returns:
score

Definition at line 85 of file charsample.cpp.

References BAD_SCORE, blob(), compare_bln_blobs(), denorm(), image(), matrix_match(), n_samples_matched, NULL, sample_blob, sample_denorm, sumsq_match_scores, and total_match_scores.

Referenced by CHAR_SAMPLES::add_sample(), check_wait_list(), and CHAR_SAMPLES::match_score().

00087                                                 {
00088   float score1;
00089   float score2;
00090   IMAGE *image = test_sample->image ();
00091 
00092   if (sample_blob != NULL && test_sample->blob () != NULL) {
00093     PBLOB *blob = test_sample->blob ();
00094     DENORM *denorm = test_sample->denorm ();
00095 
00096     score1 = compare_bln_blobs (sample_blob, sample_denorm, blob, denorm);
00097     score2 = compare_bln_blobs (blob, denorm, sample_blob, sample_denorm);
00098 
00099     score1 = (score1 > score2) ? score1 : score2;
00100   }
00101   else if (sample_image != NULL && image != NULL) {
00102     CHAR_PROTO *sample = new CHAR_PROTO (this);
00103 
00104     score1 = matrix_match (sample_image, image);
00105     delete sample;
00106   }
00107   else
00108     return BAD_SCORE;
00109 
00110   if ((tessedit_use_best_sample || tessedit_cluster_debug) && updating) {
00111     n_samples_matched++;
00112     total_match_scores += score1;
00113     sumsq_match_scores += score1 * score1;
00114   }
00115   return score1;
00116 }

double CHAR_SAMPLE::mean_score (  ) 

compute score

Note:
Global:
See also:
total_match_scores and

n_samples_matched

Parameters:
none 
Returns:
score or BAD_SCORE

Definition at line 126 of file charsample.cpp.

References BAD_SCORE, n_samples_matched, and total_match_scores.

Referenced by print(), and variance().

00126                                { 
00127   if (n_samples_matched > 0)
00128     return (total_match_scores / n_samples_matched);
00129   else
00130     return BAD_SCORE;
00131 }

INT32 CHAR_SAMPLE::n_matches (  )  [inline]

Definition at line 78 of file charsample.h.

References n_samples_matched.

00078                       {
00079       return n_samples_matched;
00080     }

void CHAR_SAMPLE::print ( FILE *  f  ) 

Definition at line 149 of file charsample.cpp.

References ch, INT32FORMAT, mean_score(), n_samples_matched, and variance().

Referenced by CHAR_SAMPLES::find_best_sample().

00149                                { 
00150   if (!tessedit_cluster_debug)
00151     return;
00152 
00153   if (n_samples_matched > 0)
00154     fprintf (f,
00155       "%c - sample matched against " INT32FORMAT
00156       " blobs, mean: %f, var: %f\n", ch, n_samples_matched,
00157       mean_score (), variance ());
00158   else
00159     fprintf (f, "No matches for this sample (%c)\n", ch);
00160 }

void CHAR_SAMPLE::reset_match_statistics (  ) 

Definition at line 165 of file charsample.cpp.

References n_samples_matched, sumsq_match_scores, and total_match_scores.

00165                                          { 
00166   n_samples_matched = 0;
00167   total_match_scores = 0.0;
00168   sumsq_match_scores = 0.0;
00169 }

void ELIST_LINK::serialise_asc ( FILE *  f  )  [inherited]

Generates an error, as it should never be called.

Definition at line 32 of file elst.cpp.

References ABORT, ERRCODE::error(), and SERIALISE_LINKS.

00033                                         {
00034   SERIALISE_LINKS.error ("ELIST_LINK::serialise_asc", ABORT,
00035     "Don't call this, override!");
00036 }

double CHAR_SAMPLE::variance (  ) 

Definition at line 136 of file charsample.cpp.

References BAD_SCORE, mean_score(), n_samples_matched, and sumsq_match_scores.

Referenced by print().

00136                              { 
00137   double mean = mean_score ();
00138 
00139   if (n_samples_matched > 0) {
00140     return (sumsq_match_scores / n_samples_matched) - mean * mean;
00141   }
00142   else
00143     return BAD_SCORE;
00144 }


Member Data Documentation

char CHAR_SAMPLE::ch

Definition at line 113 of file charsample.h.

Referenced by CHAR_SAMPLE(), character(), and print().

INT32 CHAR_SAMPLE::n_samples_matched

Definition at line 110 of file charsample.h.

Referenced by CHAR_SAMPLE(), match_sample(), mean_score(), n_matches(), print(), reset_match_statistics(), and variance().

NEWDELETE2 (CHAR_SAMPLE) private PBLOB* CHAR_SAMPLE::sample_blob

Definition at line 106 of file charsample.h.

Referenced by blob(), CHAR_SAMPLE(), and match_sample().

DENORM* CHAR_SAMPLE::sample_denorm

Definition at line 109 of file charsample.h.

Referenced by CHAR_SAMPLE(), denorm(), and match_sample().

double CHAR_SAMPLE::sumsq_match_scores

Definition at line 112 of file charsample.h.

Referenced by CHAR_SAMPLE(), match_sample(), reset_match_statistics(), and variance().

double CHAR_SAMPLE::total_match_scores

Definition at line 111 of file charsample.h.

Referenced by CHAR_SAMPLE(), match_sample(), mean_score(), and reset_match_statistics().


The documentation for this class was generated from the following files:
Generated on Wed Feb 28 19:49:30 2007 for Tesseract by  doxygen 1.5.1