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 printf(
"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());
203 int resolution = pixGetXRes(tess->
pix_binary());
213 TO_BLOCK_LIST land_blocks, port_blocks;
216 if (port_blocks.empty()) {
219 &blocks, &port_blocks);
230 return os_detect(&port_blocks, osr, tess);
239 TO_BLOCK_IT block_it;
240 block_it.set_to_list(port_blocks);
242 BLOBNBOX_CLIST filtered_list;
243 BLOBNBOX_C_IT filtered_it(&filtered_list);
245 for (block_it.mark_cycle_pt(); !block_it.cycled_list();
246 block_it.forward ()) {
247 TO_BLOCK* to_block = block_it.data();
251 bbox_it.set_to_list(&to_block->
blobs);
252 for (bbox_it.mark_cycle_pt (); !bbox_it.cycled_list ();
253 bbox_it.forward ()) {
259 float y_x = fabs((box.
height() * 1.0) / 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);
285 BLOBNBOX_C_IT filtered_it(blob_list);
293 printf(
"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.0
f, 0.0
f);
333 BLOB_CHOICE_LIST ratings[4];
335 for (
int i = 0; i < 4; ++i) {
340 float x_origin = (box.
left() + box.
right()) / 2.0
f;
341 float y_origin = (box.
bottom() + box.
top()) / 2.0
f;
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,
358 current_rotation.
rotate(rotation90);
365 stop = s->
must_stop(orientation) && stop;
377 float blob_o_score[4] = {0.0, 0.0, 0.0, 0.0};
378 float total_blob_o_score = 0.0;
380 for (
int i = 0; i < 4; ++i) {
381 BLOB_CHOICE_IT choice_it;
382 choice_it.set_to_list(scores + i);
383 if (!choice_it.empty()) {
386 blob_o_score[i] = 1 + 0.05 * choice_it.data()->certainty();
387 total_blob_o_score += blob_o_score[i];
392 for (
int i = 0; total_blob_o_score != 0 && i < 4; ++i) {
393 osr_->
orientations[i] += log(blob_o_score[i] / total_blob_o_score);
400 for (
int i = 0; i < 4; ++i) {
437 for (
int i = 0; i < 4; ++i) {
441 BLOB_CHOICE_IT choice_it;
442 choice_it.set_to_list(scores + i);
444 float prev_score = -1;
445 int script_count = 0;
448 int prev_class_id = -1;
449 int prev_fontinfo_id = -1;
450 const char* prev_unichar =
"";
451 const char* unichar =
"";
452 float next_best_score = -1.0;
453 int next_best_script_id = -1;
454 const char* next_best_unichar =
"";
456 for (choice_it.mark_cycle_pt(); !choice_it.cycled_list();
457 choice_it.forward()) {
461 if (done[
id])
continue;
466 if (prev_score < 0) {
471 prev_unichar = unichar;
477 next_best_script_id = choice->
script_id();
481 if (strlen(prev_unichar) == 1)
482 if (unichar[0] >=
'0' && unichar[0] <=
'9')
487 if (script_count >= 2)
491 if (script_count == 1) {
496 if (prev_id == latin_id_) {
497 if (prev_fontinfo_id >= 0) {
512 if (prev_id == katakana_id_)
514 if (prev_id == hiragana_id_)
516 if (prev_id == hangul_id_)
518 if (prev_id == han_id_)
520 if (prev_id == han_id_)