21# include "config_auto.h"
43#ifndef GRAPHICS_DISABLED
45# define ASC_HEIGHT (2 * kBlnBaselineOffset + kBlnXHeight)
46# define X_HEIGHT (kBlnBaselineOffset + kBlnXHeight)
47# define BL_HEIGHT kBlnBaselineOffset
102static ScrollView *image_win;
103static ParamsEditor *pe;
104static bool stillRunning =
false;
106static ScrollView *bln_word_window =
nullptr;
110static bool recog_done =
false;
114static std::bitset<16> word_display_mode;
116static bool display_image =
false;
117static bool display_blocks =
false;
118static bool display_baselines =
false;
120static PAGE_RES *current_page_res =
nullptr;
125static INT_VAR(editor_image_menuheight, 50,
"Add to image height for menu bar");
142static void show_point(
PAGE_RES *page_res,
float x,
float y) {
146 std::stringstream msg;
147 msg.imbue(std::locale::classic());
148 msg << std::fixed << std::setprecision(3) <<
"Pt:(" <<
x <<
", " <<
y <<
") ";
150 for (
WERD_RES *word = pr_it.
word(); word !=
nullptr; word = pr_it.forward()) {
151 if (pr_it.row() != pr_it.prev_row() && pr_it.row()->row->bounding_box().contains(pt)) {
152 msg <<
"BL(x)=" << pr_it.row()->row->base_line(
x) <<
' ';
154 if (word->word->bounding_box().contains(pt)) {
155 TBOX box = word->word->bounding_box();
156 msg <<
"Wd(" << box.left() <<
", " << box.bottom() <<
")/("
157 << box.right() <<
", " << box.top() <<
") ";
158 C_BLOB_IT cblob_it(word->word->cblob_list());
159 for (cblob_it.mark_cycle_pt(); !cblob_it.cycled_list(); cblob_it.forward()) {
160 C_BLOB *cblob = cblob_it.data();
161 box = cblob->bounding_box();
162 if (box.contains(pt)) {
163 msg <<
"CBlb(" << box.left() <<
", " << box.bottom() <<
")/("
164 << box.right() <<
", " << box.top() <<
") ";
178static void pgeditor_msg(
187 bln_word_window =
nullptr;
189 show_point(current_page_res, sv_event->
x, sv_event->
y);
199static ScrollView *bln_word_window_handle() {
201 if (bln_word_window ==
nullptr) {
202 pgeditor_msg(
"Creating BLN word window...");
205 auto *a =
new BlnEventHandler();
207 pgeditor_msg(
"Creating BLN word window...Done");
209 return bln_word_window;
219static void build_image_window(
int width,
int height) {
222 width + 1, height + editor_image_menuheight + 1, width, height,
true);
231static void display_bln_lines(ScrollView *window,
ScrollView::Color colour,
float scale_factor,
232 float y_offset,
float minx,
float maxx) {
234 window->Line(minx, y_offset + scale_factor *
DESC_HEIGHT, maxx,
236 window->Line(minx, y_offset + scale_factor *
BL_HEIGHT, maxx,
238 window->Line(minx, y_offset + scale_factor *
X_HEIGHT, maxx, y_offset + scale_factor *
X_HEIGHT);
239 window->Line(minx, y_offset + scale_factor *
ASC_HEIGHT, maxx,
257 stillRunning =
false;
259 if (strcmp(event->
parameter,
"true") == 0) {
261 }
else if (strcmp(event->
parameter,
"false") == 0) {
290 parent_menu = root_menu_item->
AddChild(
"DISPLAY");
308 parent_menu = root_menu_item->
AddChild(
"OTHER");
317 return root_menu_item;
330 image_win->
Draw(pix_binary_, 0, 0);
336 (this->*word_painter)(&pr_it);
337 if (display_baselines && pr_it.
row() != pr_it.
prev_row()) {
356 current_page_res = page_res;
364 build_image_window(width, height);
367# ifndef GRAPHICS_DISABLED
439 word_config_ = parameter;
443 if (new_value[0] ==
'T') {
444 word_display_mode.set(
DF_BOX);
446 word_display_mode.reset(
DF_BOX);
451 if (new_value[0] ==
'T') {
460 if (new_value[0] ==
'T') {
461 word_display_mode.set(
DF_TEXT);
463 word_display_mode.reset(
DF_TEXT);
468 if (new_value[0] ==
'T') {
476 if (new_value[0] ==
'T') {
484 if (new_value[0] ==
'T') {
495 display_image = (new_value[0] ==
'T');
499 display_blocks = (new_value[0] ==
'T');
503 display_baselines = (new_value[0] ==
'T');
551 snprintf(msg,
sizeof(msg),
"Unrecognised event %" PRId32
"(%s)", cmd_event, new_value);
576 switch (event.
type) {
582 show_point(current_page_res, event.
x, event.
y);
589 selection_box =
TBOX(down, up);
611# ifndef DISABLED_LEGACY_ENGINE
612 image_win->
AddMessage(
"Recogging selected words");
618 image_win->
AddMessage(
"Recogging selected blobs");
626 snprintf(msg,
sizeof(msg),
"Mode %d not yet implemented", mode);
641# ifndef DISABLED_LEGACY_ENGINE
644 recog_all_words(page_res,
nullptr, &selection_box, word_config_.c_str(), 0);
682 classify_bln_numeric_mode, textord_use_cjk_fp_model,
685 bln_word_window_handle()->
Clear();
686 display_bln_lines(bln_word_window_handle(),
ScrollView::CYAN, 1.0, 0.0f, -1000.0f, 1000.0f);
689 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
693 bln_word_window_handle()->
Update();
707 bool displayed_something =
false;
711# ifndef DISABLED_LEGACY_ENGINE
714 int length = box_word->
length();
715 if (word_res->
fontinfo ==
nullptr) {
719 for (
int i = 0;
i < length; ++
i) {
721 switch (color_mode) {
767 image_win->
Pen(color);
790 for (c_it.mark_cycle_pt(); !c_it.cycled_list(); c_it.forward()) {
791 c_it.data()->bounding_box().plot(image_win);
793 displayed_something =
true;
798 word->
plot(image_win);
799 displayed_something =
true;
806 tword->
plot(image_win);
808 displayed_something =
true;
822 if (blamer_bundle ==
nullptr) {
828 std::string best_choice_str;
830 best_choice_str =
"NULL";
834 text += best_choice_str;
842 if (text.length() > 0) {
845 word_height = word_bb.
height();
846 int text_height = 0.50 * word_height;
847 if (text_height > 20) {
850 image_win->
TextAttributes(
"Arial", text_height,
false,
false,
false);
851 shift = (word_height < word_bb.
width()) ? 0.25 * word_height : 0.0f;
852 image_win->
Text(word_bb.
left() + shift, word_bb.
bottom() + 0.25 * word_height, text.c_str());
853 if (blame.length() > 0) {
854 image_win->
Text(word_bb.
left() + shift, word_bb.
bottom() + 0.25 * word_height - text_height,
858 displayed_something =
true;
861 if (!displayed_something) {
887 if (word_res->
blamer_bundle !=
nullptr && wordrec_debug_blamer &&
894#ifndef GRAPHICS_DISABLED
914# ifndef DISABLED_LEGACY_ENGINE
920 classify_bln_numeric_mode, textord_use_cjk_fp_model,
925 std::vector<INT_FEATURE_STRUCT> bl_features;
926 std::vector<INT_FEATURE_STRUCT> cn_features;
932 for (
auto &bl_feature : bl_features) {
939 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)
std::unique_ptr< SVEvent > AwaitEvent(SVEventType type)
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)
SVMenuNode * AddChild(const char *txt)
void BuildMenu(ScrollView *sv, bool menu_bar=true)