提交 c8465252 编写于 作者: T theraysmith

Rewrite of DENORM

git-svn-id: https://tesseract-ocr.googlecode.com/svn/trunk@538 d0cd1f9f-072b-0410-8dd7-cf729c803f20
上级 b98c9223
......@@ -251,6 +251,7 @@ libdir = @libdir@
libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@
lt_ECHO = @lt_ECHO@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
......
......@@ -345,7 +345,7 @@ void Tesseract::recog_all_words(PAGE_RES* page_res,
set_global_loc_code(LOC_FUZZY_SPACE);
if (!tessedit_test_adaption && tessedit_fix_fuzzy_spaces
&& !tessedit_word_for_word)
&& !tessedit_word_for_word && !right_to_left())
fix_fuzzy_spaces(monitor, stats_.word_count, page_res);
// ****************** Pass 4 *******************
......@@ -455,6 +455,10 @@ void Tesseract::recog_all_words(PAGE_RES* page_res,
PageSegMode pageseg_mode = static_cast<PageSegMode>(
static_cast<int>(tessedit_pageseg_mode));
textord_.CleanupSingleRowResult(pageseg_mode, page_res);
if (monitor != NULL) {
monitor->progress = 100;
}
}
......
......@@ -154,11 +154,11 @@ float Tesseract::ComputeCompatibleXheight(WERD_RES *word_res) {
if (debug_x_ht_level >= 20) {
tprintf("Median xht=%f\n", new_xht);
tprintf("Mode20:A: New x-height = %f (norm), %f (orig)\n",
new_xht, new_xht / word_res->denorm.scale());
new_xht, new_xht / word_res->denorm.y_scale());
}
// The xheight must change by at least x_ht_min_change to be used.
if (fabs(new_xht - kBlnXHeight) >= x_ht_min_change)
return new_xht / word_res->denorm.scale();
return new_xht / word_res->denorm.y_scale();
else
return 0.0f;
}
......
......@@ -280,57 +280,42 @@ int os_detect_blobs(BLOBNBOX_CLIST* blob_list, OSResults* osr,
bool os_detect_blob(BLOBNBOX* bbox, OrientationDetector* o,
ScriptDetector* s, OSResults* osr,
tesseract::Tesseract* tess) {
C_BLOB* blob = bbox->cblob();
TBOX box = blob->bounding_box();
int x_mid = (box.left() + box.right()) / 2.0f;
int y_mid = (box.bottom() + box.top()) / 2.0f;
PBLOB pblob(blob);
tess->tess_cn_matching.set_value(true); // turn it on
tess->tess_bn_matching.set_value(false);
C_BLOB* blob = bbox->cblob();
TBLOB* tblob = TBLOB::PolygonalCopy(blob);
TBOX box = tblob->bounding_box();
FCOORD current_rotation(1.0f, 0.0f);
FCOORD rotation90(0.0f, 1.0f);
BLOB_CHOICE_LIST ratings[4];
// Test the 4 orientations
for (int i = 0; i < 4; ++i) {
// normalize the blob
// Normalize the blob. Set the origin to the place we want to be the
// bottom-middle after rotation.
// Scaling is to make the rotated height the x-height.
float scaling = static_cast<float>(kBlnXHeight) / box.height();
DENORM denorm(x_mid, scaling, 0.0, box.bottom(), 0, NULL, false, NULL);
pblob.move(FCOORD(-x_mid, -box.bottom()));
pblob.scale(scaling);
pblob.move(FCOORD(0.0f, kBlnBaselineOffset));
{
// List of choices given by the classifier
tess->tess_cn_matching.set_value(true); // turn it on
tess->tess_bn_matching.set_value(false);
// Convert blob
TBLOB* tessblob = make_tess_blob(&pblob);
// Classify
tess->set_denorm(&denorm);
tess->AdaptiveClassifier(tessblob, ratings + i, NULL);
delete tessblob;
float x_origin = (box.left() + box.right()) / 2.0f;
float y_origin = (box.bottom() + box.top()) / 2.0f;
if (i == 0 || i == 2) {
// Rotation is 0 or 180.
y_origin = i == 0 ? box.bottom() : box.top();
} else {
// Rotation is 90 or 270.
scaling = static_cast<float>(kBlnXHeight) / box.width();
x_origin = i == 1 ? box.left() : box.right();
}
// undo normalize
pblob.move(FCOORD(0.0f, -kBlnBaselineOffset));
pblob.scale(1.0f / scaling);
pblob.move(FCOORD(x_mid, box.bottom()));
// center the blob
pblob.move(FCOORD(-x_mid, -y_mid));
// TODO(rays) Although we should now get the correct image coords with
// the DENORM, there is nothing to tell the classifier to rotate the
// image or to actually rotate the image for it.
// Rotate it
pblob.rotate();
// Re-compute the mid
box = pblob.bounding_box();
x_mid = (box.left() + box.right()) / 2;
y_mid = (box.top() + box.bottom()) / 2;
// re-center in the new mid
pblob.move(FCOORD(x_mid, y_mid));
DENORM denorm;
denorm.SetupNormalization(NULL, NULL, &current_rotation, NULL, NULL, 0,
x_origin, y_origin, scaling, scaling,
0.0f, static_cast<float>(kBlnBaselineOffset));
TBLOB* rotated_blob = new TBLOB(*tblob);
rotated_blob->Normalize(denorm);
tess->set_denorm(&denorm);
tess->AdaptiveClassifier(rotated_blob, ratings + i, NULL);
delete rotated_blob;
current_rotation.rotate(rotation90);
}
delete tblob;
bool stop = o->detect_blob(ratings);
s->detect_blob(ratings);
......
......@@ -220,7 +220,7 @@ void Tesseract::make_reject_map( //make rej map for wd //detailed results
and the whole of any words which are very small
*/
else if (tessedit_reject_mode == 5) {
if (kBlnXHeight / word->denorm.scale () <= min_sane_x_ht_pixels)
if (kBlnXHeight / word->denorm.y_scale() <= min_sane_x_ht_pixels)
word->reject_map.rej_word_small_xht ();
else {
one_ell_conflict(word, TRUE);
......@@ -820,7 +820,7 @@ void Tesseract::flip_hyphens(WERD_RES *word_res) {
else
next_left = blob->next->bounding_box().left();
// Dont touch small or touching blobs - it is too dangerous.
if ((out_box.width() > 8 * word_res->denorm.scale()) &&
if ((out_box.width() > 8 * word_res->denorm.x_scale()) &&
(out_box.left() > prev_right) && (out_box.right() < next_left)) {
aspect_ratio = out_box.width() / (float) out_box.height();
if (unicharset.eq(best_choice->unichar_id(i), ".")) {
......
......@@ -109,8 +109,10 @@ bool Tesseract::init_tesseract_lang_data(
// Initialize TessdataManager.
STRING tessdata_path = language_data_path_prefix + kTrainedDataSuffix;
tessdata_manager.Init(tessdata_path.string(),
tessdata_manager_debug_level);
if (!tessdata_manager.Init(tessdata_path.string(),
tessdata_manager_debug_level)) {
return false;
}
// If a language specific config file (lang.config) exists, load it in.
if (tessdata_manager.SeekToStart(TESSDATA_LANG_CONFIG)) {
......
......@@ -75,14 +75,9 @@ Tesseract::Tesseract()
" a character composed form fragments", this->params()),
BOOL_MEMBER(tessedit_adaption_debug, false, "Generate and print debug"
" information for adaption", this->params()),
BOOL_MEMBER(applybox_rebalance, TRUE, "Drop dead", this->params()),
INT_MEMBER(applybox_debug, 1, "Debug level", this->params()),
INT_MEMBER(applybox_page, 0,
"Page number to apply boxes from", this->params()),
STRING_MEMBER(applybox_test_exclusions, "",
"Chars ignored for testing", this->params()),
double_MEMBER(applybox_error_band, 0.15,
"Err band as fract of xht", this->params()),
STRING_MEMBER(applybox_exposure_pattern, ".exp", "Exposure value follows"
" this pattern in the image filename. The name of the image"
" files are expected to be in the form"
......@@ -94,10 +89,6 @@ Tesseract::Tesseract()
BOOL_MEMBER(applybox_learn_ngrams_mode, false, "Each bounding box"
" is assumed to contain ngrams. Only learn the ngrams"
" whose outlines overlap horizontally.", this->params()),
BOOL_MEMBER(tessedit_print_text, false,
"Write text to stdout", this->params()),
BOOL_MEMBER(tessedit_draw_words, false,
"Draw source words", this->params()),
BOOL_MEMBER(tessedit_draw_outwords, false,
"Draw output words", this->params()),
BOOL_MEMBER(tessedit_training_tess, false,
......@@ -277,12 +268,6 @@ Tesseract::Tesseract()
"Min change in xht before actually trying it", this->params()),
BOOL_MEMBER(tessedit_write_block_separators, false,
"Write block separators in output", this->params()),
BOOL_MEMBER(tessedit_write_raw_output, false,
"Write raw stuff to name.raw", this->params()),
BOOL_MEMBER(tessedit_write_output, false,
"Write text to name.txt", this->params()),
BOOL_MEMBER(tessedit_write_ratings, false,
"Return ratings in IPEOCRAPI data", this->params()),
BOOL_MEMBER(tessedit_write_rep_codes, false,
"Write repetition char code", this->params()),
BOOL_MEMBER(tessedit_write_unlv, false,
......@@ -351,18 +336,12 @@ Tesseract::Tesseract()
"Reject any x-ht lt or eq than this", this->params()),
BOOL_MEMBER(tessedit_create_boxfile, false,
"Output text with boxes", this->params()),
BOOL_MEMBER(tessedit_read_image, true,
"Ensure the image is read", this->params()),
INT_MEMBER(tessedit_serial_unlv, 0, "0->Whole page, 1->serial"
" no adapt, 2->serial with adapt", this->params()),
INT_MEMBER(tessedit_page_number, -1, "-1 -> All pages"
" , else specifc page to process", this->params()),
BOOL_MEMBER(tessedit_write_images, false,
"Capture the image from the IPE", this->params()),
BOOL_MEMBER(interactive_mode, false, "Run interactively?", this->params()),
STRING_MEMBER(file_type, ".tif", "Filename extension", this->params()),
INT_MEMBER(testedit_match_debug, 0,
"Integer match debug ctrl", this->params()),
BOOL_MEMBER(tessedit_override_permuter, true,
"According to dict_word", this->params()),
INT_INIT_MEMBER(tessdata_manager_debug_level, 0, "Debug level for"
......
......@@ -562,11 +562,8 @@ class Tesseract : public Wordrec {
" a character composed form fragments");
BOOL_VAR_H(tessedit_adaption_debug, false,
"Generate and print debug information for adaption");
BOOL_VAR_H(applybox_rebalance, true, "Drop dead");
INT_VAR_H(applybox_debug, 1, "Debug level");
INT_VAR_H(applybox_page, 0, "Page number to apply boxes from");
STRING_VAR_H(applybox_test_exclusions, "", "Chars ignored for testing");
double_VAR_H(applybox_error_band, 0.15, "Err band as fract of xht");
STRING_VAR_H(applybox_exposure_pattern, ".exp",
"Exposure value follows this pattern in the image"
" filename. The name of the image files are expected"
......@@ -578,8 +575,6 @@ class Tesseract : public Wordrec {
BOOL_VAR_H(applybox_learn_ngrams_mode, false,
"Each bounding box is assumed to contain ngrams. Only"
" learn the ngrams whose outlines overlap horizontally.");
BOOL_VAR_H(tessedit_print_text, false, "Write text to stdout");
BOOL_VAR_H(tessedit_draw_words, false, "Draw source words");
BOOL_VAR_H(tessedit_draw_outwords, false, "Draw output words");
BOOL_VAR_H(tessedit_training_tess, false, "Call Tess to learn blobs");
BOOL_VAR_H(tessedit_dump_choices, false, "Dump char choices");
......@@ -706,11 +701,6 @@ class Tesseract : public Wordrec {
INT_VAR_H(x_ht_min_change, 8, "Min change in xht before actually trying it");
BOOL_VAR_H(tessedit_write_block_separators, false,
"Write block separators in output");
BOOL_VAR_H(tessedit_write_raw_output, false,
"Write raw stuff to name.raw");
BOOL_VAR_H(tessedit_write_output, false, "Write text to name.txt");
BOOL_VAR_H(tessedit_write_ratings, false,
"Return ratings in IPEOCRAPI data");
BOOL_VAR_H(tessedit_write_rep_codes, false,
"Write repetition char code");
BOOL_VAR_H(tessedit_write_unlv, false, "Write .unlv output file");
......@@ -755,15 +745,11 @@ class Tesseract : public Wordrec {
STRING_VAR_H(conflict_set_I_l_1, "Il1[]", "Il1 conflict set");
INT_VAR_H(min_sane_x_ht_pixels, 8, "Reject any x-ht lt or eq than this");
BOOL_VAR_H(tessedit_create_boxfile, false, "Output text with boxes");
BOOL_VAR_H(tessedit_read_image, true, "Ensure the image is read");
INT_VAR_H(tessedit_serial_unlv, 0,
"0->Whole page, 1->serial no adapt, 2->serial with adapt");
INT_VAR_H(tessedit_page_number, -1,
"-1 -> All pages, else specifc page to process");
BOOL_VAR_H(tessedit_write_images, false, "Capture the image from the IPE");
BOOL_VAR_H(interactive_mode, false, "Run interactively?");
STRING_VAR_H(file_type, ".tif", "Filename extension");
INT_VAR_H(testedit_match_debug, 0, "Integer match debug ctrl");
BOOL_VAR_H(tessedit_override_permuter, true, "According to dict_word");
INT_VAR_H(tessdata_manager_debug_level, 0,
"Debug level for TessdataManager functions.");
......
/**********************************************************************
* File: werdit.cpp (Formerly wordit.c)
* Description: An iterator for passing over all the words in a document.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册