tesseract v5.3.3.20231005
tesseract::LocalCorrelation Class Reference

Classes

struct  float_pair
 

Public Member Functions

 LocalCorrelation ()
 
 ~LocalCorrelation ()=default
 
void Finish ()
 
void Clear ()
 
void Add (float x, float y, int v)
 
float EstimateYFor (float x, float r)
 

Detailed Description

Definition at line 111 of file cjkpitch.cpp.

Constructor & Destructor Documentation

◆ LocalCorrelation()

tesseract::LocalCorrelation::LocalCorrelation ( )
inline

Definition at line 118 of file cjkpitch.cpp.

118: finalized_(false) {}

◆ ~LocalCorrelation()

tesseract::LocalCorrelation::~LocalCorrelation ( )
default

Member Function Documentation

◆ Add()

void tesseract::LocalCorrelation::Add ( float  x,
float  y,
int  v 
)
inline

Definition at line 130 of file cjkpitch.cpp.

130 {
131 struct float_pair value;
132 value.x = x;
133 value.y = y;
134 value.vote = v;
135 values_.push_back(value);
136 finalized_ = false;
137 }
int value
const double y

◆ Clear()

void tesseract::LocalCorrelation::Clear ( )
inline

Definition at line 126 of file cjkpitch.cpp.

126 {
127 finalized_ = false;
128 }

◆ EstimateYFor()

float tesseract::LocalCorrelation::EstimateYFor ( float  x,
float  r 
)
inline

Definition at line 139 of file cjkpitch.cpp.

139 {
140 ASSERT_HOST(finalized_);
141 unsigned start = 0, end = values_.size();
142 // Because the number of samples (used_) is assumed to be small,
143 // just use linear search to find values within the range.
144 while (start < values_.size() && values_[start].x < x * (1 - r)) {
145 start++;
146 }
147 while (end > 0 && values_[end - 1].x > x * (1 + r)) {
148 end--;
149 }
150
151 // Fall back to the global average if there are no data within r
152 // of x.
153 if (start >= end) {
154 start = 0;
155 end = values_.size();
156 }
157
158 // Compute weighted average of the values.
159 float rc = 0;
160 int vote = 0;
161 for (auto i = start; i < end; i++) {
162 rc += values_[i].vote * x * values_[i].y / values_[i].x;
163 vote += values_[i].vote;
164 }
165
166 return vote == 0 ? 0.0f : rc / vote;
167 }
#define ASSERT_HOST(x)
Definition: errcode.h:54

◆ Finish()

void tesseract::LocalCorrelation::Finish ( )
inline

Definition at line 121 of file cjkpitch.cpp.

121 {
122 std::sort(values_.begin(), values_.end(), float_pair_compare);
123 finalized_ = true;
124 }

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