tesseract  4.0.0-1-g2a2b
tesseract::IntFeatureDist Class Reference

#include <intfeaturedist.h>

Public Member Functions

 IntFeatureDist ()
 
 ~IntFeatureDist ()
 
void Init (const IntFeatureMap *feature_map)
 
void Set (const GenericVector< int > &indexed_features, int canonical_count, bool value)
 
double FeatureDistance (const GenericVector< int > &features) const
 
double DebugFeatureDistance (const GenericVector< int > &features) const
 

Detailed Description

Definition at line 39 of file intfeaturedist.h.

Constructor & Destructor Documentation

◆ IntFeatureDist()

tesseract::IntFeatureDist::IntFeatureDist ( )

Definition at line 25 of file intfeaturedist.cpp.

26  : size_(0), total_feature_weight_(0.0),
27  feature_map_(nullptr), features_(nullptr),
28  features_delta_one_(nullptr), features_delta_two_(nullptr) {
29 }

◆ ~IntFeatureDist()

tesseract::IntFeatureDist::~IntFeatureDist ( )

Definition at line 31 of file intfeaturedist.cpp.

31  {
32  Clear();
33 }

Member Function Documentation

◆ DebugFeatureDistance()

double tesseract::IntFeatureDist::DebugFeatureDistance ( const GenericVector< int > &  features) const

Definition at line 98 of file intfeaturedist.cpp.

99  {
100  const int num_test_features = features.size();
101  const double denominator = total_feature_weight_ + num_test_features;
102  double misses = denominator;
103  for (int i = 0; i < num_test_features; ++i) {
104  const int index = features[i];
105  const double weight = 1.0;
106  INT_FEATURE_STRUCT f = feature_map_->InverseMapFeature(features[i]);
107  tprintf("Testing feature weight %g:", weight);
108  f.print();
109  if (features_[index]) {
110  // A perfect match.
111  misses -= 2.0 * weight;
112  tprintf("Perfect hit\n");
113  } else if (features_delta_one_[index]) {
114  misses -= 1.5 * weight;
115  tprintf("-1 hit\n");
116  } else if (features_delta_two_[index]) {
117  // A near miss.
118  misses -= 1.0 * weight;
119  tprintf("-2 hit\n");
120  } else {
121  tprintf("Total miss\n");
122  }
123  }
124  tprintf("Features present:");
125  for (int i = 0; i < size_; ++i) {
126  if (features_[i]) {
127  INT_FEATURE_STRUCT f = feature_map_->InverseMapFeature(i);
128  f.print();
129  }
130  }
131  tprintf("\nMinus one features:");
132  for (int i = 0; i < size_; ++i) {
133  if (features_delta_one_[i]) {
134  INT_FEATURE_STRUCT f = feature_map_->InverseMapFeature(i);
135  f.print();
136  }
137  }
138  tprintf("\nMinus two features:");
139  for (int i = 0; i < size_; ++i) {
140  if (features_delta_two_[i]) {
141  INT_FEATURE_STRUCT f = feature_map_->InverseMapFeature(i);
142  f.print();
143  }
144  }
145  tprintf("\n");
146  return misses / denominator;
147 }
int size() const
Definition: genericvector.h:71
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
void print() const
Definition: intproto.h:145
INT_FEATURE_STRUCT InverseMapFeature(int map_feature) const

◆ FeatureDistance()

double tesseract::IntFeatureDist::FeatureDistance ( const GenericVector< int > &  features) const

Definition at line 75 of file intfeaturedist.cpp.

76  {
77  const int num_test_features = features.size();
78  const double denominator = total_feature_weight_ + num_test_features;
79  double misses = denominator;
80  for (int i = 0; i < num_test_features; ++i) {
81  const int index = features[i];
82  const double weight = 1.0;
83  if (features_[index]) {
84  // A perfect match.
85  misses -= 2.0 * weight;
86  } else if (features_delta_one_[index]) {
87  misses -= 1.5 * weight;
88  } else if (features_delta_two_[index]) {
89  // A near miss.
90  misses -= 1.0 * weight;
91  }
92  }
93  return misses / denominator;
94 }
int size() const
Definition: genericvector.h:71

◆ Init()

void tesseract::IntFeatureDist::Init ( const IntFeatureMap feature_map)

Definition at line 36 of file intfeaturedist.cpp.

36  {
37  size_ = feature_map->sparse_size();
38  Clear();
39  feature_map_ = feature_map;
40  features_ = new bool[size_];
41  features_delta_one_ = new bool[size_];
42  features_delta_two_ = new bool[size_];
43  memset(features_, false, size_ * sizeof(features_[0]));
44  memset(features_delta_one_, false, size_ * sizeof(features_delta_one_[0]));
45  memset(features_delta_two_, false, size_ * sizeof(features_delta_two_[0]));
46  total_feature_weight_ = 0.0;
47 }

◆ Set()

void tesseract::IntFeatureDist::Set ( const GenericVector< int > &  indexed_features,
int  canonical_count,
bool  value 
)

Definition at line 51 of file intfeaturedist.cpp.

52  {
53  total_feature_weight_ = canonical_count;
54  for (int i = 0; i < indexed_features.size(); ++i) {
55  const int f = indexed_features[i];
56  features_[f] = value;
57  for (int dir = -kNumOffsetMaps; dir <= kNumOffsetMaps; ++dir) {
58  if (dir == 0) continue;
59  const int mapped_f = feature_map_->OffsetFeature(f, dir);
60  if (mapped_f >= 0) {
61  features_delta_one_[mapped_f] = value;
62  for (int dir2 = -kNumOffsetMaps; dir2 <= kNumOffsetMaps; ++dir2) {
63  if (dir2 == 0) continue;
64  const int mapped_f2 = feature_map_->OffsetFeature(mapped_f, dir2);
65  if (mapped_f2 >= 0)
66  features_delta_two_[mapped_f2] = value;
67  }
68  }
69  }
70  }
71 }
int size() const
Definition: genericvector.h:71
int OffsetFeature(int index_feature, int dir) const

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