MCPcopy Create free account
hub / github.com/creatale/node-dv / ComputeOffsetFeature

Method ComputeOffsetFeature

deps/tesseract/classify/intfeaturemap.cpp:201–242  ·  view source on GitHub ↗

Helper to compute an offset index feature. In this context an offset feature with a dir of +/-1 is a feature of a similar direction, but shifted perpendicular to the direction of the feature. An offset feature with a dir of +/-2 is feature at the same position, but rotated by +/- one [compact] quantum. Returns the index of the generated offset feature, or -1 if it doesn't exist. Dir should be in [

Source from the content-addressed store, hash-verified

199// distance moved from the input to guarantee that it maps to the next
200// available quantum in the mapped/compact space.
201int IntFeatureMap::ComputeOffsetFeature(int index_feature, int dir) const {
202 INT_FEATURE_STRUCT f = InverseIndexFeature(index_feature);
203 ASSERT_HOST(IndexFeature(f) == index_feature);
204 if (dir == 0) {
205 return index_feature;
206 } else if (dir == 1 || dir == -1) {
207 FCOORD feature_dir = FeatureDirection(f.Theta);
208 FCOORD rotation90(0.0f, 1.0f);
209 feature_dir.rotate(rotation90);
210 // Find the nearest existing feature.
211 for (int m = 1; m < kMaxOffsetDist; ++m) {
212 double x_pos = f.X + feature_dir.x() * (m * dir);
213 double y_pos = f.Y + feature_dir.y() * (m * dir);
214 int x = IntCastRounded(x_pos);
215 int y = IntCastRounded(y_pos);
216 if (x >= 0 && x <= MAX_UINT8 && y >= 0 && y <= MAX_UINT8) {
217 INT_FEATURE_STRUCT offset_f;
218 offset_f.X = x;
219 offset_f.Y = y;
220 offset_f.Theta = f.Theta;
221 int offset_index = IndexFeature(offset_f);
222 if (offset_index != index_feature && offset_index >= 0)
223 return offset_index; // Found one.
224 } else {
225 return -1; // Hit the edge of feature space.
226 }
227 }
228 } else if (dir == 2 || dir == -2) {
229 // Find the nearest existing index_feature.
230 for (int m = 1; m < kMaxOffsetDist; ++m) {
231 int theta = f.Theta + m * dir / 2;
232 INT_FEATURE_STRUCT offset_f;
233 offset_f.X = f.X;
234 offset_f.Y = f.Y;
235 offset_f.Theta = Modulo(theta, 256);
236 int offset_index = IndexFeature(offset_f);
237 if (offset_index != index_feature && offset_index >= 0)
238 return offset_index; // Found one.
239 }
240 }
241 return -1; // Nothing within the max distance.
242}
243
244} // namespace tesseract.

Callers

nothing calls this directly

Calls 6

FeatureDirectionFunction · 0.85
IntCastRoundedFunction · 0.85
ModuloFunction · 0.85
rotateMethod · 0.45
xMethod · 0.45
yMethod · 0.45

Tested by

no test coverage detected