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";
71 for (
int i = 2; i < 4; ++i) {
104 }
else if (
scripts_na[orientation][i] > second) {
116 if (strcmp(script,
"Common") && strcmp(script,
"NULL")) {
127 for (
int i = 0; i < 4; ++i) {
128 tprintf(
"Orientation id #%d", i);
145 for (
int i = 0; i < 4; ++i) {
159 TO_BLOCK_LIST *to_blocks) {
164 tesseract::TabVector_LIST v_lines;
165 tesseract::TabVector_LIST h_lines;
169 tprintf(
"Warning. Invalid resolution %d dpi. Using %d instead.\n",
170 pixGetXRes(pix), resolution);
172 resolution = pixGetXRes(pix);
176 &vertical_x, &vertical_y,
177 nullptr, &v_lines, &h_lines);
179 if (im_pix !=
nullptr) {
180 pixSubtract(pix, pix, im_pix);
197 lastdot = strrchr(name.
c_str(),
'.');
198 if (lastdot !=
nullptr)
199 name[lastdot-name.
c_str()] =
'\0';
203 int height = pixGetHeight(tess->
pix_binary());
210 TO_BLOCK_LIST land_blocks, port_blocks;
211 remove_nontext_regions(tess, &blocks, &port_blocks);
213 if (port_blocks.empty()) {
216 &blocks, &port_blocks);
227 return os_detect(&port_blocks, osr, tess);
236 TO_BLOCK_IT block_it;
237 block_it.set_to_list(port_blocks);
239 BLOBNBOX_CLIST filtered_list;
240 BLOBNBOX_C_IT filtered_it(&filtered_list);
242 for (block_it.mark_cycle_pt(); !block_it.cycled_list();
243 block_it.forward ()) {
244 TO_BLOCK* to_block = block_it.data();
248 bbox_it.set_to_list(&to_block->
blobs);
249 for (bbox_it.mark_cycle_pt (); !bbox_it.cycled_list ();
250 bbox_it.forward ()) {
257 if (box.
width() == 0)
continue;
259 float y_x = std::fabs((box.
height() * 1.0f) / box.
width());
260 float x_y = 1.0f / y_x;
262 float ratio = x_y > y_x ? x_y : y_x;
266 filtered_it.add_to_end(bbox);
279 BLOBNBOX_CLIST* blob_list,
OSResults* osr,
283 int maxCharactersToTry = 5 * minCharactersToTry;
291 BLOBNBOX_C_IT filtered_it(blob_list);
292 int real_max = std::min(filtered_it.length(), maxCharactersToTry);
298 if (real_max < minCharactersToTry / 2) {
299 tprintf(
"Too few characters. Skipping this page\n");
303 auto** blobs =
new BLOBNBOX*[filtered_it.length()];
304 int number_of_blobs = 0;
305 for (filtered_it.mark_cycle_pt (); !filtered_it.cycled_list ();
306 filtered_it.forward ()) {
307 blobs[number_of_blobs++] = filtered_it.data();
310 int num_blobs_evaluated = 0;
311 for (
int i = 0; i < real_max; ++i) {
313 && i > minCharactersToTry) {
316 ++num_blobs_evaluated;
323 return num_blobs_evaluated;
337 FCOORD current_rotation(1.0f, 0.0f);
338 FCOORD rotation90(0.0f, 1.0f);
339 BLOB_CHOICE_LIST ratings[4];
341 for (
int i = 0; i < 4; ++i) {
346 float x_origin = (box.
left() + box.
right()) / 2.0f;
347 float y_origin = (box.
bottom() + box.
top()) / 2.0f;
348 if (i == 0 || i == 2) {
350 y_origin = i == 0 ? box.
bottom() : box.
top();
354 x_origin = i == 1 ? box.
left() : box.
right();
356 std::unique_ptr<TBLOB> rotated_blob(
new TBLOB(*tblob));
357 rotated_blob->
Normalize(
nullptr, ¤t_rotation,
nullptr,
358 x_origin, y_origin, scaling, scaling,
362 current_rotation.
rotate(rotation90);
369 stop = s->
must_stop(orientation) && stop;
377 allowed_scripts_ = allowed_scripts;
383 float blob_o_score[4] = {0.0f, 0.0f, 0.0f, 0.0f};
384 float total_blob_o_score = 0.0f;
386 for (
int i = 0; i < 4; ++i) {
387 BLOB_CHOICE_IT choice_it(scores + i);
388 if (!choice_it.empty()) {
390 if (allowed_scripts_ !=
nullptr && !allowed_scripts_->
empty()) {
392 for (choice_it.mark_cycle_pt(); !choice_it.cycled_list() &&
393 choice ==
nullptr; choice_it.forward()) {
394 int choice_script = choice_it.data()->
script_id();
396 for (s = 0; s < allowed_scripts_->
size(); ++s) {
397 if ((*allowed_scripts_)[s] == choice_script) {
398 choice = choice_it.data();
404 choice = choice_it.data();
406 if (choice !=
nullptr) {
409 blob_o_score[i] = 1 + 0.05 * choice->
certainty();
410 total_blob_o_score += blob_o_score[i];
414 if (total_blob_o_score == 0.0)
return false;
417 float worst_score = 0.0f;
418 int num_good_scores = 0;
419 for (
float f : blob_o_score) {
422 if (worst_score == 0.0f || f < worst_score)
426 if (num_good_scores == 1) {
430 for (
float& f : blob_o_score) {
433 total_blob_o_score += worst_score;
438 for (
int i = 0; total_blob_o_score != 0 && i < 4; ++i) {
457 allowed_scripts_ = allowed_scripts;
472 for (
int i = 0; i < 4; ++i) {
475 BLOB_CHOICE_IT choice_it;
476 choice_it.set_to_list(scores + i);
478 float prev_score = -1;
479 int script_count = 0;
481 int prev_fontinfo_id = -1;
482 const char* prev_unichar =
"";
483 const char* unichar =
"";
485 for (choice_it.mark_cycle_pt(); !choice_it.cycled_list();
486 choice_it.forward()) {
489 if (allowed_scripts_ !=
nullptr && !allowed_scripts_->
empty()) {
492 for (s = 0; s < allowed_scripts_->
size(); ++s) {
493 if ((*allowed_scripts_)[s] == id)
break;
495 if (s == allowed_scripts_->
size())
continue;
498 if (done[
id])
continue;
503 if (prev_score < 0) {
507 prev_unichar = unichar;
513 if (strlen(prev_unichar) == 1)
514 if (unichar[0] >=
'0' && unichar[0] <=
'9')
519 if (script_count >= 2)
523 if (script_count == 1) {
528 if (prev_id == latin_id_) {
529 if (prev_fontinfo_id >= 0) {
544 if (prev_id == katakana_id_)
546 if (prev_id == hiragana_id_)
548 if (prev_id == hangul_id_)
550 if (prev_id == han_id_) {