* Fits a line to the baseline at the given level, and appends its coefficients * to the hOCR string. * NOTE: The hOCR spec is unclear on how to specify baseline coefficients for * rotated textlines. For this reason, on textlines that are not upright, this * method currently only inserts a 'textangle' property to indicate the rotation * direction and does not add any baseline information to th
| 1318 | * direction and does not add any baseline information to the hocr string. |
| 1319 | */ |
| 1320 | static void AddBaselineCoordsTohOCR(const PageIterator *it, |
| 1321 | PageIteratorLevel level, |
| 1322 | STRING* hocr_str) { |
| 1323 | tesseract::Orientation orientation = GetBlockTextOrientation(it); |
| 1324 | if (orientation != ORIENTATION_PAGE_UP) { |
| 1325 | hocr_str->add_str_int("; textangle ", 360 - orientation * 90); |
| 1326 | return; |
| 1327 | } |
| 1328 | |
| 1329 | int left, top, right, bottom; |
| 1330 | it->BoundingBox(level, &left, &top, &right, &bottom); |
| 1331 | |
| 1332 | // Try to get the baseline coordinates at this level. |
| 1333 | int x1, y1, x2, y2; |
| 1334 | if (!it->Baseline(level, &x1, &y1, &x2, &y2)) |
| 1335 | return; |
| 1336 | // Following the description of this field of the hOCR spec, we convert the |
| 1337 | // baseline coordinates so that "the bottom left of the bounding box is the |
| 1338 | // origin". |
| 1339 | x1 -= left; |
| 1340 | x2 -= left; |
| 1341 | y1 -= bottom; |
| 1342 | y2 -= bottom; |
| 1343 | |
| 1344 | // Now fit a line through the points so we can extract coefficients for the |
| 1345 | // equation: y = p1 x + p0 |
| 1346 | double p1 = 0; |
| 1347 | double p0 = 0; |
| 1348 | if (x1 == x2) { |
| 1349 | // Problem computing the polynomial coefficients. |
| 1350 | return; |
| 1351 | } |
| 1352 | p1 = (y2 - y1) / static_cast<double>(x2 - x1); |
| 1353 | p0 = y1 - static_cast<double>(p1 * x1); |
| 1354 | |
| 1355 | hocr_str->add_str_double("; baseline ", round(p1 * 1000.0) / 1000.0); |
| 1356 | hocr_str->add_str_double(" ", round(p0 * 1000.0) / 1000.0); |
| 1357 | } |
| 1358 | |
| 1359 | static void AddIdTohOCR(STRING* hocr_str, const std::string base, int num1, |
| 1360 | int num2) { |
no test coverage detected