40#ifndef GRAPHICS_DISABLED
42# define ASC_HEIGHT (2 * kBlnBaselineOffset + kBlnXHeight)
43# define X_HEIGHT (kBlnBaselineOffset + kBlnXHeight)
44# define BL_HEIGHT kBlnBaselineOffset
99static ScrollView *image_win;
100static ParamsEditor *pe;
101static bool stillRunning =
false;
103static ScrollView *bln_word_window =
nullptr;
107static bool recog_done =
false;
111static std::bitset<16> word_display_mode;
113static bool display_image =
false;
114static bool display_blocks =
false;
115static bool display_baselines =
false;
117static PAGE_RES *current_page_res =
nullptr;
122static INT_VAR(editor_image_menuheight, 50,
"Add to image height for menu bar");
139static void show_point(
PAGE_RES *page_res,
float x,
float y) {
143 const int kBufsize = 512;
147 msg_ptr += sprintf(msg_ptr,
"Pt:(%0.3f, %0.3f) ", x, y);
149 for (
WERD_RES *word = pr_it.
word(); word !=
nullptr; word = pr_it.forward()) {
150 if (pr_it.row() != pr_it.prev_row() && pr_it.row()->row->bounding_box().contains(pt)) {
151 msg_ptr += sprintf(msg_ptr,
"BL(x)=%0.3f ", pr_it.row()->row->base_line(x));
153 if (word->word->bounding_box().contains(pt)) {
154 TBOX box = word->word->bounding_box();
155 msg_ptr += sprintf(msg_ptr,
"Wd(%d, %d)/(%d, %d) ", box.left(), box.bottom(), box.right(),
157 C_BLOB_IT cblob_it(word->word->cblob_list());
158 for (cblob_it.mark_cycle_pt(); !cblob_it.cycled_list(); cblob_it.forward()) {
159 C_BLOB *cblob = cblob_it.data();
160 box = cblob->bounding_box();
161 if (box.contains(pt)) {
162 msg_ptr += sprintf(msg_ptr,
"CBlb(%d, %d)/(%d, %d) ", box.left(), box.bottom(),
163 box.right(), box.top());
177static void pgeditor_msg(
186 bln_word_window =
nullptr;
188 show_point(current_page_res, sv_event->
x, sv_event->
y);
198static ScrollView *bln_word_window_handle() {
200 if (bln_word_window ==
nullptr) {
201 pgeditor_msg(
"Creating BLN word window...");
204 auto *a =
new BlnEventHandler();
206 pgeditor_msg(
"Creating BLN word window...Done");
208 return bln_word_window;
218static void build_image_window(
int width,
int height) {
221 width + 1, height + editor_image_menuheight + 1, width, height,
true);
230static void display_bln_lines(ScrollView *window,
ScrollView::Color colour,
float scale_factor,
231 float y_offset,
float minx,
float maxx) {
233 window->Line(minx, y_offset + scale_factor *
DESC_HEIGHT, maxx,
235 window->Line(minx, y_offset + scale_factor *
BL_HEIGHT, maxx,
237 window->Line(minx, y_offset + scale_factor *
X_HEIGHT, maxx, y_offset + scale_factor *
X_HEIGHT);
238 window->Line(minx, y_offset + scale_factor *
ASC_HEIGHT, maxx,
256 stillRunning =
false;
258 if (strcmp(event->
parameter,
"true") == 0) {
260 }
else if (strcmp(event->
parameter,
"false") == 0) {
289 parent_menu = root_menu_item->
AddChild(
"DISPLAY");
307 parent_menu = root_menu_item->
AddChild(
"OTHER");
316 return root_menu_item;
329 image_win->
Draw(pix_binary_, 0, 0);
335 (this->*word_painter)(&pr_it);
336 if (display_baselines && pr_it.
row() != pr_it.
prev_row()) {
355 current_page_res = page_res;
363 build_image_window(width, height);
366# ifndef GRAPHICS_DISABLED
438 word_config_ = parameter;
442 if (new_value[0] ==
'T') {
443 word_display_mode.set(
DF_BOX);
445 word_display_mode.reset(
DF_BOX);
450 if (new_value[0] ==
'T') {
459 if (new_value[0] ==
'T') {
460 word_display_mode.set(
DF_TEXT);
462 word_display_mode.reset(
DF_TEXT);
467 if (new_value[0] ==
'T') {
475 if (new_value[0] ==
'T') {
483 if (new_value[0] ==
'T') {
494 display_image = (new_value[0] ==
'T');
498 display_blocks = (new_value[0] ==
'T');
502 display_baselines = (new_value[0] ==
'T');
550 snprintf(msg,
sizeof(msg),
"Unrecognised event %" PRId32
"(%s)", cmd_event, new_value);
575 switch (event.
type) {
581 show_point(current_page_res, event.
x, event.
y);
588 selection_box =
TBOX(down, up);
610# ifndef DISABLED_LEGACY_ENGINE
611 image_win->
AddMessage(
"Recogging selected words");
617 image_win->
AddMessage(
"Recogging selected blobs");
625 sprintf(msg,
"Mode %d not yet implemented", mode);
640# ifndef DISABLED_LEGACY_ENGINE
643 recog_all_words(page_res,
nullptr, &selection_box, word_config_.c_str(), 0);
681 classify_bln_numeric_mode, textord_use_cjk_fp_model,
684 bln_word_window_handle()->
Clear();
685 display_bln_lines(bln_word_window_handle(),
ScrollView::CYAN, 1.0, 0.0f, -1000.0f, 1000.0f);
688 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
692 bln_word_window_handle()->
Update();
706 bool displayed_something =
false;
710# ifndef DISABLED_LEGACY_ENGINE
713 int length = box_word->
length();
714 if (word_res->
fontinfo ==
nullptr) {
718 for (
int i = 0; i < length; ++i) {
720 switch (color_mode) {
766 image_win->
Pen(color);
789 for (c_it.mark_cycle_pt(); !c_it.cycled_list(); c_it.forward()) {
790 c_it.data()->bounding_box().plot(image_win);
792 displayed_something =
true;
797 word->
plot(image_win);
798 displayed_something =
true;
805 tword->
plot(image_win);
807 displayed_something =
true;
821 if (blamer_bundle ==
nullptr) {
827 std::string best_choice_str;
829 best_choice_str =
"NULL";
833 text += best_choice_str;
841 if (text.length() > 0) {
844 word_height = word_bb.
height();
845 int text_height = 0.50 * word_height;
846 if (text_height > 20) {
849 image_win->
TextAttributes(
"Arial", text_height,
false,
false,
false);
850 shift = (word_height < word_bb.
width()) ? 0.25 * word_height : 0.0f;
851 image_win->
Text(word_bb.
left() + shift, word_bb.
bottom() + 0.25 * word_height, text.c_str());
852 if (blame.length() > 0) {
853 image_win->
Text(word_bb.
left() + shift, word_bb.
bottom() + 0.25 * word_height - text_height,
857 displayed_something =
true;
860 if (!displayed_something) {
886 if (word_res->
blamer_bundle !=
nullptr && wordrec_debug_blamer &&
893#ifndef GRAPHICS_DISABLED
913# ifndef DISABLED_LEGACY_ENGINE
919 classify_bln_numeric_mode, textord_use_cjk_fp_model,
924 std::vector<INT_FEATURE_STRUCT> bl_features;
925 std::vector<INT_FEATURE_STRUCT> cn_features;
931 for (
auto &bl_feature : bl_features) {
938 for (
auto &cn_feature : cn_features) {
#define INT_VAR(name, val, comment)
#define STRING_VAR(name, val, comment)
@ SHOW_SUBSCRIPT_CMD_EVENT
@ SHOW_UNDERLINE_CMD_EVENT
@ SHOW_BLN_WERD_CMD_EVENT
@ SHOW_SUPERSCRIPT_CMD_EVENT
@ SHOW_DROPCAPS_CMD_EVENT
@ SHOW_FIXEDPITCH_CMD_EVENT
@ SHOW_SMALLCAPS_CMD_EVENT
PAGE_RES_IT * make_pseudo_word(PAGE_RES *page_res, const TBOX &selection_box)
void tprintf(const char *format,...)
ScrollView * CreateFeatureSpaceWindow(const char *name, int xpos, int ypos)
void RenderIntFeature(ScrollView *window, const INT_FEATURE_STRUCT *Feature, ScrollView::Color color)
@ DF_POLYGONAL
Polyg approx.
@ DF_BLAMER
Blamer information.
@ DF_BN_POLYGONAL
BL normalisd polyapx.
@ DF_EDGE_STEP
Edge steps.
int editor_image_word_bb_color
int editor_image_blob_bb_color
void ClearFeatureSpaceWindow(NORM_METHOD norm_method, ScrollView *window)
char * editor_image_win_name
void Notify(const SVEvent *sve) override
void Notify(const SVEvent *sv_event) override
void Notify(const SVEvent *sve) override
bool recog_interactive(PAGE_RES_IT *pr_it)
void process_image_event(const SVEvent &event)
bool process_cmd_win_event(int32_t cmd_event, char *new_value)
SVMenuNode * build_menu_new()
void recog_pseudo_word(PAGE_RES *page_res, TBOX &selection_box)
bool word_display(PAGE_RES_IT *pr_it)
bool word_bln_display(PAGE_RES_IT *pr_it)
void process_selected_words(PAGE_RES *page_res, TBOX &selection_box, bool(tesseract::Tesseract::*word_processor)(PAGE_RES_IT *pr_it))
bool word_set_display(PAGE_RES_IT *pr_it)
bool word_dumper(PAGE_RES_IT *pr_it)
void ResetAdaptiveClassifier()
bool word_blank_and_set_display(PAGE_RES_IT *pr_its)
void debug_word(PAGE_RES *page_res, const TBOX &selection_box)
void pgeditor_main(int width, int height, PAGE_RES *page_res)
void blob_feature_display(PAGE_RES *page_res, const TBOX &selection_box)
void do_re_display(bool(tesseract::Tesseract::*word_painter)(PAGE_RES_IT *pr_it))
bool recog_all_words(PAGE_RES *page_res, ETEXT_DESC *monitor, const TBOX *target_word_box, const char *word_config, int dopasses)
static const char * IncorrectReasonName(IncorrectResultReason irr)
std::string TruthString() const
const std::string & debug() const
IncorrectResultReason incorrect_result_reason() const
static TWERD * PolygonalCopy(bool allow_detailed_fx, WERD *src)
std::vector< TBLOB * > blobs
void plot(ScrollView *window)
const TBOX & BlobBox(unsigned index) const
bool is_fixed_pitch() const
void print(FILE *fp, bool dump)
dump whole table
PDBLK pdblk
Page Description Block.
void plot_baseline(ScrollView *window, ScrollView::Color colour)
void print(FILE *fp) const
BLOCK_RES_LIST block_res_list
WERD_CHOICE * best_choice
bool SetupForRecognition(const UNICHARSET &unicharset_in, tesseract::Tesseract *tesseract, Image pix, int norm_mode, const TBOX *norm_box, bool numeric_mode, bool use_body_size, bool allow_detailed_fx, ROW *row, const BLOCK *block)
BlamerBundle * blamer_bundle
const FontInfo * fontinfo
tesseract::BoxWord * box_word
BLOCK_RES * block() const
BLOCK_RES * prev_block() const
ROW_RES * prev_row() const
void plot(ScrollView *window, int32_t serial, ScrollView::Color colour)
void set_x(TDimension xin)
rewrite function
void set_y(TDimension yin)
rewrite function
void string_and_lengths(std::string *word_str, std::string *word_lengths_str) const
ScriptPos BlobPosition(unsigned index) const
TDimension height() const
TDimension bottom() const
void plot(ScrollView *fd) const
const char * text() const
void set_display_flag(uint8_t flag, bool value)
bool display_flag(uint8_t flag) const
static ScrollView::Color NextColor(ScrollView::Color colour)
TBOX bounding_box() const
void plot(ScrollView *window, ScrollView::Color colour)
C_BLOB_LIST * cblob_list()
static void ExtractFeatures(const TBLOB &blob, bool nonlinear_norm, std::vector< INT_FEATURE_STRUCT > *bl_features, std::vector< INT_FEATURE_STRUCT > *cn_features, INT_FX_RESULT_STRUCT *results, std::vector< int > *outline_cn_counts)
char * ShowInputDialog(const char *msg)
void AddMessage(const char *message)
void TextAttributes(const char *font, int pixel_size, bool bold, bool italic, bool underlined)
void Text(int x, int y, const char *mystring)
void Draw(Image image, int x_pos, int y_pos)
void SetVisible(bool visible)
void AddEventHandler(SVEventHandler *listener)
Add an Event Listener to this ScrollView Window.
void Rectangle(int x1, int y1, int x2, int y2)
SVEvent * AwaitEvent(SVEventType type)
SVMenuNode * AddChild(const char *txt)
void BuildMenu(ScrollView *sv, bool menu_bar=true)