Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Member Functions | Static Protected Attributes
tesseract::FeatureChebyshev Class Reference

`#include <feature_chebyshev.h>`

Inheritance diagram for tesseract::FeatureChebyshev:

List of all members.

## Public Member Functions

| FeatureChebyshev (TuningParams *params)
virtual | ~FeatureChebyshev ()
virtual CharSamp * | ComputeFeatureBitmap (CharSamp *samp)
virtual bool | ComputeFeatures (CharSamp *samp, float *features)
virtual int | FeatureCnt ()
Public Member Functions inherited from tesseract::FeatureBase
| FeatureBase (TuningParams *params)
virtual | ~FeatureBase ()

## Protected Member Functions

void | ChebyshevCoefficients (const vector< float > &input, int coeff_cnt, float *coeff)
bool | ComputeChebyshevCoefficients (CharSamp *samp, float *features)

## Static Protected Attributes

static const int | kChebychevCoefficientCnt = 40

## Additional Inherited Members

Protected Attributes inherited from tesseract::FeatureBase
TuningParams * | params_

## Detailed Description

Definition at line 33 of file feature_chebyshev.h.

## Constructor & Destructor Documentation

tesseract::FeatureChebyshev::FeatureChebyshev | ( | TuningParams * | params | ) |

explicit

Definition at line 40 of file feature_chebyshev.cpp.

: FeatureBase(params) {
}

tesseract::FeatureChebyshev::~FeatureChebyshev | ( |  | ) |

virtual

Definition at line 44 of file feature_chebyshev.cpp.

{
}

## Member Function Documentation

void tesseract::FeatureChebyshev::ChebyshevCoefficients | ( | const vector< float > & | input,
|  | int | coeff_cnt,
|  | float * | coeff
| ) |  |

protected

Definition at line 54 of file feature_chebyshev.cpp.

{
// re-sample function
int input_range = (input.size() - 1);
vector<float> resamp(coeff_cnt);
for (int samp_idx = 0; samp_idx < coeff_cnt; samp_idx++) {
// compute sampling position
float samp_pos = input_range *
(1 + cos(M_PI * (samp_idx + 0.5) / coeff_cnt)) / 2;
// interpolate
int samp_start = static_cast<int>(samp_pos);
int samp_end = static_cast<int>(samp_pos + 0.5);
float func_delta = input[samp_end] - input[samp_start];
resamp[samp_idx] = input[samp_start] +
((samp_pos - samp_start) * func_delta);
}
// compute the coefficients
float normalizer = 2.0 / coeff_cnt;
for (int coeff_idx = 0; coeff_idx < coeff_cnt; coeff_idx++, coeff++) {
double sum = 0.0;
for (int samp_idx = 0; samp_idx < coeff_cnt; samp_idx++) {
sum += resamp[samp_idx] * cos(M_PI * coeff_idx * (samp_idx + 0.5) /
coeff_cnt);
}
(*coeff) = (normalizer * sum);
}
}

bool tesseract::FeatureChebyshev::ComputeChebyshevCoefficients | ( | CharSamp * | samp,
|  | float * | features
| ) |  |

protected

Definition at line 88 of file feature_chebyshev.cpp.

{
if (char_samp->NormBottom() <= 0) {
return false;
}
unsigned char *raw_data = char_samp->RawData();
int stride = char_samp->Stride();
// compute the height of the word
int word_hgt = (255 * (char_samp->Top() + char_samp->Height()) /
char_samp->NormBottom());
// compute left & right profiles
vector<float> left_profile(word_hgt, 0.0);
vector<float> right_profile(word_hgt, 0.0);
unsigned char *line_data = raw_data;
for (int y = 0; y < char_samp->Height(); y++, line_data += stride) {
int min_x = char_samp->Width();
int max_x = -1;
for (int x = 0; x < char_samp->Width(); x++) {
if (line_data[x] == 0) {
UpdateRange(x, &min_x, &max_x);
}
}
left_profile[char_samp->Top() + y] =
1.0 * (min_x == char_samp->Width() ? 0 : (min_x + 1)) /
char_samp->Width();
right_profile[char_samp->Top() + y] =
1.0 * (max_x == -1 ? 0 : char_samp->Width() - max_x) /
char_samp->Width();
}
// compute top and bottom profiles
vector<float> top_profile(char_samp->Width(), 0);
vector<float> bottom_profile(char_samp->Width(), 0);
for (int x = 0; x < char_samp->Width(); x++) {
int min_y = word_hgt;
int max_y = -1;
line_data = raw_data;
for (int y = 0; y < char_samp->Height(); y++, line_data += stride) {
if (line_data[x] == 0) {
UpdateRange(y + char_samp->Top(), &min_y, &max_y);
}
}
top_profile[x] = 1.0 * (min_y == word_hgt ? 0 : (min_y + 1)) / word_hgt;
bottom_profile[x] = 1.0 * (max_y == -1 ? 0 : (word_hgt - max_y)) / word_hgt;
}
// compute the chebyshev coefficients of each profile
ChebyshevCoefficients(left_profile, kChebychevCoefficientCnt, features);
ChebyshevCoefficients(top_profile, kChebychevCoefficientCnt,
features + kChebychevCoefficientCnt);
ChebyshevCoefficients(right_profile, kChebychevCoefficientCnt,
features + (2 * kChebychevCoefficientCnt));
ChebyshevCoefficients(bottom_profile, kChebychevCoefficientCnt,
features + (3 * kChebychevCoefficientCnt));
return true;
}

CharSamp * tesseract::FeatureChebyshev::ComputeFeatureBitmap | ( | CharSamp * | samp | ) |

virtual

Implements tesseract::FeatureBase.

Definition at line 49 of file feature_chebyshev.cpp.

{
return char_samp;
}

bool tesseract::FeatureChebyshev::ComputeFeatures | ( | CharSamp * | samp,
|  | float * | features
| ) |  |

virtual

Implements tesseract::FeatureBase.

Definition at line 83 of file feature_chebyshev.cpp.

{
return ComputeChebyshevCoefficients(char_samp, features);
}

virtual int tesseract::FeatureChebyshev::FeatureCnt | ( |  | ) |

inline virtual

Implements tesseract::FeatureBase.

Definition at line 43 of file feature_chebyshev.h.

{
return (4 * kChebychevCoefficientCnt);
}

## Member Data Documentation

const int tesseract::FeatureChebyshev::kChebychevCoefficientCnt = 40

static protected

Definition at line 48 of file feature_chebyshev.h.

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

- /mnt/data/src/tesseract-ocr/cube/feature_chebyshev.h
- /mnt/data/src/tesseract-ocr/cube/feature_chebyshev.cpp