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

Method GetUNLVText

deps/tesseract/api/baseapi.cpp:1786–1885  ·  view source on GitHub ↗

* The recognized text is returned as a char* which is coded * as UNLV format Latin-1 with specific reject and suspect codes * and must be freed with the delete [] operator. */

Source from the content-addressed store, hash-verified

1784 * and must be freed with the delete [] operator.
1785 */
1786char* TessBaseAPI::GetUNLVText() {
1787 if (tesseract_ == NULL ||
1788 (!recognition_done_ && Recognize(NULL) < 0))
1789 return NULL;
1790 bool tilde_crunch_written = false;
1791 bool last_char_was_newline = true;
1792 bool last_char_was_tilde = false;
1793
1794 int total_length = TextLength(NULL);
1795 PAGE_RES_IT page_res_it(page_res_);
1796 char* result = new char[total_length];
1797 char* ptr = result;
1798 for (page_res_it.restart_page(); page_res_it.word () != NULL;
1799 page_res_it.forward()) {
1800 WERD_RES *word = page_res_it.word();
1801 // Process the current word.
1802 if (word->unlv_crunch_mode != CR_NONE) {
1803 if (word->unlv_crunch_mode != CR_DELETE &&
1804 (!tilde_crunch_written ||
1805 (word->unlv_crunch_mode == CR_KEEP_SPACE &&
1806 word->word->space() > 0 &&
1807 !word->word->flag(W_FUZZY_NON) &&
1808 !word->word->flag(W_FUZZY_SP)))) {
1809 if (!word->word->flag(W_BOL) &&
1810 word->word->space() > 0 &&
1811 !word->word->flag(W_FUZZY_NON) &&
1812 !word->word->flag(W_FUZZY_SP)) {
1813 /* Write a space to separate from preceding good text */
1814 *ptr++ = ' ';
1815 last_char_was_tilde = false;
1816 }
1817 if (!last_char_was_tilde) {
1818 // Write a reject char.
1819 last_char_was_tilde = true;
1820 *ptr++ = kUNLVReject;
1821 tilde_crunch_written = true;
1822 last_char_was_newline = false;
1823 }
1824 }
1825 } else {
1826 // NORMAL PROCESSING of non tilde crunched words.
1827 tilde_crunch_written = false;
1828 tesseract_->set_unlv_suspects(word);
1829 const char* wordstr = word->best_choice->unichar_string().string();
1830 const STRING& lengths = word->best_choice->unichar_lengths();
1831 int length = lengths.length();
1832 int i = 0;
1833 int offset = 0;
1834
1835 if (last_char_was_tilde &&
1836 word->word->space() == 0 && wordstr[offset] == ' ') {
1837 // Prevent adjacent tilde across words - we know that adjacent tildes
1838 // within words have been removed.
1839 // Skip the first character.
1840 offset = lengths[i++];
1841 }
1842 if (i < length && wordstr[offset] != 0) {
1843 if (!last_char_was_newline)

Callers 3

NAN_METHODFunction · 0.80
TessBaseAPIGetUNLVTextFunction · 0.80
AddImageHandlerMethod · 0.80

Calls 10

restart_pageMethod · 0.80
set_unlv_suspectsMethod · 0.80
rejectedMethod · 0.80
first_uniMethod · 0.80
wordMethod · 0.45
forwardMethod · 0.45
spaceMethod · 0.45
flagMethod · 0.45
stringMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected