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

Method GetBoxText

deps/tesseract/api/baseapi.cpp:1731–1766  ·  view source on GitHub ↗

* The recognized text is returned as a char* which is coded * as a UTF8 box file and must be freed with the delete [] operator. * page_number is a 0-base page index that will appear in the box file. */

Source from the content-addressed store, hash-verified

1729 * page_number is a 0-base page index that will appear in the box file.
1730 */
1731char* TessBaseAPI::GetBoxText(int page_number) {
1732 if (tesseract_ == NULL ||
1733 (!recognition_done_ && Recognize(NULL) < 0))
1734 return NULL;
1735 int blob_count;
1736 int utf8_length = TextLength(&blob_count);
1737 int total_length = blob_count * kBytesPerBoxFileLine + utf8_length +
1738 kMaxBytesPerLine;
1739 char* result = new char[total_length];
1740 result[0] = '\0';
1741 int output_length = 0;
1742 LTRResultIterator* it = GetLTRIterator();
1743 do {
1744 int left, top, right, bottom;
1745 if (it->BoundingBox(RIL_SYMBOL, &left, &top, &right, &bottom)) {
1746 char* text = it->GetUTF8Text(RIL_SYMBOL);
1747 // Tesseract uses space for recognition failure. Fix to a reject
1748 // character, kTesseractReject so we don't create illegal box files.
1749 for (int i = 0; text[i] != '\0'; ++i) {
1750 if (text[i] == ' ')
1751 text[i] = kTesseractReject;
1752 }
1753 snprintf(result + output_length, total_length - output_length,
1754 "%s %d %d %d %d %d\n",
1755 text, left, image_height_ - bottom,
1756 right, image_height_ - top, page_number);
1757 output_length += strlen(result + output_length);
1758 delete [] text;
1759 // Just in case...
1760 if (output_length + kMaxBytesPerLine > total_length)
1761 break;
1762 }
1763 } while (it->Next(RIL_SYMBOL));
1764 delete it;
1765 return result;
1766}
1767
1768/**
1769 * Conversion table for non-latin characters.

Callers 3

NAN_METHODFunction · 0.80
TessBaseAPIGetBoxTextFunction · 0.80
AddImageHandlerMethod · 0.80

Calls 3

BoundingBoxMethod · 0.80
GetUTF8TextMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected