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

Method GetTextDirection

deps/tesseract/api/baseapi.cpp:2134–2166  ·  view source on GitHub ↗

TODO(rays) Obsolete this function and replace with a more aptly named function that returns image coordinates rather than tesseract coordinates.

Source from the content-addressed store, hash-verified

2132// TODO(rays) Obsolete this function and replace with a more aptly named
2133// function that returns image coordinates rather than tesseract coordinates.
2134bool TessBaseAPI::GetTextDirection(int* out_offset, float* out_slope) {
2135 PageIterator* it = AnalyseLayout();
2136 if (it == NULL) {
2137 return false;
2138 }
2139 int x1, x2, y1, y2;
2140 it->Baseline(RIL_TEXTLINE, &x1, &y1, &x2, &y2);
2141 // Calculate offset and slope (NOTE: Kind of ugly)
2142 if (x2 <= x1) x2 = x1 + 1;
2143 // Convert the point pair to slope/offset of the baseline (in image coords.)
2144 *out_slope = static_cast<float>(y2 - y1) / (x2 - x1);
2145 *out_offset = static_cast<int>(y1 - *out_slope * x1);
2146 // Get the y-coord of the baseline at the left and right edges of the
2147 // textline's bounding box.
2148 int left, top, right, bottom;
2149 if (!it->BoundingBox(RIL_TEXTLINE, &left, &top, &right, &bottom)) {
2150 delete it;
2151 return false;
2152 }
2153 int left_y = IntCastRounded(*out_slope * left + *out_offset);
2154 int right_y = IntCastRounded(*out_slope * right + *out_offset);
2155 // Shift the baseline down so it passes through the nearest bottom-corner
2156 // of the textline's bounding box. This is the difference between the y
2157 // at the lowest (max) edge of the box and the actual box bottom.
2158 *out_offset += bottom - MAX(left_y, right_y);
2159 // Switch back to bottom-up tesseract coordinates. Requires negation of
2160 // the slope and height - offset for the offset.
2161 *out_slope = -*out_slope;
2162 *out_offset = rect_height_ - *out_offset;
2163 delete it;
2164
2165 return true;
2166}
2167
2168/** Sets Dict::letter_is_okay_ function to point to the given function. */
2169void TessBaseAPI::SetDictFunc(DictFunc f) {

Callers 1

Calls 3

IntCastRoundedFunction · 0.85
BaselineMethod · 0.80
BoundingBoxMethod · 0.80

Tested by

no test coverage detected