21 #include "config_auto.h" 40 #ifndef GRAPHICS_DISABLED 41 #define ASC_HEIGHT (2 * kBlnBaselineOffset + kBlnXHeight) 42 #define X_HEIGHT (kBlnBaselineOffset + kBlnXHeight) 43 #define BL_HEIGHT kBlnBaselineOffset 101 static bool stillRunning =
false;
107 static bool recog_done =
false;
111 static BITS16 word_display_mode;
113 static bool display_image =
false;
114 static bool display_blocks =
false;
115 static bool display_baselines =
false;
117 static PAGE_RES *current_page_res =
nullptr;
120 "Editor image window name");
123 static INT_VAR(editor_image_menuheight, 50,
"Add to image height for menu bar");
125 "Word bounding box colour");
127 "Blob bounding box colour");
129 "Correct text colour");
132 "Editor debug window name");
144 static STRING_VAR(editor_debug_config_file,
"",
"Config file to apply to single words");
153 static void show_point(
PAGE_RES* page_res,
float x,
float y) {
157 const int kBufsize = 512;
161 msg_ptr += sprintf(msg_ptr,
"Pt:(%0.3f, %0.3f) ", x, y);
163 for (
WERD_RES* word = pr_it.
word(); word !=
nullptr; word = pr_it.forward()) {
164 if (pr_it.row() != pr_it.prev_row() &&
165 pr_it.row()->row->bounding_box().contains(pt)) {
166 msg_ptr += sprintf(msg_ptr,
"BL(x)=%0.3f ",
167 pr_it.row()->row->base_line(x));
169 if (word->word->bounding_box().contains(pt)) {
170 TBOX box = word->word->bounding_box();
171 msg_ptr += sprintf(msg_ptr,
"Wd(%d, %d)/(%d, %d) ",
174 C_BLOB_IT cblob_it(word->word->cblob_list());
175 for (cblob_it.mark_cycle_pt();
176 !cblob_it.cycled_list();
177 cblob_it.forward()) {
178 C_BLOB* cblob = cblob_it.data();
181 msg_ptr += sprintf(msg_ptr,
182 "CBlb(%d, %d)/(%d, %d) ",
198 static void pgeditor_msg(
207 bln_word_window =
nullptr;
209 show_point(current_page_res, sv_event->
x, sv_event->
y);
220 if (bln_word_window ==
nullptr) {
221 pgeditor_msg(
"Creating BLN word window...");
227 pgeditor_msg(
"Creating BLN word window...Done");
229 return bln_word_window;
239 static void build_image_window(
int width,
int height) {
244 height + editor_image_menuheight + 1,
257 float scale_factor,
float y_offset,
258 float minx,
float maxx) {
261 maxx, y_offset + scale_factor * DESC_HEIGHT);
263 maxx, y_offset + scale_factor * BL_HEIGHT);
265 maxx, y_offset + scale_factor * X_HEIGHT);
267 maxx, y_offset + scale_factor * ASC_HEIGHT);
285 if (strcmp(event->
parameter,
"true") == 0) { myval =
'T'; }
286 else if (strcmp(event->
parameter,
"false") == 0) { myval =
'F'; }
287 tess_->process_cmd_win_event(event->
command_id, &myval);
290 tess_->process_image_event(*event);
315 parent_menu = root_menu_item->
AddChild(
"DISPLAY");
334 parent_menu = root_menu_item->
AddChild(
"OTHER");
343 return root_menu_item;
351 void Tesseract::do_re_display(
357 image_win->
Image(pix_binary_, 0, 0);
363 (this->*word_painter)(&pr_it);
364 if (display_baselines && pr_it.
row() != pr_it.
prev_row())
380 void Tesseract::pgeditor_main(
int width,
int height,
PAGE_RES *page_res) {
381 current_page_res = page_res;
388 build_image_window(width, height);
391 #ifndef GRAPHICS_DISABLED 417 bool Tesseract::process_cmd_win_event(
439 recog_all_words(current_page_res,
nullptr,
nullptr,
nullptr, 0);
465 word_config_ = parameter;
469 if (new_value[0] ==
'T')
476 if (new_value[0] ==
'T')
484 if (new_value[0] ==
'T')
491 if (new_value[0] ==
'T')
498 if (new_value[0] ==
'T')
505 if (new_value[0] ==
'T')
515 display_image =(new_value[0] ==
'T');
519 display_blocks =(new_value[0] ==
'T');
523 display_baselines =(new_value[0] ==
'T');
571 snprintf(msg,
sizeof(msg),
"Unrecognised event %" PRId32
"(%s)",
572 cmd_event, new_value);
589 void Tesseract::process_image_event(
605 show_point(current_page_res, event.
x, event.
y);
611 selection_box =
TBOX(down, up);
615 process_selected_words(
621 process_selected_words(current_page_res,
626 process_selected_words(current_page_res,
631 debug_word(current_page_res, selection_box);
637 #ifndef DISABLED_LEGACY_ENGINE 638 image_win->
AddMessage(
"Recogging selected words");
639 this->process_selected_words(current_page_res,
641 &Tesseract::recog_interactive);
642 #endif // ndef DISABLED_LEGACY_ENGINE 645 image_win->
AddMessage(
"Recogging selected blobs");
646 recog_pseudo_word(current_page_res, selection_box);
649 blob_feature_display(current_page_res, selection_box);
653 sprintf(msg,
"Mode %d not yet implemented", mode);
667 void Tesseract::debug_word(
PAGE_RES* page_res,
const TBOX &selection_box) {
668 #ifndef DISABLED_LEGACY_ENGINE 669 ResetAdaptiveClassifier();
671 recog_all_words(page_res,
nullptr, &selection_box, word_config_.string(), 0);
695 #endif // GRAPHICS_DISABLED 697 #ifndef GRAPHICS_DISABLED 701 return word_set_display(pr_it);
715 tessedit_ocr_engine_mode,
nullptr,
716 classify_bln_numeric_mode,
717 textord_use_cjk_fp_model,
718 poly_allow_detailed_fx,
721 bln_word_window_handle()->
Clear();
723 1.0, 0.0f, -1000.0f, 1000.0f);
726 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
728 bln_word_window_handle());
731 bln_word_window_handle()->
Update();
747 bool displayed_something =
false;
753 int length = box_word->
length();
754 if (word_res->
fontinfo ==
nullptr)
return false;
756 for (
int i = 0; i < length; ++i) {
758 switch (color_mode) {
796 image_win->
Pen(color);
809 static_cast<ScrollView::Color>((int32_t)
811 static_cast<ScrollView::Color>((int32_t)
812 editor_image_word_bb_color));
818 for (c_it.mark_cycle_pt(); !c_it.cycled_list(); c_it.forward())
819 c_it.data()->bounding_box().plot(image_win);
820 displayed_something =
true;
825 word->
plot(image_win);
826 displayed_something =
true;
833 tword->
plot(image_win);
835 displayed_something =
true;
849 if (blamer_bundle ==
nullptr) {
857 best_choice_str =
"NULL";
861 text += best_choice_str;
872 word_height = word_bb.
height();
873 int text_height = 0.50 * word_height;
874 if (text_height > 20) text_height = 20;
875 image_win->
TextAttributes(
"Arial", text_height,
false,
false,
false);
876 shift = (word_height < word_bb.
width()) ? 0.25 * word_height : 0.0f;
877 image_win->
Text(word_bb.
left() + shift,
880 image_win->
Text(word_bb.
left() + shift,
881 word_bb.
bottom() + 0.25 * word_height - text_height,
885 displayed_something =
true;
888 if (!displayed_something)
891 static_cast<ScrollView::Color>((int32_t)
892 editor_image_word_bb_color));
895 #endif // GRAPHICS_DISABLED 912 if (word_res->
blamer_bundle !=
nullptr && wordrec_debug_blamer &&
914 tprintf(
"Current blamer debug: %s\n",
920 #ifndef GRAPHICS_DISABLED 935 return word_display(pr_it);
941 void Tesseract::blob_feature_display(
PAGE_RES* page_res,
942 const TBOX& selection_box) {
943 #ifndef DISABLED_LEGACY_ENGINE 949 tessedit_ocr_engine_mode,
nullptr,
950 classify_bln_numeric_mode,
951 textord_use_cjk_fp_model,
952 poly_allow_detailed_fx,
959 Classify::ExtractFeatures(*bln_blob, classify_nonlinear_norm, &bl_features,
960 &cn_features, &fx_info,
nullptr);
964 for (
int f = 0; f < bl_features.
size(); ++f)
970 for (
int f = 0; f < cn_features.
size(); ++f)
977 #endif // ndef DISABLED_LEGACY_ENGINE 981 #endif // GRAPHICS_DISABLED
void Notify(const SVEvent *sv_event) override
void BuildMenu(ScrollView *sv, bool menu_bar=true)
STRING TruthString() const
void print(FILE *fp, bool dump)
dump whole table
bool word_display(PAGE_RES_IT *pr_it)
SVMenuNode * AddChild(const char *txt)
void Text(int x, int y, const char *mystring)
void Notify(const SVEvent *sve) override
static TWERD * PolygonalCopy(bool allow_detailed_fx, WERD *src)
void SetVisible(bool visible)
void Image(struct Pix *image, int x_pos, int y_pos)
bool SetupForRecognition(const UNICHARSET &unicharset_in, tesseract::Tesseract *tesseract, Pix *pix, int norm_mode, const TBOX *norm_box, bool numeric_mode, bool use_body_size, bool allow_detailed_fx, ROW *row, const BLOCK *block)
GenericVector< TBLOB * > blobs
void Rectangle(int x1, int y1, int x2, int y2)
void set_x(int16_t xin)
rewrite function
#define INT_VAR(name, val, comment)
ROW_RES * prev_row() const
bool word_blank_and_set_display(PAGE_RES_IT *pr_its)
int editor_image_word_bb_color
void Notify(const SVEvent *sve) override
BLOCK_RES * block() const
void ClearFeatureSpaceWindow(NORM_METHOD norm_method, ScrollView *window)
void set_display_flag(uint8_t flag, bool value)
static ScrollView::Color NextColor(ScrollView::Color colour)
char * ShowInputDialog(const char *msg)
bool word_set_display(PAGE_RES_IT *pr_it)
bool contains(const FCOORD pt) const
void set_y(int16_t yin)
rewrite function
const TBOX & BlobBox(int index) const
char * editor_image_win_name
bool bit(uint8_t bit_num) const
TBOX bounding_box() const
bool word_dumper(PAGE_RES_IT *pr_it)
void plot(ScrollView *window)
SVEvent * AwaitEvent(SVEventType type)
void plot_baseline(ScrollView *window, ScrollView::Color colour)
void string_and_lengths(STRING *word_str, STRING *word_lengths_str) const
void turn_off_bit(uint8_t bit_num)
void TextAttributes(const char *font, int pixel_size, bool bold, bool italic, bool underlined)
void plot(ScrollView *fd) const
ScrollView * CreateFeatureSpaceWindow(const char *name, int xpos, int ypos)
bool word_bln_display(PAGE_RES_IT *pr_it)
IncorrectResultReason incorrect_result_reason() const
#define STRING_VAR(name, val, comment)
void AddEventHandler(SVEventHandler *listener)
Add an Event Listener to this ScrollView Window.
BLOCK_RES * prev_block() const
const FontInfo * fontinfo
const char * string() const
DLLSYM void tprintf(const char *format,...)
const STRING & debug() const
PAGE_RES_IT * make_pseudo_word(PAGE_RES *page_res, const TBOX &selection_box)
tesseract::BoxWord * box_word
PDBLK pdblk
Page Description Block.
bool display_flag(uint8_t flag) const
bool is_fixed_pitch() const
void turn_on_bit(uint8_t bit_num)
TBOX bounding_box() const
void plot(ScrollView *window, ScrollView::Color colour)
int editor_image_text_color
WERD_CHOICE * best_choice
int editor_image_blob_bb_color
void Line(int x1, int y1, int x2, int y2)
void plot(ScrollView *window, int32_t serial, ScrollView::Color colour)
void AddMessage(const char *format,...)
const char * text() const
tesseract::ScriptPos BlobPosition(int index) const
BLOCK_RES_LIST block_res_list
static const char * IncorrectReasonName(IncorrectResultReason irr)
void RenderIntFeature(ScrollView *window, const INT_FEATURE_STRUCT *Feature, ScrollView::Color color)
BlamerBundle * blamer_bundle
C_BLOB_LIST * cblob_list()