51 static const char* han_script =
"Han";
52 static const char* latin_script =
"Latin";
53 static const char* katakana_script =
"Katakana";
54 static const char* hiragana_script =
"Hiragana";
55 static const char* hangul_script =
"Hangul";
58 const char* ScriptDetector::korean_script_ =
"Korean";
59 const char* ScriptDetector::japanese_script_ =
"Japanese";
60 const char* ScriptDetector::fraktur_script_ =
"Fraktur";
76 for (
int i = 2; i < 4; ++i) {
109 }
else if (
scripts_na[orientation][i] > second) {
121 if (strcmp(script,
"Common") && strcmp(script,
"NULL")) {
132 for (
int i = 0; i < 4; ++i) {
133 tprintf(
"Orientation id #%d", i);
150 for (
int i = 0; i < 4; ++i) {
163 TO_BLOCK_LIST *to_blocks) {
168 tesseract::TabVector_LIST v_lines;
169 tesseract::TabVector_LIST h_lines;
171 int resolution = (kMinCredibleResolution > pixGetXRes(pix)) ?
172 kMinCredibleResolution : pixGetXRes(pix);
175 &vertical_x, &vertical_y,
176 NULL, &v_lines, &h_lines);
178 if (im_pix !=
NULL) {
179 pixSubtract(pix, pix, im_pix);
196 lastdot = strrchr (name.
string (),
'.');
198 name[lastdot-name.
string()] =
'\0';
202 int height = pixGetHeight(tess->
pix_binary());
209 TO_BLOCK_LIST land_blocks, port_blocks;
212 if (port_blocks.empty()) {
215 &blocks, &port_blocks);
226 return os_detect(&port_blocks, osr, tess);
235 TO_BLOCK_IT block_it;
236 block_it.set_to_list(port_blocks);
238 BLOBNBOX_CLIST filtered_list;
239 BLOBNBOX_C_IT filtered_it(&filtered_list);
241 for (block_it.mark_cycle_pt(); !block_it.cycled_list();
242 block_it.forward ()) {
243 TO_BLOCK* to_block = block_it.data();
247 bbox_it.set_to_list(&to_block->
blobs);
248 for (bbox_it.mark_cycle_pt (); !bbox_it.cycled_list ();
249 bbox_it.forward ()) {
255 float y_x = fabs((box.
height() * 1.0) / box.
width());
256 float x_y = 1.0f / y_x;
258 float ratio = x_y > y_x ? x_y : y_x;
262 filtered_it.add_to_end(bbox);
275 BLOBNBOX_CLIST* blob_list,
OSResults* osr,
285 BLOBNBOX_C_IT filtered_it(blob_list);
293 tprintf(
"Too few characters. Skipping this page\n");
298 int number_of_blobs = 0;
299 for (filtered_it.mark_cycle_pt (); !filtered_it.cycled_list ();
300 filtered_it.forward ()) {
301 blobs[number_of_blobs++] = (
BLOBNBOX*)filtered_it.data();
304 int num_blobs_evaluated = 0;
305 for (
int i = 0; i < real_max; ++i) {
310 ++num_blobs_evaluated;
317 return num_blobs_evaluated;
331 FCOORD current_rotation(1.0f, 0.0f);
332 FCOORD rotation90(0.0f, 1.0f);
333 BLOB_CHOICE_LIST ratings[4];
335 for (
int i = 0; i < 4; ++i) {
340 float x_origin = (box.
left() + box.
right()) / 2.0f;
341 float y_origin = (box.
bottom() + box.
top()) / 2.0f;
342 if (i == 0 || i == 2) {
344 y_origin = i == 0 ? box.
bottom() : box.
top();
348 x_origin = i == 1 ? box.
left() : box.
right();
352 x_origin, y_origin, scaling, scaling,
357 current_rotation.
rotate(rotation90);
364 stop = s->
must_stop(orientation) && stop;
372 allowed_scripts_ = allowed_scripts;
378 float blob_o_score[4] = {0.0f, 0.0f, 0.0f, 0.0f};
379 float total_blob_o_score = 0.0f;
381 for (
int i = 0; i < 4; ++i) {
382 BLOB_CHOICE_IT choice_it(scores + i);
383 if (!choice_it.empty()) {
385 if (allowed_scripts_ !=
NULL && !allowed_scripts_->
empty()) {
387 for (choice_it.mark_cycle_pt(); !choice_it.cycled_list() &&
388 choice ==
NULL; choice_it.forward()) {
389 int choice_script = choice_it.data()->script_id();
391 for (s = 0; s < allowed_scripts_->
size(); ++s) {
392 if ((*allowed_scripts_)[s] == choice_script) {
393 choice = choice_it.data();
399 choice = choice_it.data();
401 if (choice !=
NULL) {
404 blob_o_score[i] = 1 + 0.05 * choice->
certainty();
405 total_blob_o_score += blob_o_score[i];
409 if (total_blob_o_score == 0.0)
return false;
412 float worst_score = 0.0f;
413 int num_good_scores = 0;
414 for (
int i = 0; i < 4; ++i) {
415 if (blob_o_score[i] > 0.0f) {
417 if (worst_score == 0.0f || blob_o_score[i] < worst_score)
418 worst_score = blob_o_score[i];
421 if (num_good_scores == 1) {
425 for (
int i = 0; i < 4; ++i) {
426 if (blob_o_score[i] == 0.0f) {
427 blob_o_score[i] = worst_score;
428 total_blob_o_score += worst_score;
433 for (
int i = 0; total_blob_o_score != 0 && i < 4; ++i) {
434 osr_->
orientations[i] += log(blob_o_score[i] / total_blob_o_score);
452 allowed_scripts_ = allowed_scripts;
468 for (
int i = 0; i < 4; ++i) {
472 BLOB_CHOICE_IT choice_it;
473 choice_it.set_to_list(scores + i);
475 float prev_score = -1;
476 int script_count = 0;
478 int prev_fontinfo_id = -1;
479 const char* prev_unichar =
"";
480 const char* unichar =
"";
482 for (choice_it.mark_cycle_pt(); !choice_it.cycled_list();
483 choice_it.forward()) {
486 if (allowed_scripts_ !=
NULL && !allowed_scripts_->
empty()) {
489 for (s = 0; s < allowed_scripts_->
size(); ++s) {
490 if ((*allowed_scripts_)[s] == id)
break;
492 if (s == allowed_scripts_->
size())
continue;
495 if (done[
id])
continue;
500 if (prev_score < 0) {
504 prev_unichar = unichar;
510 if (strlen(prev_unichar) == 1)
511 if (unichar[0] >=
'0' && unichar[0] <=
'9')
516 if (script_count >= 2)
520 if (script_count == 1) {
525 if (prev_id == latin_id_) {
526 if (prev_fontinfo_id >= 0) {
541 if (prev_id == katakana_id_)
543 if (prev_id == hiragana_id_)
545 if (prev_id == hangul_id_)
547 if (prev_id == han_id_) {
Textord * mutable_textord()
static Pix * FindImages(Pix *pix)
const int kMaxCharactersToTry
void update_best_orientation()
void detect_blob(BLOB_CHOICE_LIST *scores)
float scripts_na[4][kMaxNumberOfScripts]
void rotate(const FCOORD vec)
const int kMaxNumberOfScripts
const int kMinCredibleResolution
const int kMinAcceptableBlobHeight
void Normalize(const BLOCK *block, const FCOORD *rotation, const DENORM *predecessor, float x_origin, float y_origin, float x_scale, float y_scale, float final_xshift, float final_yshift, bool inverse, Pix *pix)
static void FindAndRemoveLines(int resolution, bool debug, Pix *pix, int *vertical_x, int *vertical_y, Pix **pix_music_mask, TabVector_LIST *v_lines, TabVector_LIST *h_lines)
void FullPageBlock(int width, int height, BLOCK_LIST *blocks)
void set_best_orientation(int orientation_id)
const float kOrientationAcceptRatio
void accumulate(const OSResults &osr)
static TBLOB * PolygonalCopy(bool allow_detailed_fx, C_BLOB *src)
const float kHanRatioInKorean
const float kScriptAcceptRatio
bool must_stop(int orientation)
inT16 fontinfo_id() const
void remove_nontext_regions(tesseract::Tesseract *tess, BLOCK_LIST *blocks, TO_BLOCK_LIST *to_blocks)
const float kNonAmbiguousMargin
void AdaptiveClassifier(TBLOB *Blob, BLOB_CHOICE_LIST *Choices)
const char *const id_to_unichar(UNICHAR_ID id) const
const int OrientationIdToValue(const int &id)
bool poly_allow_detailed_fx
int add_script(const char *script)
int orientation_and_script_detection(STRING &filename, OSResults *osr, tesseract::Tesseract *tess)
const int kBlnBaselineOffset
ScriptDetector(const GenericVector< int > *allowed_scripts, OSResults *osr, tesseract::Tesseract *tess)
void update_best_script(int orientation_id)
void filter_blobs(ICOORD page_tr, TO_BLOCK_LIST *blocks, BOOL8 testing_on)
UnicityTable< FontInfo > & get_fontinfo_table()
OrientationDetector(const GenericVector< int > *allowed_scripts, OSResults *results)
const float kSizeRatioToReject
const char * get_script_from_script_id(int id) const
TESS_API int get_best_script(int orientation_id) const
int os_detect(TO_BLOCK_LIST *port_blocks, OSResults *osr, tesseract::Tesseract *tess)
int os_detect_blobs(const GenericVector< int > *allowed_scripts, BLOBNBOX_CLIST *blob_list, OSResults *osr, tesseract::Tesseract *tess)
bool detect_blob(BLOB_CHOICE_LIST *scores)
bool os_detect_blob(BLOBNBOX *bbox, OrientationDetector *o, ScriptDetector *s, OSResults *osr, tesseract::Tesseract *tess)
TBOX bounding_box() const
void find_components(Pix *pix, BLOCK_LIST *blocks, TO_BLOCK_LIST *to_blocks)
const ICOORD & topright() const
void print_scores(void) const
TBOX bounding_box() const
const float kHanRatioInJapanese
const char * string() const
POLY_BLOCK * poly_block() const
bool read_unlv_file(STRING name, inT32 xsize, inT32 ysize, BLOCK_LIST *blocks)
const int kMinCharactersToTry
UNICHAR_ID unichar_id() const
const int kDefaultResolution