2007-03-08 04:03:40 +08:00
|
|
|
/******************************************************************
|
|
|
|
* File: docqual.cpp (Formerly docqual.c)
|
|
|
|
* Description: Document Quality Metrics
|
2019-07-02 03:59:48 +08:00
|
|
|
* Author: Phil Cheatle
|
2007-03-08 04:03:40 +08:00
|
|
|
*
|
|
|
|
* (C) Copyright 1994, Hewlett-Packard Ltd.
|
|
|
|
** Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
** you may not use this file except in compliance with the License.
|
|
|
|
** You may obtain a copy of the License at
|
|
|
|
** http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
** Unless required by applicable law or agreed to in writing, software
|
|
|
|
** distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
** See the License for the specific language governing permissions and
|
|
|
|
** limitations under the License.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
|
2019-07-02 03:59:48 +08:00
|
|
|
#include "docqual.h"
|
2021-03-13 03:35:02 +08:00
|
|
|
#include <cctype>
|
2019-07-02 03:59:48 +08:00
|
|
|
#include "reject.h"
|
|
|
|
#include "tesseractclass.h"
|
2021-03-13 03:35:02 +08:00
|
|
|
#include "tessvars.h"
|
2007-03-08 04:03:40 +08:00
|
|
|
|
2021-03-13 03:35:02 +08:00
|
|
|
namespace tesseract {
|
2010-07-20 07:29:17 +08:00
|
|
|
|
2021-03-13 03:35:02 +08:00
|
|
|
static void countMatchingBlobs(int16_t &match_count, int /*index*/) {
|
2019-07-02 03:59:48 +08:00
|
|
|
++match_count;
|
|
|
|
}
|
2007-03-08 04:03:40 +08:00
|
|
|
|
2021-03-13 03:35:02 +08:00
|
|
|
static void countAcceptedBlobs(WERD_RES *word, int16_t &match_count, int16_t &accepted_match_count,
|
|
|
|
int index) {
|
2019-07-02 03:59:48 +08:00
|
|
|
if (word->reject_map[index].accepted()) {
|
|
|
|
++accepted_match_count;
|
2010-11-24 02:34:14 +08:00
|
|
|
}
|
2019-07-02 03:59:48 +08:00
|
|
|
++match_count;
|
|
|
|
}
|
2007-03-08 04:03:40 +08:00
|
|
|
|
2021-03-13 03:35:02 +08:00
|
|
|
static void acceptIfGoodQuality(WERD_RES *word, int index) {
|
2019-07-02 03:59:48 +08:00
|
|
|
if (word->reject_map[index].accept_if_good_quality()) {
|
|
|
|
word->reject_map[index].setrej_quality_accept();
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
2019-07-02 03:59:48 +08:00
|
|
|
}
|
2007-03-08 04:03:40 +08:00
|
|
|
|
|
|
|
/*************************************************************************
|
2010-11-24 02:34:14 +08:00
|
|
|
* word_blob_quality()
|
|
|
|
* How many blobs in the box_word are identical to those of the inword?
|
|
|
|
* ASSUME blobs in both initial word and box_word are in ascending order of
|
|
|
|
* left hand blob edge.
|
2007-03-08 04:03:40 +08:00
|
|
|
*************************************************************************/
|
2021-03-13 03:35:02 +08:00
|
|
|
int16_t Tesseract::word_blob_quality(WERD_RES *word) {
|
2019-07-02 03:59:48 +08:00
|
|
|
int16_t match_count = 0;
|
|
|
|
if (word->bln_boxes != nullptr && word->rebuild_word != nullptr &&
|
|
|
|
!word->rebuild_word->blobs.empty()) {
|
2021-03-13 03:35:02 +08:00
|
|
|
using namespace std::placeholders; // for _1
|
|
|
|
word->bln_boxes->ProcessMatchedBlobs(*word->rebuild_word,
|
|
|
|
std::bind(countMatchingBlobs, match_count, _1));
|
2019-07-02 03:59:48 +08:00
|
|
|
}
|
|
|
|
return match_count;
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
|
Use POSIX data types and macros (#878)
* api: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* cutil: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* training: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract data types by POSIX data types
Now all Tesseract data types which are no longer needed can be removed
from ccutil/host.h.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* lstm: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Remove the macros which are now unused from ccutil/host.h.
Remove also the obsolete history comments.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* Fix build error caused by ambiguous ClipToRange
Error message vom Appveyor CI:
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2672: 'ClipToRange': no matching overloaded function found [C:\projects\tesseract\build\libtesseract.vcxproj]
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2782: 'T ClipToRange(const T &,const T &,const T &)': template parameter 'T' is ambiguous [C:\projects\tesseract\build\libtesseract.vcxproj]
c:\projects\tesseract\ccutil\helpers.h(122): note: see declaration of 'ClipToRange'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: could be 'char'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: or 'int'
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* unittest: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* arch: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2018-03-14 04:36:30 +08:00
|
|
|
int16_t Tesseract::word_outline_errs(WERD_RES *word) {
|
|
|
|
int16_t i = 0;
|
|
|
|
int16_t err_count = 0;
|
2007-03-08 04:03:40 +08:00
|
|
|
|
2016-12-13 00:19:35 +08:00
|
|
|
if (word->rebuild_word != nullptr) {
|
2013-09-23 23:26:50 +08:00
|
|
|
for (int b = 0; b < word->rebuild_word->NumBlobs(); ++b) {
|
2021-03-13 03:35:02 +08:00
|
|
|
TBLOB *blob = word->rebuild_word->blobs[b];
|
|
|
|
err_count += count_outline_errs(word->best_choice->unichar_string()[i], blob->NumOutlines());
|
2012-02-02 10:59:49 +08:00
|
|
|
i++;
|
|
|
|
}
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
return err_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* word_char_quality()
|
|
|
|
* Combination of blob quality and outline quality - how many good chars are
|
|
|
|
* there? - I.e chars which pass the blob AND outline tests.
|
|
|
|
*************************************************************************/
|
2021-03-13 03:35:02 +08:00
|
|
|
void Tesseract::word_char_quality(WERD_RES *word, int16_t *match_count,
|
|
|
|
int16_t *accepted_match_count) {
|
2019-07-02 03:59:48 +08:00
|
|
|
*match_count = 0;
|
|
|
|
*accepted_match_count = 0;
|
|
|
|
if (word->bln_boxes != nullptr && word->rebuild_word != nullptr &&
|
|
|
|
!word->rebuild_word->blobs.empty()) {
|
2021-03-13 03:35:02 +08:00
|
|
|
using namespace std::placeholders; // for _1
|
2019-07-02 03:59:48 +08:00
|
|
|
word->bln_boxes->ProcessMatchedBlobs(
|
|
|
|
*word->rebuild_word,
|
2021-03-13 03:35:02 +08:00
|
|
|
std::bind(countAcceptedBlobs, word, *match_count, *accepted_match_count, _1));
|
2015-09-02 23:05:14 +08:00
|
|
|
}
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* unrej_good_chs()
|
|
|
|
* Unreject POTENTIAL rejects if the blob passes the blob and outline checks
|
|
|
|
*************************************************************************/
|
2021-03-13 03:35:02 +08:00
|
|
|
void Tesseract::unrej_good_chs(WERD_RES *word) {
|
2019-07-02 03:59:48 +08:00
|
|
|
if (word->bln_boxes != nullptr && word->rebuild_word != nullptr &&
|
|
|
|
word->rebuild_word->blobs.empty()) {
|
2021-03-13 03:35:02 +08:00
|
|
|
using namespace std::placeholders; // for _1
|
|
|
|
word->bln_boxes->ProcessMatchedBlobs(*word->rebuild_word,
|
|
|
|
std::bind(acceptIfGoodQuality, word, _1));
|
2019-07-02 03:59:48 +08:00
|
|
|
}
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
|
Use POSIX data types and macros (#878)
* api: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* cutil: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* training: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract data types by POSIX data types
Now all Tesseract data types which are no longer needed can be removed
from ccutil/host.h.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* lstm: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Remove the macros which are now unused from ccutil/host.h.
Remove also the obsolete history comments.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* Fix build error caused by ambiguous ClipToRange
Error message vom Appveyor CI:
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2672: 'ClipToRange': no matching overloaded function found [C:\projects\tesseract\build\libtesseract.vcxproj]
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2782: 'T ClipToRange(const T &,const T &,const T &)': template parameter 'T' is ambiguous [C:\projects\tesseract\build\libtesseract.vcxproj]
c:\projects\tesseract\ccutil\helpers.h(122): note: see declaration of 'ClipToRange'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: could be 'char'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: or 'int'
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* unittest: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* arch: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2018-03-14 04:36:30 +08:00
|
|
|
int16_t Tesseract::count_outline_errs(char c, int16_t outline_count) {
|
2007-03-08 04:03:40 +08:00
|
|
|
int expected_outline_count;
|
|
|
|
|
2021-03-14 17:48:06 +08:00
|
|
|
if (outlines_odd.contains(c))
|
2021-03-13 03:35:02 +08:00
|
|
|
return 0; // Don't use this char
|
2021-03-14 17:48:06 +08:00
|
|
|
else if (outlines_2.contains(c))
|
2007-03-08 04:03:40 +08:00
|
|
|
expected_outline_count = 2;
|
|
|
|
else
|
|
|
|
expected_outline_count = 1;
|
2021-03-13 03:35:02 +08:00
|
|
|
return abs(outline_count - expected_outline_count);
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
|
2021-03-13 03:35:02 +08:00
|
|
|
void Tesseract::quality_based_rejection(PAGE_RES_IT &page_res_it, bool good_quality_doc) {
|
2007-03-08 04:03:40 +08:00
|
|
|
if ((tessedit_good_quality_unrej && good_quality_doc))
|
2007-07-18 09:15:07 +08:00
|
|
|
unrej_good_quality_words(page_res_it);
|
|
|
|
doc_and_block_rejection(page_res_it, good_quality_doc);
|
2007-03-08 04:03:40 +08:00
|
|
|
if (unlv_tilde_crunching) {
|
2007-07-18 09:15:07 +08:00
|
|
|
tilde_crunch(page_res_it);
|
|
|
|
tilde_delete(page_res_it);
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* unrej_good_quality_words()
|
|
|
|
* Accept potential rejects in words which pass the following checks:
|
|
|
|
* - Contains a potential reject
|
|
|
|
* - Word looks like a sensible alpha word.
|
|
|
|
* - Word segmentation is the same as the original image
|
2016-11-08 02:46:33 +08:00
|
|
|
* - All characters have the expected number of outlines
|
2007-03-08 04:03:40 +08:00
|
|
|
* NOTE - the rejection counts are recalculated after unrejection
|
2015-09-15 03:59:16 +08:00
|
|
|
* - CAN'T do it in a single pass without a bit of fiddling
|
2016-11-08 02:46:33 +08:00
|
|
|
* - keep it simple but inefficient
|
2007-03-08 04:03:40 +08:00
|
|
|
*************************************************************************/
|
2021-03-13 03:35:02 +08:00
|
|
|
void Tesseract::unrej_good_quality_words( // unreject potential
|
|
|
|
PAGE_RES_IT &page_res_it) {
|
2007-03-08 04:03:40 +08:00
|
|
|
WERD_RES *word;
|
|
|
|
ROW_RES *current_row;
|
|
|
|
BLOCK_RES *current_block;
|
|
|
|
int i;
|
|
|
|
|
2021-03-13 03:35:02 +08:00
|
|
|
page_res_it.restart_page();
|
|
|
|
while (page_res_it.word() != nullptr) {
|
|
|
|
check_debug_pt(page_res_it.word(), 100);
|
2007-03-08 04:03:40 +08:00
|
|
|
if (bland_unrej) {
|
2021-03-13 03:35:02 +08:00
|
|
|
word = page_res_it.word();
|
|
|
|
for (i = 0; i < word->reject_map.length(); i++) {
|
|
|
|
if (word->reject_map[i].accept_if_good_quality())
|
|
|
|
word->reject_map[i].setrej_quality_accept();
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
2021-03-13 03:35:02 +08:00
|
|
|
page_res_it.forward();
|
|
|
|
} else if ((page_res_it.row()->char_count > 0) &&
|
|
|
|
((page_res_it.row()->rej_count /
|
|
|
|
static_cast<float>(page_res_it.row()->char_count)) <= quality_rowrej_pc)) {
|
|
|
|
word = page_res_it.word();
|
2012-02-02 10:59:49 +08:00
|
|
|
if (word->reject_map.quality_recoverable_rejects() &&
|
|
|
|
(tessedit_unrej_any_wd ||
|
2021-03-13 03:35:02 +08:00
|
|
|
acceptable_word_string(*word->uch_set, word->best_choice->unichar_string().c_str(),
|
|
|
|
word->best_choice->unichar_lengths().c_str()) !=
|
|
|
|
AC_UNACCEPTABLE)) {
|
2019-07-02 03:59:48 +08:00
|
|
|
unrej_good_chs(word);
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
2021-03-13 03:35:02 +08:00
|
|
|
page_res_it.forward();
|
|
|
|
} else {
|
2019-07-02 03:59:48 +08:00
|
|
|
// Skip to end of dodgy row.
|
2021-03-13 03:35:02 +08:00
|
|
|
current_row = page_res_it.row();
|
|
|
|
while ((page_res_it.word() != nullptr) && (page_res_it.row() == current_row))
|
|
|
|
page_res_it.forward();
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
2021-03-13 03:35:02 +08:00
|
|
|
check_debug_pt(page_res_it.word(), 110);
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
2021-03-13 03:35:02 +08:00
|
|
|
page_res_it.restart_page();
|
2007-03-08 04:03:40 +08:00
|
|
|
page_res_it.page_res->char_count = 0;
|
|
|
|
page_res_it.page_res->rej_count = 0;
|
2016-12-13 00:19:35 +08:00
|
|
|
current_block = nullptr;
|
|
|
|
current_row = nullptr;
|
2021-03-13 03:35:02 +08:00
|
|
|
while (page_res_it.word() != nullptr) {
|
|
|
|
if (current_block != page_res_it.block()) {
|
|
|
|
current_block = page_res_it.block();
|
2007-03-08 04:03:40 +08:00
|
|
|
current_block->char_count = 0;
|
|
|
|
current_block->rej_count = 0;
|
|
|
|
}
|
2021-03-13 03:35:02 +08:00
|
|
|
if (current_row != page_res_it.row()) {
|
|
|
|
current_row = page_res_it.row();
|
2007-03-08 04:03:40 +08:00
|
|
|
current_row->char_count = 0;
|
|
|
|
current_row->rej_count = 0;
|
|
|
|
current_row->whole_word_rej_count = 0;
|
|
|
|
}
|
2021-03-13 03:35:02 +08:00
|
|
|
page_res_it.rej_stat_word();
|
|
|
|
page_res_it.forward();
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* doc_and_block_rejection()
|
|
|
|
*
|
|
|
|
* If the page has too many rejects - reject all of it.
|
|
|
|
* If any block has too many rejects - reject all words in the block
|
|
|
|
*************************************************************************/
|
|
|
|
|
2021-03-13 03:35:02 +08:00
|
|
|
void Tesseract::doc_and_block_rejection( // reject big chunks
|
|
|
|
PAGE_RES_IT &page_res_it, bool good_quality_doc) {
|
Use POSIX data types and macros (#878)
* api: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* cutil: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* training: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract data types by POSIX data types
Now all Tesseract data types which are no longer needed can be removed
from ccutil/host.h.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* lstm: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Remove the macros which are now unused from ccutil/host.h.
Remove also the obsolete history comments.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* Fix build error caused by ambiguous ClipToRange
Error message vom Appveyor CI:
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2672: 'ClipToRange': no matching overloaded function found [C:\projects\tesseract\build\libtesseract.vcxproj]
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2782: 'T ClipToRange(const T &,const T &,const T &)': template parameter 'T' is ambiguous [C:\projects\tesseract\build\libtesseract.vcxproj]
c:\projects\tesseract\ccutil\helpers.h(122): note: see declaration of 'ClipToRange'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: could be 'char'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: or 'int'
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* unittest: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* arch: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2018-03-14 04:36:30 +08:00
|
|
|
int16_t block_no = 0;
|
|
|
|
int16_t row_no = 0;
|
2007-03-08 04:03:40 +08:00
|
|
|
BLOCK_RES *current_block;
|
|
|
|
ROW_RES *current_row;
|
|
|
|
|
2018-05-21 04:04:03 +08:00
|
|
|
bool rej_word;
|
|
|
|
bool prev_word_rejected;
|
Use POSIX data types and macros (#878)
* api: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* cutil: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* training: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract data types by POSIX data types
Now all Tesseract data types which are no longer needed can be removed
from ccutil/host.h.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* lstm: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Remove the macros which are now unused from ccutil/host.h.
Remove also the obsolete history comments.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* Fix build error caused by ambiguous ClipToRange
Error message vom Appveyor CI:
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2672: 'ClipToRange': no matching overloaded function found [C:\projects\tesseract\build\libtesseract.vcxproj]
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2782: 'T ClipToRange(const T &,const T &,const T &)': template parameter 'T' is ambiguous [C:\projects\tesseract\build\libtesseract.vcxproj]
c:\projects\tesseract\ccutil\helpers.h(122): note: see declaration of 'ClipToRange'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: could be 'char'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: or 'int'
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* unittest: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* arch: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2018-03-14 04:36:30 +08:00
|
|
|
int16_t char_quality = 0;
|
|
|
|
int16_t accepted_char_quality;
|
2007-03-08 04:03:40 +08:00
|
|
|
|
2021-03-13 03:35:02 +08:00
|
|
|
if (page_res_it.page_res->rej_count * 100.0 / page_res_it.page_res->char_count >
|
|
|
|
tessedit_reject_doc_percent) {
|
2007-07-18 09:15:07 +08:00
|
|
|
reject_whole_page(page_res_it);
|
2007-03-08 04:03:40 +08:00
|
|
|
if (tessedit_debug_doc_rejection) {
|
2021-03-13 03:35:02 +08:00
|
|
|
tprintf("REJECT ALL #chars: %d #Rejects: %d; \n", page_res_it.page_res->char_count,
|
2012-02-02 10:59:49 +08:00
|
|
|
page_res_it.page_res->rej_count);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (tessedit_debug_doc_rejection) {
|
2021-03-13 03:35:02 +08:00
|
|
|
tprintf("NO PAGE REJECTION #chars: %d # Rejects: %d; \n", page_res_it.page_res->char_count,
|
2012-02-02 10:59:49 +08:00
|
|
|
page_res_it.page_res->rej_count);
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Walk blocks testing for block rejection */
|
|
|
|
|
2012-02-02 10:59:49 +08:00
|
|
|
page_res_it.restart_page();
|
2021-03-13 03:35:02 +08:00
|
|
|
WERD_RES *word;
|
2016-12-13 00:19:35 +08:00
|
|
|
while ((word = page_res_it.word()) != nullptr) {
|
2009-07-11 10:03:51 +08:00
|
|
|
current_block = page_res_it.block();
|
2018-04-19 19:55:39 +08:00
|
|
|
block_no = current_block->block->pdblk.index();
|
2012-02-02 10:59:49 +08:00
|
|
|
if (current_block->char_count > 0 &&
|
|
|
|
(current_block->rej_count * 100.0 / current_block->char_count) >
|
2021-03-13 03:35:02 +08:00
|
|
|
tessedit_reject_block_percent) {
|
2012-02-02 10:59:49 +08:00
|
|
|
if (tessedit_debug_block_rejection) {
|
2021-03-13 03:35:02 +08:00
|
|
|
tprintf("REJECTING BLOCK %d #chars: %d; #Rejects: %d\n", block_no,
|
|
|
|
current_block->char_count, current_block->rej_count);
|
2012-02-02 10:59:49 +08:00
|
|
|
}
|
2018-05-21 04:04:03 +08:00
|
|
|
prev_word_rejected = false;
|
2021-03-13 03:35:02 +08:00
|
|
|
while ((word = page_res_it.word()) != nullptr && (page_res_it.block() == current_block)) {
|
2007-03-08 04:03:40 +08:00
|
|
|
if (tessedit_preserve_blk_rej_perfect_wds) {
|
2012-02-02 10:59:49 +08:00
|
|
|
rej_word = word->reject_map.reject_count() > 0 ||
|
2021-03-13 03:35:02 +08:00
|
|
|
word->reject_map.length() < tessedit_preserve_min_wd_len;
|
2012-02-02 10:59:49 +08:00
|
|
|
if (rej_word && tessedit_dont_blkrej_good_wds &&
|
|
|
|
word->reject_map.length() >= tessedit_preserve_min_wd_len &&
|
2021-03-13 03:35:02 +08:00
|
|
|
acceptable_word_string(*word->uch_set, word->best_choice->unichar_string().c_str(),
|
|
|
|
word->best_choice->unichar_lengths().c_str()) !=
|
|
|
|
AC_UNACCEPTABLE) {
|
2019-07-02 03:59:48 +08:00
|
|
|
word_char_quality(word, &char_quality, &accepted_char_quality);
|
|
|
|
rej_word = char_quality != word->reject_map.length();
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
2012-02-02 10:59:49 +08:00
|
|
|
} else {
|
2018-05-21 04:04:03 +08:00
|
|
|
rej_word = true;
|
2012-02-02 10:59:49 +08:00
|
|
|
}
|
2007-03-08 04:03:40 +08:00
|
|
|
if (rej_word) {
|
|
|
|
/*
|
2021-03-13 03:35:02 +08:00
|
|
|
Reject spacing if both current and prev words are rejected.
|
|
|
|
NOTE - this is NOT restricted to FUZZY spaces. - When tried this
|
|
|
|
generated more space errors.
|
|
|
|
*/
|
|
|
|
if (tessedit_use_reject_spaces && prev_word_rejected &&
|
|
|
|
page_res_it.prev_row() == page_res_it.row() && word->word->space() == 1)
|
2018-05-21 05:40:58 +08:00
|
|
|
word->reject_spaces = true;
|
2012-02-02 10:59:49 +08:00
|
|
|
word->reject_map.rej_word_block_rej();
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
prev_word_rejected = rej_word;
|
2012-02-02 10:59:49 +08:00
|
|
|
page_res_it.forward();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (tessedit_debug_block_rejection) {
|
2021-03-13 03:35:02 +08:00
|
|
|
tprintf("NOT REJECTING BLOCK %d #chars: %d # Rejects: %d; \n", block_no,
|
|
|
|
page_res_it.block()->char_count, page_res_it.block()->rej_count);
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Walk rows in block testing for row rejection */
|
|
|
|
row_no = 0;
|
2021-03-13 03:35:02 +08:00
|
|
|
while (page_res_it.word() != nullptr && page_res_it.block() == current_block) {
|
2012-02-02 10:59:49 +08:00
|
|
|
current_row = page_res_it.row();
|
2007-03-08 04:03:40 +08:00
|
|
|
row_no++;
|
|
|
|
/* Reject whole row if:
|
2021-03-13 03:35:02 +08:00
|
|
|
fraction of chars on row which are rejected exceed a limit AND
|
|
|
|
fraction rejects which occur in WHOLE WERD rejects is LESS THAN a
|
|
|
|
limit
|
|
|
|
*/
|
2012-02-02 10:59:49 +08:00
|
|
|
if (current_row->char_count > 0 &&
|
|
|
|
(current_row->rej_count * 100.0 / current_row->char_count) >
|
2021-03-13 03:35:02 +08:00
|
|
|
tessedit_reject_row_percent &&
|
|
|
|
(current_row->whole_word_rej_count * 100.0 / current_row->rej_count) <
|
|
|
|
tessedit_whole_wd_rej_row_percent) {
|
2012-02-02 10:59:49 +08:00
|
|
|
if (tessedit_debug_block_rejection) {
|
2021-03-13 03:35:02 +08:00
|
|
|
tprintf("REJECTING ROW %d #chars: %d; #Rejects: %d\n", row_no,
|
|
|
|
current_row->char_count, current_row->rej_count);
|
2012-02-02 10:59:49 +08:00
|
|
|
}
|
2018-05-21 04:04:03 +08:00
|
|
|
prev_word_rejected = false;
|
2021-03-13 03:35:02 +08:00
|
|
|
while ((word = page_res_it.word()) != nullptr && page_res_it.row() == current_row) {
|
2007-03-08 04:03:40 +08:00
|
|
|
/* Preserve words on good docs unless they are mostly rejected*/
|
|
|
|
if (!tessedit_row_rej_good_docs && good_quality_doc) {
|
2012-02-02 10:59:49 +08:00
|
|
|
rej_word = word->reject_map.reject_count() /
|
2021-03-13 03:35:02 +08:00
|
|
|
static_cast<float>(word->reject_map.length()) >
|
|
|
|
tessedit_good_doc_still_rowrej_wd;
|
2012-02-02 10:59:49 +08:00
|
|
|
} else if (tessedit_preserve_row_rej_perfect_wds) {
|
|
|
|
/* Preserve perfect words anyway */
|
|
|
|
rej_word = word->reject_map.reject_count() > 0 ||
|
2021-03-13 03:35:02 +08:00
|
|
|
word->reject_map.length() < tessedit_preserve_min_wd_len;
|
2012-02-02 10:59:49 +08:00
|
|
|
if (rej_word && tessedit_dont_rowrej_good_wds &&
|
|
|
|
word->reject_map.length() >= tessedit_preserve_min_wd_len &&
|
2021-03-13 03:35:02 +08:00
|
|
|
acceptable_word_string(
|
|
|
|
*word->uch_set, word->best_choice->unichar_string().c_str(),
|
|
|
|
word->best_choice->unichar_lengths().c_str()) != AC_UNACCEPTABLE) {
|
|
|
|
word_char_quality(word, &char_quality, &accepted_char_quality);
|
2012-02-02 10:59:49 +08:00
|
|
|
rej_word = char_quality != word->reject_map.length();
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
2012-02-02 10:59:49 +08:00
|
|
|
} else {
|
2018-05-21 04:04:03 +08:00
|
|
|
rej_word = true;
|
2012-02-02 10:59:49 +08:00
|
|
|
}
|
2007-03-08 04:03:40 +08:00
|
|
|
if (rej_word) {
|
|
|
|
/*
|
2021-03-13 03:35:02 +08:00
|
|
|
Reject spacing if both current and prev words are rejected.
|
|
|
|
NOTE - this is NOT restricted to FUZZY spaces. - When tried
|
|
|
|
this generated more space errors.
|
|
|
|
*/
|
|
|
|
if (tessedit_use_reject_spaces && prev_word_rejected &&
|
|
|
|
page_res_it.prev_row() == page_res_it.row() && word->word->space() == 1)
|
2018-05-21 05:40:58 +08:00
|
|
|
word->reject_spaces = true;
|
2012-02-02 10:59:49 +08:00
|
|
|
word->reject_map.rej_word_row_rej();
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
prev_word_rejected = rej_word;
|
2012-02-02 10:59:49 +08:00
|
|
|
page_res_it.forward();
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
2012-02-02 10:59:49 +08:00
|
|
|
} else {
|
|
|
|
if (tessedit_debug_block_rejection) {
|
2021-03-13 03:35:02 +08:00
|
|
|
tprintf("NOT REJECTING ROW %d #chars: %d # Rejects: %d; \n", row_no,
|
|
|
|
current_row->char_count, current_row->rej_count);
|
2012-02-02 10:59:49 +08:00
|
|
|
}
|
2021-03-13 03:35:02 +08:00
|
|
|
while (page_res_it.word() != nullptr && page_res_it.row() == current_row)
|
2012-02-02 10:59:49 +08:00
|
|
|
page_res_it.forward();
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-02 10:59:49 +08:00
|
|
|
|
2007-03-08 04:03:40 +08:00
|
|
|
/*************************************************************************
|
|
|
|
* reject_whole_page()
|
2015-09-15 03:59:16 +08:00
|
|
|
* Don't believe any of it - set the reject map to 00..00 in all words
|
2007-03-08 04:03:40 +08:00
|
|
|
*
|
|
|
|
*************************************************************************/
|
|
|
|
|
2007-07-18 09:15:07 +08:00
|
|
|
void reject_whole_page(PAGE_RES_IT &page_res_it) {
|
2021-03-13 03:35:02 +08:00
|
|
|
page_res_it.restart_page();
|
|
|
|
while (page_res_it.word() != nullptr) {
|
|
|
|
page_res_it.word()->reject_map.rej_word_doc_rej();
|
|
|
|
page_res_it.forward();
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
2021-03-13 03:35:02 +08:00
|
|
|
// whole page is rejected
|
2018-05-21 05:40:58 +08:00
|
|
|
page_res_it.page_res->rejected = true;
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
|
2009-07-11 10:03:51 +08:00
|
|
|
void Tesseract::tilde_crunch(PAGE_RES_IT &page_res_it) {
|
2007-03-08 04:03:40 +08:00
|
|
|
WERD_RES *word;
|
|
|
|
GARBAGE_LEVEL garbage_level;
|
|
|
|
PAGE_RES_IT copy_it;
|
2018-05-21 04:04:03 +08:00
|
|
|
bool prev_potential_marked = false;
|
|
|
|
bool found_terrible_word = false;
|
2019-03-30 20:42:46 +08:00
|
|
|
bool ok_dict_word;
|
2007-03-08 04:03:40 +08:00
|
|
|
|
2012-02-02 10:59:49 +08:00
|
|
|
page_res_it.restart_page();
|
2016-12-13 00:19:35 +08:00
|
|
|
while (page_res_it.word() != nullptr) {
|
2021-03-13 03:35:02 +08:00
|
|
|
POLY_BLOCK *pb = page_res_it.block()->block->pdblk.poly_block();
|
2016-12-13 00:19:35 +08:00
|
|
|
if (pb != nullptr && !pb->IsText()) {
|
2012-02-02 10:59:49 +08:00
|
|
|
page_res_it.forward();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
word = page_res_it.word();
|
2007-03-08 04:03:40 +08:00
|
|
|
|
|
|
|
if (crunch_early_convert_bad_unlv_chs)
|
2007-07-18 09:15:07 +08:00
|
|
|
convert_bad_unlv_chs(word);
|
2007-03-08 04:03:40 +08:00
|
|
|
|
|
|
|
if (crunch_early_merge_tess_fails)
|
2012-02-02 10:59:49 +08:00
|
|
|
word->merge_tess_fails();
|
2007-03-08 04:03:40 +08:00
|
|
|
|
2021-03-13 03:35:02 +08:00
|
|
|
if (word->reject_map.accept_count() != 0) {
|
2018-05-21 04:04:03 +08:00
|
|
|
found_terrible_word = false;
|
2021-03-13 03:35:02 +08:00
|
|
|
// Forget earlier potential crunches
|
2018-05-21 04:04:03 +08:00
|
|
|
prev_potential_marked = false;
|
2021-03-13 03:35:02 +08:00
|
|
|
} else {
|
2012-02-02 10:59:49 +08:00
|
|
|
ok_dict_word = safe_dict_word(word);
|
2018-05-21 04:04:03 +08:00
|
|
|
garbage_level = garbage_word(word, ok_dict_word);
|
2007-03-08 04:03:40 +08:00
|
|
|
|
2021-03-13 03:35:02 +08:00
|
|
|
if ((garbage_level != G_NEVER_CRUNCH) && (terrible_word_crunch(word, garbage_level))) {
|
2007-03-08 04:03:40 +08:00
|
|
|
if (crunch_debug > 0) {
|
2021-03-13 03:35:02 +08:00
|
|
|
tprintf("T CRUNCHING: \"%s\"\n", word->best_choice->unichar_string().c_str());
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
word->unlv_crunch_mode = CR_KEEP_SPACE;
|
|
|
|
if (prev_potential_marked) {
|
2021-03-13 03:35:02 +08:00
|
|
|
while (copy_it.word() != word) {
|
2007-03-08 04:03:40 +08:00
|
|
|
if (crunch_debug > 0) {
|
2021-03-13 03:35:02 +08:00
|
|
|
tprintf("P1 CRUNCHING: \"%s\"\n",
|
|
|
|
copy_it.word()->best_choice->unichar_string().c_str());
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
2021-03-13 03:35:02 +08:00
|
|
|
copy_it.word()->unlv_crunch_mode = CR_KEEP_SPACE;
|
|
|
|
copy_it.forward();
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
2018-05-21 04:04:03 +08:00
|
|
|
prev_potential_marked = false;
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
2018-05-21 04:04:03 +08:00
|
|
|
found_terrible_word = true;
|
2021-03-13 03:35:02 +08:00
|
|
|
} else if ((garbage_level != G_NEVER_CRUNCH) &&
|
|
|
|
(potential_word_crunch(word, garbage_level, ok_dict_word))) {
|
2007-03-08 04:03:40 +08:00
|
|
|
if (found_terrible_word) {
|
|
|
|
if (crunch_debug > 0) {
|
2021-03-13 03:35:02 +08:00
|
|
|
tprintf("P2 CRUNCHING: \"%s\"\n", word->best_choice->unichar_string().c_str());
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
word->unlv_crunch_mode = CR_KEEP_SPACE;
|
2021-03-13 03:35:02 +08:00
|
|
|
} else if (!prev_potential_marked) {
|
2007-03-08 04:03:40 +08:00
|
|
|
copy_it = page_res_it;
|
2018-05-21 04:04:03 +08:00
|
|
|
prev_potential_marked = true;
|
2007-03-08 04:03:40 +08:00
|
|
|
if (crunch_debug > 1) {
|
2021-03-13 03:35:02 +08:00
|
|
|
tprintf("P3 CRUNCHING: \"%s\"\n", word->best_choice->unichar_string().c_str());
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
}
|
2021-03-13 03:35:02 +08:00
|
|
|
} else {
|
2018-05-21 04:04:03 +08:00
|
|
|
found_terrible_word = false;
|
2021-03-13 03:35:02 +08:00
|
|
|
// Forget earlier potential crunches
|
2018-05-21 04:04:03 +08:00
|
|
|
prev_potential_marked = false;
|
2007-03-08 04:03:40 +08:00
|
|
|
if (crunch_debug > 2) {
|
2021-03-13 03:35:02 +08:00
|
|
|
tprintf("NO CRUNCH: \"%s\"\n", word->best_choice->unichar_string().c_str());
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-13 03:35:02 +08:00
|
|
|
page_res_it.forward();
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-13 03:35:02 +08:00
|
|
|
bool Tesseract::terrible_word_crunch(WERD_RES *word, GARBAGE_LEVEL garbage_level) {
|
2007-03-08 04:03:40 +08:00
|
|
|
float rating_per_ch;
|
|
|
|
int adjusted_len;
|
|
|
|
int crunch_mode = 0;
|
|
|
|
|
2017-07-15 00:30:14 +08:00
|
|
|
if ((word->best_choice->unichar_string().length() == 0) ||
|
2019-09-23 14:12:33 +08:00
|
|
|
(strspn(word->best_choice->unichar_string().c_str(), " ") ==
|
2021-03-10 19:36:59 +08:00
|
|
|
word->best_choice->unichar_string().size()))
|
2007-03-08 04:03:40 +08:00
|
|
|
crunch_mode = 1;
|
|
|
|
else {
|
2021-03-13 03:35:02 +08:00
|
|
|
adjusted_len = word->reject_map.length();
|
2007-03-08 04:03:40 +08:00
|
|
|
if (adjusted_len > crunch_rating_max)
|
|
|
|
adjusted_len = crunch_rating_max;
|
2021-03-13 03:35:02 +08:00
|
|
|
rating_per_ch = word->best_choice->rating() / adjusted_len;
|
2007-03-08 04:03:40 +08:00
|
|
|
|
|
|
|
if (rating_per_ch > crunch_terrible_rating)
|
|
|
|
crunch_mode = 2;
|
|
|
|
else if (crunch_terrible_garbage && (garbage_level == G_TERRIBLE))
|
|
|
|
crunch_mode = 3;
|
2021-03-13 03:35:02 +08:00
|
|
|
else if ((word->best_choice->certainty() < crunch_poor_garbage_cert) && (garbage_level != G_OK))
|
2007-03-08 04:03:40 +08:00
|
|
|
crunch_mode = 4;
|
2021-03-13 03:35:02 +08:00
|
|
|
else if ((rating_per_ch > crunch_poor_garbage_rate) && (garbage_level != G_OK))
|
2007-03-08 04:03:40 +08:00
|
|
|
crunch_mode = 5;
|
|
|
|
}
|
|
|
|
if (crunch_mode > 0) {
|
|
|
|
if (crunch_debug > 2) {
|
2021-03-13 03:35:02 +08:00
|
|
|
tprintf("Terrible_word_crunch (%d) on \"%s\"\n", crunch_mode,
|
|
|
|
word->best_choice->unichar_string().c_str());
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
2018-05-21 05:40:58 +08:00
|
|
|
return true;
|
2021-03-13 03:35:02 +08:00
|
|
|
} else
|
2018-05-21 05:40:58 +08:00
|
|
|
return false;
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
|
2021-03-13 03:35:02 +08:00
|
|
|
bool Tesseract::potential_word_crunch(WERD_RES *word, GARBAGE_LEVEL garbage_level,
|
2018-05-21 05:40:58 +08:00
|
|
|
bool ok_dict_word) {
|
2007-03-08 04:03:40 +08:00
|
|
|
float rating_per_ch;
|
|
|
|
int adjusted_len;
|
2019-09-23 14:12:33 +08:00
|
|
|
const char *str = word->best_choice->unichar_string().c_str();
|
|
|
|
const char *lengths = word->best_choice->unichar_lengths().c_str();
|
2018-05-21 04:04:03 +08:00
|
|
|
bool word_crunchable;
|
2007-03-08 04:03:40 +08:00
|
|
|
int poor_indicator_count = 0;
|
|
|
|
|
2021-03-13 03:35:02 +08:00
|
|
|
word_crunchable =
|
|
|
|
!crunch_leave_accept_strings || word->reject_map.length() < 3 ||
|
|
|
|
(acceptable_word_string(*word->uch_set, str, lengths) == AC_UNACCEPTABLE && !ok_dict_word);
|
2007-03-08 04:03:40 +08:00
|
|
|
|
2012-02-02 10:59:49 +08:00
|
|
|
adjusted_len = word->reject_map.length();
|
2007-03-08 04:03:40 +08:00
|
|
|
if (adjusted_len > 10)
|
|
|
|
adjusted_len = 10;
|
2012-02-02 10:59:49 +08:00
|
|
|
rating_per_ch = word->best_choice->rating() / adjusted_len;
|
2007-03-08 04:03:40 +08:00
|
|
|
|
|
|
|
if (rating_per_ch > crunch_pot_poor_rate) {
|
|
|
|
if (crunch_debug > 2) {
|
2021-03-13 03:35:02 +08:00
|
|
|
tprintf("Potential poor rating on \"%s\"\n", word->best_choice->unichar_string().c_str());
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
poor_indicator_count++;
|
|
|
|
}
|
|
|
|
|
2021-03-13 03:35:02 +08:00
|
|
|
if (word_crunchable && word->best_choice->certainty() < crunch_pot_poor_cert) {
|
2007-03-08 04:03:40 +08:00
|
|
|
if (crunch_debug > 2) {
|
2021-03-13 03:35:02 +08:00
|
|
|
tprintf("Potential poor cert on \"%s\"\n", word->best_choice->unichar_string().c_str());
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
poor_indicator_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (garbage_level != G_OK) {
|
|
|
|
if (crunch_debug > 2) {
|
2021-03-13 03:35:02 +08:00
|
|
|
tprintf("Potential garbage on \"%s\"\n", word->best_choice->unichar_string().c_str());
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
poor_indicator_count++;
|
|
|
|
}
|
2012-02-02 10:59:49 +08:00
|
|
|
return poor_indicator_count >= crunch_pot_indicators;
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
|
2009-07-11 10:03:51 +08:00
|
|
|
void Tesseract::tilde_delete(PAGE_RES_IT &page_res_it) {
|
2007-03-08 04:03:40 +08:00
|
|
|
WERD_RES *word;
|
|
|
|
PAGE_RES_IT copy_it;
|
2018-05-21 04:04:03 +08:00
|
|
|
bool deleting_from_bol = false;
|
|
|
|
bool marked_delete_point = false;
|
Use POSIX data types and macros (#878)
* api: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* cutil: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* training: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract data types by POSIX data types
Now all Tesseract data types which are no longer needed can be removed
from ccutil/host.h.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* lstm: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Remove the macros which are now unused from ccutil/host.h.
Remove also the obsolete history comments.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* Fix build error caused by ambiguous ClipToRange
Error message vom Appveyor CI:
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2672: 'ClipToRange': no matching overloaded function found [C:\projects\tesseract\build\libtesseract.vcxproj]
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2782: 'T ClipToRange(const T &,const T &,const T &)': template parameter 'T' is ambiguous [C:\projects\tesseract\build\libtesseract.vcxproj]
c:\projects\tesseract\ccutil\helpers.h(122): note: see declaration of 'ClipToRange'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: could be 'char'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: or 'int'
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* unittest: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* arch: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2018-03-14 04:36:30 +08:00
|
|
|
int16_t debug_delete_mode;
|
2007-03-08 04:03:40 +08:00
|
|
|
CRUNCH_MODE delete_mode;
|
Use POSIX data types and macros (#878)
* api: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* cutil: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* training: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract data types by POSIX data types
Now all Tesseract data types which are no longer needed can be removed
from ccutil/host.h.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* lstm: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Remove the macros which are now unused from ccutil/host.h.
Remove also the obsolete history comments.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* Fix build error caused by ambiguous ClipToRange
Error message vom Appveyor CI:
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2672: 'ClipToRange': no matching overloaded function found [C:\projects\tesseract\build\libtesseract.vcxproj]
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2782: 'T ClipToRange(const T &,const T &,const T &)': template parameter 'T' is ambiguous [C:\projects\tesseract\build\libtesseract.vcxproj]
c:\projects\tesseract\ccutil\helpers.h(122): note: see declaration of 'ClipToRange'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: could be 'char'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: or 'int'
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* unittest: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* arch: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2018-03-14 04:36:30 +08:00
|
|
|
int16_t x_debug_delete_mode;
|
2007-03-08 04:03:40 +08:00
|
|
|
CRUNCH_MODE x_delete_mode;
|
|
|
|
|
2012-02-02 10:59:49 +08:00
|
|
|
page_res_it.restart_page();
|
2016-12-13 00:19:35 +08:00
|
|
|
while (page_res_it.word() != nullptr) {
|
2012-02-02 10:59:49 +08:00
|
|
|
word = page_res_it.word();
|
2007-03-08 04:03:40 +08:00
|
|
|
|
2021-03-13 03:35:02 +08:00
|
|
|
delete_mode = word_deletable(word, debug_delete_mode);
|
2007-03-08 04:03:40 +08:00
|
|
|
if (delete_mode != CR_NONE) {
|
2021-03-13 03:35:02 +08:00
|
|
|
if (word->word->flag(W_BOL) || deleting_from_bol) {
|
2007-03-08 04:03:40 +08:00
|
|
|
if (crunch_debug > 0) {
|
2021-03-13 03:35:02 +08:00
|
|
|
tprintf("BOL CRUNCH DELETING(%d): \"%s\"\n", debug_delete_mode,
|
|
|
|
word->best_choice->unichar_string().c_str());
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
word->unlv_crunch_mode = delete_mode;
|
2018-05-21 04:04:03 +08:00
|
|
|
deleting_from_bol = true;
|
2012-02-02 10:59:49 +08:00
|
|
|
} else if (word->word->flag(W_EOL)) {
|
2007-03-08 04:03:40 +08:00
|
|
|
if (marked_delete_point) {
|
2012-02-02 10:59:49 +08:00
|
|
|
while (copy_it.word() != word) {
|
2021-03-13 03:35:02 +08:00
|
|
|
x_delete_mode = word_deletable(copy_it.word(), x_debug_delete_mode);
|
2007-03-08 04:03:40 +08:00
|
|
|
if (crunch_debug > 0) {
|
2021-03-13 03:35:02 +08:00
|
|
|
tprintf("EOL CRUNCH DELETING(%d): \"%s\"\n", x_debug_delete_mode,
|
|
|
|
copy_it.word()->best_choice->unichar_string().c_str());
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
2021-03-13 03:35:02 +08:00
|
|
|
copy_it.word()->unlv_crunch_mode = x_delete_mode;
|
|
|
|
copy_it.forward();
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (crunch_debug > 0) {
|
2021-03-13 03:35:02 +08:00
|
|
|
tprintf("EOL CRUNCH DELETING(%d): \"%s\"\n", debug_delete_mode,
|
|
|
|
word->best_choice->unichar_string().c_str());
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
word->unlv_crunch_mode = delete_mode;
|
2018-05-21 04:04:03 +08:00
|
|
|
deleting_from_bol = false;
|
|
|
|
marked_delete_point = false;
|
2021-03-13 03:35:02 +08:00
|
|
|
} else {
|
2007-03-08 04:03:40 +08:00
|
|
|
if (!marked_delete_point) {
|
|
|
|
copy_it = page_res_it;
|
2018-05-21 04:04:03 +08:00
|
|
|
marked_delete_point = true;
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
}
|
2021-03-13 03:35:02 +08:00
|
|
|
} else {
|
2018-05-21 04:04:03 +08:00
|
|
|
deleting_from_bol = false;
|
2021-03-13 03:35:02 +08:00
|
|
|
// Forget earlier potential crunches
|
2018-05-21 04:04:03 +08:00
|
|
|
marked_delete_point = false;
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
/*
|
2021-03-13 03:35:02 +08:00
|
|
|
The following step has been left till now as the tess fails are used to
|
|
|
|
determine if the word is deletable.
|
|
|
|
*/
|
2007-03-08 04:03:40 +08:00
|
|
|
if (!crunch_early_merge_tess_fails)
|
2012-02-02 10:59:49 +08:00
|
|
|
word->merge_tess_fails();
|
2021-03-13 03:35:02 +08:00
|
|
|
page_res_it.forward();
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-11 10:03:51 +08:00
|
|
|
void Tesseract::convert_bad_unlv_chs(WERD_RES *word_res) {
|
2007-03-08 04:03:40 +08:00
|
|
|
int i;
|
2012-02-02 10:59:49 +08:00
|
|
|
UNICHAR_ID unichar_dash = word_res->uch_set->unichar_to_id("-");
|
|
|
|
UNICHAR_ID unichar_space = word_res->uch_set->unichar_to_id(" ");
|
|
|
|
UNICHAR_ID unichar_tilde = word_res->uch_set->unichar_to_id("~");
|
|
|
|
UNICHAR_ID unichar_pow = word_res->uch_set->unichar_to_id("^");
|
2009-07-11 10:03:51 +08:00
|
|
|
for (i = 0; i < word_res->reject_map.length(); ++i) {
|
|
|
|
if (word_res->best_choice->unichar_id(i) == unichar_tilde) {
|
|
|
|
word_res->best_choice->set_unichar_id(unichar_dash, i);
|
2021-03-13 03:35:02 +08:00
|
|
|
if (word_res->reject_map[i].accepted())
|
|
|
|
word_res->reject_map[i].setrej_unlv_rej();
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
2009-07-11 10:03:51 +08:00
|
|
|
if (word_res->best_choice->unichar_id(i) == unichar_pow) {
|
|
|
|
word_res->best_choice->set_unichar_id(unichar_space, i);
|
2021-03-13 03:35:02 +08:00
|
|
|
if (word_res->reject_map[i].accepted())
|
|
|
|
word_res->reject_map[i].setrej_unlv_rej();
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-30 20:42:46 +08:00
|
|
|
GARBAGE_LEVEL Tesseract::garbage_word(WERD_RES *word, bool ok_dict_word) {
|
2021-03-13 03:35:02 +08:00
|
|
|
enum STATES {
|
2007-03-08 04:03:40 +08:00
|
|
|
JUNK,
|
|
|
|
FIRST_UPPER,
|
|
|
|
FIRST_LOWER,
|
|
|
|
FIRST_NUM,
|
|
|
|
SUBSEQUENT_UPPER,
|
|
|
|
SUBSEQUENT_LOWER,
|
|
|
|
SUBSEQUENT_NUM
|
|
|
|
};
|
2019-09-23 14:12:33 +08:00
|
|
|
const char *str = word->best_choice->unichar_string().c_str();
|
|
|
|
const char *lengths = word->best_choice->unichar_lengths().c_str();
|
2007-03-08 04:03:40 +08:00
|
|
|
STATES state = JUNK;
|
|
|
|
int len = 0;
|
|
|
|
int isolated_digits = 0;
|
|
|
|
int isolated_alphas = 0;
|
|
|
|
int bad_char_count = 0;
|
|
|
|
int tess_rejs = 0;
|
|
|
|
int dodgy_chars = 0;
|
|
|
|
int ok_chars;
|
2007-07-18 09:15:07 +08:00
|
|
|
UNICHAR_ID last_char = -1;
|
2007-03-08 04:03:40 +08:00
|
|
|
int alpha_repetition_count = 0;
|
|
|
|
int longest_alpha_repetition_count = 0;
|
|
|
|
int longest_lower_run_len = 0;
|
|
|
|
int lower_string_count = 0;
|
|
|
|
int longest_upper_run_len = 0;
|
|
|
|
int upper_string_count = 0;
|
|
|
|
int total_alpha_count = 0;
|
|
|
|
int total_digit_count = 0;
|
|
|
|
|
2007-07-18 09:15:07 +08:00
|
|
|
for (; *str != '\0'; str += *(lengths++)) {
|
2007-03-08 04:03:40 +08:00
|
|
|
len++;
|
2021-03-13 03:35:02 +08:00
|
|
|
if (word->uch_set->get_isupper(str, *lengths)) {
|
2007-03-08 04:03:40 +08:00
|
|
|
total_alpha_count++;
|
|
|
|
switch (state) {
|
|
|
|
case SUBSEQUENT_UPPER:
|
|
|
|
case FIRST_UPPER:
|
|
|
|
state = SUBSEQUENT_UPPER;
|
|
|
|
upper_string_count++;
|
|
|
|
if (longest_upper_run_len < upper_string_count)
|
|
|
|
longest_upper_run_len = upper_string_count;
|
2012-02-02 10:59:49 +08:00
|
|
|
if (last_char == word->uch_set->unichar_to_id(str, *lengths)) {
|
2007-03-08 04:03:40 +08:00
|
|
|
alpha_repetition_count++;
|
|
|
|
if (longest_alpha_repetition_count < alpha_repetition_count) {
|
|
|
|
longest_alpha_repetition_count = alpha_repetition_count;
|
|
|
|
}
|
2021-03-13 03:35:02 +08:00
|
|
|
} else {
|
2012-02-02 10:59:49 +08:00
|
|
|
last_char = word->uch_set->unichar_to_id(str, *lengths);
|
2007-03-08 04:03:40 +08:00
|
|
|
alpha_repetition_count = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FIRST_NUM:
|
|
|
|
isolated_digits++;
|
2019-02-04 05:22:47 +08:00
|
|
|
// Fall through.
|
2007-03-08 04:03:40 +08:00
|
|
|
default:
|
|
|
|
state = FIRST_UPPER;
|
2012-02-02 10:59:49 +08:00
|
|
|
last_char = word->uch_set->unichar_to_id(str, *lengths);
|
2007-03-08 04:03:40 +08:00
|
|
|
alpha_repetition_count = 1;
|
|
|
|
upper_string_count = 1;
|
|
|
|
break;
|
|
|
|
}
|
2021-03-13 03:35:02 +08:00
|
|
|
} else if (word->uch_set->get_islower(str, *lengths)) {
|
2007-03-08 04:03:40 +08:00
|
|
|
total_alpha_count++;
|
|
|
|
switch (state) {
|
|
|
|
case SUBSEQUENT_LOWER:
|
|
|
|
case FIRST_LOWER:
|
|
|
|
state = SUBSEQUENT_LOWER;
|
|
|
|
lower_string_count++;
|
|
|
|
if (longest_lower_run_len < lower_string_count)
|
|
|
|
longest_lower_run_len = lower_string_count;
|
2012-02-02 10:59:49 +08:00
|
|
|
if (last_char == word->uch_set->unichar_to_id(str, *lengths)) {
|
2007-03-08 04:03:40 +08:00
|
|
|
alpha_repetition_count++;
|
|
|
|
if (longest_alpha_repetition_count < alpha_repetition_count) {
|
|
|
|
longest_alpha_repetition_count = alpha_repetition_count;
|
|
|
|
}
|
2021-03-13 03:35:02 +08:00
|
|
|
} else {
|
2012-02-02 10:59:49 +08:00
|
|
|
last_char = word->uch_set->unichar_to_id(str, *lengths);
|
2007-03-08 04:03:40 +08:00
|
|
|
alpha_repetition_count = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FIRST_NUM:
|
|
|
|
isolated_digits++;
|
2019-02-04 05:22:47 +08:00
|
|
|
// Fall through.
|
2007-03-08 04:03:40 +08:00
|
|
|
default:
|
|
|
|
state = FIRST_LOWER;
|
2012-02-02 10:59:49 +08:00
|
|
|
last_char = word->uch_set->unichar_to_id(str, *lengths);
|
2007-03-08 04:03:40 +08:00
|
|
|
alpha_repetition_count = 1;
|
|
|
|
lower_string_count = 1;
|
|
|
|
break;
|
|
|
|
}
|
2021-03-13 03:35:02 +08:00
|
|
|
} else if (word->uch_set->get_isdigit(str, *lengths)) {
|
2007-03-08 04:03:40 +08:00
|
|
|
total_digit_count++;
|
|
|
|
switch (state) {
|
|
|
|
case FIRST_NUM:
|
|
|
|
state = SUBSEQUENT_NUM;
|
|
|
|
case SUBSEQUENT_NUM:
|
|
|
|
break;
|
|
|
|
case FIRST_UPPER:
|
|
|
|
case FIRST_LOWER:
|
|
|
|
isolated_alphas++;
|
2019-02-04 05:22:47 +08:00
|
|
|
// Fall through.
|
2007-03-08 04:03:40 +08:00
|
|
|
default:
|
|
|
|
state = FIRST_NUM;
|
|
|
|
break;
|
|
|
|
}
|
2021-03-13 03:35:02 +08:00
|
|
|
} else {
|
2007-07-18 09:15:07 +08:00
|
|
|
if (*lengths == 1 && *str == ' ')
|
2007-03-08 04:03:40 +08:00
|
|
|
tess_rejs++;
|
|
|
|
else
|
|
|
|
bad_char_count++;
|
|
|
|
switch (state) {
|
|
|
|
case FIRST_NUM:
|
|
|
|
isolated_digits++;
|
|
|
|
break;
|
|
|
|
case FIRST_UPPER:
|
|
|
|
case FIRST_LOWER:
|
|
|
|
isolated_alphas++;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
state = JUNK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case FIRST_NUM:
|
|
|
|
isolated_digits++;
|
|
|
|
break;
|
|
|
|
case FIRST_UPPER:
|
|
|
|
case FIRST_LOWER:
|
|
|
|
isolated_alphas++;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (crunch_include_numerals) {
|
|
|
|
total_alpha_count += total_digit_count - isolated_digits;
|
|
|
|
}
|
|
|
|
|
2021-03-13 03:35:02 +08:00
|
|
|
if (crunch_leave_ok_strings && len >= 4 && 2 * (total_alpha_count - isolated_alphas) > len &&
|
2012-02-02 10:59:49 +08:00
|
|
|
longest_alpha_repetition_count < crunch_long_repetitions) {
|
2007-03-08 04:03:40 +08:00
|
|
|
if ((crunch_accept_ok &&
|
2021-03-13 03:35:02 +08:00
|
|
|
acceptable_word_string(*word->uch_set, str, lengths) != AC_UNACCEPTABLE) ||
|
2012-02-02 10:59:49 +08:00
|
|
|
longest_lower_run_len > crunch_leave_lc_strings ||
|
|
|
|
longest_upper_run_len > crunch_leave_uc_strings)
|
2007-03-08 04:03:40 +08:00
|
|
|
return G_NEVER_CRUNCH;
|
|
|
|
}
|
2021-03-13 03:35:02 +08:00
|
|
|
if (word->reject_map.length() > 1 && strpbrk(str, " ") == nullptr &&
|
2012-02-02 10:59:49 +08:00
|
|
|
(word->best_choice->permuter() == SYSTEM_DAWG_PERM ||
|
|
|
|
word->best_choice->permuter() == FREQ_DAWG_PERM ||
|
|
|
|
word->best_choice->permuter() == USER_DAWG_PERM ||
|
|
|
|
word->best_choice->permuter() == NUMBER_PERM ||
|
2021-03-13 03:35:02 +08:00
|
|
|
acceptable_word_string(*word->uch_set, str, lengths) != AC_UNACCEPTABLE || ok_dict_word))
|
2007-03-08 04:03:40 +08:00
|
|
|
return G_OK;
|
|
|
|
|
2021-03-13 03:35:02 +08:00
|
|
|
ok_chars = len - bad_char_count - isolated_digits - isolated_alphas - tess_rejs;
|
2007-03-08 04:03:40 +08:00
|
|
|
|
|
|
|
if (crunch_debug > 3) {
|
2021-03-13 03:35:02 +08:00
|
|
|
tprintf("garbage_word: \"%s\"\n", word->best_choice->unichar_string().c_str());
|
|
|
|
tprintf("LEN: %d bad: %d iso_N: %d iso_A: %d rej: %d\n", len, bad_char_count,
|
|
|
|
isolated_digits, isolated_alphas, tess_rejs);
|
|
|
|
}
|
|
|
|
if (bad_char_count == 0 && tess_rejs == 0 &&
|
2012-02-02 10:59:49 +08:00
|
|
|
(len > isolated_digits + isolated_alphas || len <= 2))
|
2007-03-08 04:03:40 +08:00
|
|
|
return G_OK;
|
|
|
|
|
2021-03-13 03:35:02 +08:00
|
|
|
if (tess_rejs > ok_chars || (tess_rejs > 0 && (bad_char_count + tess_rejs) * 2 > len))
|
2007-03-08 04:03:40 +08:00
|
|
|
return G_TERRIBLE;
|
|
|
|
|
|
|
|
if (len > 4) {
|
2021-03-13 03:35:02 +08:00
|
|
|
dodgy_chars = 2 * tess_rejs + bad_char_count + isolated_digits + isolated_alphas;
|
2019-04-07 14:32:02 +08:00
|
|
|
if (dodgy_chars > 5 || (dodgy_chars / static_cast<float>(len)) > 0.5)
|
2007-03-08 04:03:40 +08:00
|
|
|
return G_DODGY;
|
|
|
|
else
|
|
|
|
return G_OK;
|
2012-02-02 10:59:49 +08:00
|
|
|
} else {
|
2007-03-08 04:03:40 +08:00
|
|
|
dodgy_chars = 2 * tess_rejs + bad_char_count;
|
2021-03-13 03:35:02 +08:00
|
|
|
if ((len == 4 && dodgy_chars > 2) || (len == 3 && dodgy_chars > 2) || dodgy_chars >= len)
|
2007-03-08 04:03:40 +08:00
|
|
|
return G_DODGY;
|
|
|
|
else
|
|
|
|
return G_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* word_deletable()
|
|
|
|
* DELETE WERDS AT ENDS OF ROWS IF
|
|
|
|
* Word is crunched &&
|
|
|
|
* ( string length = 0 OR
|
2009-07-11 10:03:51 +08:00
|
|
|
* > 50% of chars are "|" (before merging) OR
|
2007-03-08 04:03:40 +08:00
|
|
|
* certainty < -10 OR
|
|
|
|
* rating /char > 60 OR
|
|
|
|
* TOP of word is more than 0.5 xht BELOW baseline OR
|
|
|
|
* BOTTOM of word is more than 0.5 xht ABOVE xht OR
|
|
|
|
* length of word < 3xht OR
|
|
|
|
* height of word < 0.7 xht OR
|
|
|
|
* height of word > 3.0 xht OR
|
|
|
|
* >75% of the outline BBs have longest dimension < 0.5xht
|
|
|
|
*************************************************************************/
|
|
|
|
|
Use POSIX data types and macros (#878)
* api: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* cutil: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* training: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract data types by POSIX data types
Now all Tesseract data types which are no longer needed can be removed
from ccutil/host.h.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* lstm: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Remove the macros which are now unused from ccutil/host.h.
Remove also the obsolete history comments.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* Fix build error caused by ambiguous ClipToRange
Error message vom Appveyor CI:
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2672: 'ClipToRange': no matching overloaded function found [C:\projects\tesseract\build\libtesseract.vcxproj]
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2782: 'T ClipToRange(const T &,const T &,const T &)': template parameter 'T' is ambiguous [C:\projects\tesseract\build\libtesseract.vcxproj]
c:\projects\tesseract\ccutil\helpers.h(122): note: see declaration of 'ClipToRange'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: could be 'char'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: or 'int'
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* unittest: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* arch: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2018-03-14 04:36:30 +08:00
|
|
|
CRUNCH_MODE Tesseract::word_deletable(WERD_RES *word, int16_t &delete_mode) {
|
2021-03-13 03:35:02 +08:00
|
|
|
int word_len = word->reject_map.length();
|
2007-03-08 04:03:40 +08:00
|
|
|
float rating_per_ch;
|
2021-03-13 03:35:02 +08:00
|
|
|
TBOX box; // BB of word
|
2007-03-08 04:03:40 +08:00
|
|
|
|
|
|
|
if (word->unlv_crunch_mode == CR_NONE) {
|
|
|
|
delete_mode = 0;
|
|
|
|
return CR_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (word_len == 0) {
|
|
|
|
delete_mode = 1;
|
|
|
|
return CR_DELETE;
|
|
|
|
}
|
|
|
|
|
2016-12-13 00:19:35 +08:00
|
|
|
if (word->rebuild_word != nullptr) {
|
|
|
|
// Cube leaves rebuild_word nullptr.
|
2012-02-02 10:59:49 +08:00
|
|
|
box = word->rebuild_word->bounding_box();
|
2021-03-13 03:35:02 +08:00
|
|
|
if (box.height() < crunch_del_min_ht * kBlnXHeight) {
|
2012-02-02 10:59:49 +08:00
|
|
|
delete_mode = 4;
|
|
|
|
return CR_DELETE;
|
|
|
|
}
|
2007-03-08 04:03:40 +08:00
|
|
|
|
2012-02-02 10:59:49 +08:00
|
|
|
if (noise_outlines(word->rebuild_word)) {
|
|
|
|
delete_mode = 5;
|
|
|
|
return CR_DELETE;
|
|
|
|
}
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
|
2021-03-13 03:35:02 +08:00
|
|
|
if ((failure_count(word) * 1.5) > word_len) {
|
2007-03-08 04:03:40 +08:00
|
|
|
delete_mode = 2;
|
|
|
|
return CR_LOOSE_SPACE;
|
|
|
|
}
|
|
|
|
|
2021-03-13 03:35:02 +08:00
|
|
|
if (word->best_choice->certainty() < crunch_del_cert) {
|
2007-03-08 04:03:40 +08:00
|
|
|
delete_mode = 7;
|
|
|
|
return CR_LOOSE_SPACE;
|
|
|
|
}
|
|
|
|
|
2021-03-13 03:35:02 +08:00
|
|
|
rating_per_ch = word->best_choice->rating() / word_len;
|
2007-03-08 04:03:40 +08:00
|
|
|
|
|
|
|
if (rating_per_ch > crunch_del_rating) {
|
|
|
|
delete_mode = 8;
|
|
|
|
return CR_LOOSE_SPACE;
|
|
|
|
}
|
|
|
|
|
2021-03-13 03:35:02 +08:00
|
|
|
if (box.top() < kBlnBaselineOffset - crunch_del_low_word * kBlnXHeight) {
|
2007-03-08 04:03:40 +08:00
|
|
|
delete_mode = 9;
|
|
|
|
return CR_LOOSE_SPACE;
|
|
|
|
}
|
|
|
|
|
2021-03-13 03:35:02 +08:00
|
|
|
if (box.bottom() > kBlnBaselineOffset + crunch_del_high_word * kBlnXHeight) {
|
2007-03-08 04:03:40 +08:00
|
|
|
delete_mode = 10;
|
|
|
|
return CR_LOOSE_SPACE;
|
|
|
|
}
|
|
|
|
|
2021-03-13 03:35:02 +08:00
|
|
|
if (box.height() > crunch_del_max_ht * kBlnXHeight) {
|
2007-03-08 04:03:40 +08:00
|
|
|
delete_mode = 11;
|
|
|
|
return CR_LOOSE_SPACE;
|
|
|
|
}
|
|
|
|
|
2021-03-13 03:35:02 +08:00
|
|
|
if (box.width() < crunch_del_min_width * kBlnXHeight) {
|
2007-03-08 04:03:40 +08:00
|
|
|
delete_mode = 3;
|
|
|
|
return CR_LOOSE_SPACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete_mode = 0;
|
|
|
|
return CR_NONE;
|
|
|
|
}
|
|
|
|
|
Use POSIX data types and macros (#878)
* api: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* cutil: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* training: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract data types by POSIX data types
Now all Tesseract data types which are no longer needed can be removed
from ccutil/host.h.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* lstm: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Remove the macros which are now unused from ccutil/host.h.
Remove also the obsolete history comments.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* Fix build error caused by ambiguous ClipToRange
Error message vom Appveyor CI:
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2672: 'ClipToRange': no matching overloaded function found [C:\projects\tesseract\build\libtesseract.vcxproj]
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2782: 'T ClipToRange(const T &,const T &,const T &)': template parameter 'T' is ambiguous [C:\projects\tesseract\build\libtesseract.vcxproj]
c:\projects\tesseract\ccutil\helpers.h(122): note: see declaration of 'ClipToRange'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: could be 'char'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: or 'int'
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* unittest: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* arch: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2018-03-14 04:36:30 +08:00
|
|
|
int16_t Tesseract::failure_count(WERD_RES *word) {
|
2019-09-23 14:12:33 +08:00
|
|
|
const char *str = word->best_choice->unichar_string().c_str();
|
2007-03-08 04:03:40 +08:00
|
|
|
int tess_rejs = 0;
|
|
|
|
|
|
|
|
for (; *str != '\0'; str++) {
|
|
|
|
if (*str == ' ')
|
|
|
|
tess_rejs++;
|
|
|
|
}
|
|
|
|
return tess_rejs;
|
|
|
|
}
|
|
|
|
|
2021-03-13 03:35:02 +08:00
|
|
|
bool Tesseract::noise_outlines(TWERD *word) {
|
|
|
|
TBOX box; // BB of outline
|
Use POSIX data types and macros (#878)
* api: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* cutil: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* training: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract data types by POSIX data types
Now all Tesseract data types which are no longer needed can be removed
from ccutil/host.h.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* lstm: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Remove the macros which are now unused from ccutil/host.h.
Remove also the obsolete history comments.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* Fix build error caused by ambiguous ClipToRange
Error message vom Appveyor CI:
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2672: 'ClipToRange': no matching overloaded function found [C:\projects\tesseract\build\libtesseract.vcxproj]
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2782: 'T ClipToRange(const T &,const T &,const T &)': template parameter 'T' is ambiguous [C:\projects\tesseract\build\libtesseract.vcxproj]
c:\projects\tesseract\ccutil\helpers.h(122): note: see declaration of 'ClipToRange'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: could be 'char'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: or 'int'
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* unittest: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* arch: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2018-03-14 04:36:30 +08:00
|
|
|
int16_t outline_count = 0;
|
|
|
|
int16_t small_outline_count = 0;
|
|
|
|
int16_t max_dimension;
|
2010-11-24 02:34:14 +08:00
|
|
|
float small_limit = kBlnXHeight * crunch_small_outlines_size;
|
2007-03-08 04:03:40 +08:00
|
|
|
|
2013-09-23 23:26:50 +08:00
|
|
|
for (int b = 0; b < word->NumBlobs(); ++b) {
|
2021-03-13 03:35:02 +08:00
|
|
|
TBLOB *blob = word->blobs[b];
|
|
|
|
for (TESSLINE *ol = blob->outlines; ol != nullptr; ol = ol->next) {
|
2007-03-08 04:03:40 +08:00
|
|
|
outline_count++;
|
2010-11-24 02:34:14 +08:00
|
|
|
box = ol->bounding_box();
|
|
|
|
if (box.height() > box.width())
|
|
|
|
max_dimension = box.height();
|
2007-03-08 04:03:40 +08:00
|
|
|
else
|
2010-11-24 02:34:14 +08:00
|
|
|
max_dimension = box.width();
|
2007-03-08 04:03:40 +08:00
|
|
|
if (max_dimension < small_limit)
|
|
|
|
small_outline_count++;
|
|
|
|
}
|
|
|
|
}
|
2013-09-23 23:26:50 +08:00
|
|
|
return small_outline_count >= outline_count;
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
2013-09-23 23:26:50 +08:00
|
|
|
|
2021-03-13 03:35:02 +08:00
|
|
|
} // namespace tesseract
|