49 int coeff_cnt,
float *coeff) {
51 int input_range = (input.size() - 1);
52 vector<float> resamp(coeff_cnt);
53 for (
int samp_idx = 0; samp_idx < coeff_cnt; samp_idx++) {
55 float samp_pos = input_range *
56 (1 + cos(M_PI * (samp_idx + 0.5) / coeff_cnt)) / 2;
58 int samp_start =
static_cast<int>(samp_pos);
59 int samp_end =
static_cast<int>(samp_pos + 0.5);
60 float func_delta = input[samp_end] - input[samp_start];
61 resamp[samp_idx] = input[samp_start] +
62 ((samp_pos - samp_start) * func_delta);
65 float normalizer = 2.0 / coeff_cnt;
66 for (
int coeff_idx = 0; coeff_idx < coeff_cnt; coeff_idx++, coeff++) {
68 for (
int samp_idx = 0; samp_idx < coeff_cnt; samp_idx++) {
69 sum += resamp[samp_idx] * cos(M_PI * coeff_idx * (samp_idx + 0.5) /
72 (*coeff) = (normalizer * sum);
87 unsigned char *raw_data = char_samp->
RawData();
88 int stride = char_samp->
Stride();
90 int word_hgt = (255 * (char_samp->
Top() + char_samp->
Height()) /
93 vector<float> left_profile(word_hgt, 0.0);
94 vector<float> right_profile(word_hgt, 0.0);
95 unsigned char *line_data = raw_data;
96 for (
int y = 0; y < char_samp->
Height(); y++, line_data += stride) {
97 int min_x = char_samp->
Width();
99 for (
int x = 0; x < char_samp->
Width(); x++) {
100 if (line_data[x] == 0) {
104 left_profile[char_samp->
Top() + y] =
105 1.0 * (min_x == char_samp->
Width() ? 0 : (min_x + 1)) /
107 right_profile[char_samp->
Top() + y] =
108 1.0 * (max_x == -1 ? 0 : char_samp->
Width() - max_x) /
113 vector<float> top_profile(char_samp->
Width(), 0);
114 vector<float> bottom_profile(char_samp->
Width(), 0);
115 for (
int x = 0; x < char_samp->
Width(); x++) {
116 int min_y = word_hgt;
118 line_data = raw_data;
119 for (
int y = 0; y < char_samp->
Height(); y++, line_data += stride) {
120 if (line_data[x] == 0) {
124 top_profile[x] = 1.0 * (min_y == word_hgt ? 0 : (min_y + 1)) / word_hgt;
125 bottom_profile[x] = 1.0 * (max_y == -1 ? 0 : (word_hgt - max_y)) / word_hgt;
unsigned short Height() const
void UpdateRange(const T1 &x, T2 *lower_bound, T2 *upper_bound)
unsigned short Width() const
FeatureChebyshev(TuningParams *params)
unsigned short Top() const
static const int kChebychevCoefficientCnt
unsigned char * RawData() const
unsigned short NormBottom() const
unsigned short Stride() const
void ChebyshevCoefficients(const vector< float > &input, int coeff_cnt, float *coeff)
virtual CharSamp * ComputeFeatureBitmap(CharSamp *samp)
virtual ~FeatureChebyshev()
virtual bool ComputeFeatures(CharSamp *samp, float *features)
bool ComputeChebyshevCoefficients(CharSamp *samp, float *features)