Merge pull request #3058 from stweil/scrollview

Disable more code and data with GRAPHICS_DISABLED
This commit is contained in:
zdenop 2020-07-11 09:11:27 +02:00 committed by GitHub
commit 875bd48bd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
68 changed files with 302 additions and 197 deletions

View File

@ -886,7 +886,7 @@ int TessBaseAPI::Recognize(ETEXT_DESC* monitor) {
if (tesseract_->interactive_display_mode) {
#ifndef GRAPHICS_DISABLED
tesseract_->pgeditor_main(rect_width_, rect_height_, page_res_);
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
// The page_res is invalid after an interactive session, so cleanup
// in a way that lets us continue to the next page without crashing.
delete page_res_;

View File

@ -355,4 +355,4 @@ void ParamsEditor::WriteParams(char *filename,
}
fclose(fp);
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED

View File

@ -128,5 +128,5 @@ class ParamsEditor : public SVEventHandler {
ScrollView* sv_window_;
};
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
#endif // TESSERACT_CCMAIN_PARAMSD_H_

View File

@ -690,7 +690,7 @@ void Tesseract::debug_word(PAGE_RES* page_res, const TBOX &selection_box) {
* Blank display of word then redisplay word according to current display mode
* settings
*/
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
namespace tesseract {
#ifndef GRAPHICS_DISABLED
bool Tesseract::word_blank_and_set_display(PAGE_RES_IT* pr_it) {
@ -894,7 +894,7 @@ bool Tesseract::word_display(PAGE_RES_IT* pr_it) {
editor_image_word_bb_color));
return true;
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
/**
* word_dumper()
@ -980,6 +980,6 @@ void Tesseract::blob_feature_display(PAGE_RES* page_res,
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
} // namespace tesseract

View File

@ -566,7 +566,7 @@ class Tesseract : public Wordrec {
SVMenuNode* build_menu_new();
#ifndef GRAPHICS_DISABLED
void pgeditor_main(int width, int height, PAGE_RES* page_res);
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
void process_image_event( // action in image win
const SVEvent& event);
bool process_cmd_win_event( // UI command semantics
@ -582,7 +582,7 @@ class Tesseract : public Wordrec {
bool word_set_display(PAGE_RES_IT* pr_it);
// #ifndef GRAPHICS_DISABLED
bool word_dumper(PAGE_RES_IT* pr_it);
// #endif // GRAPHICS_DISABLED
// #endif // !GRAPHICS_DISABLED
void blob_feature_display(PAGE_RES* page_res, const TBOX& selection_box);
//// reject.h //////////////////////////////////////////////////////////
// make rej map for word
@ -1093,7 +1093,7 @@ class Tesseract : public Wordrec {
"Sets the number of cascading iterations for the Beamsearch in "
"lstm_choice_mode. Note that lstm_choice_mode must be set to "
"a value greater than 0 to produce results.");
double_VAR_H(lstm_rating_coefficient, 5,
double_VAR_H(lstm_rating_coefficient, 5,
"Sets the rating coefficient for the lstm choices. The smaller "
"the coefficient, the better are the ratings for each choice "
"and less information is lost due to the cut off at 0. The "

View File

@ -1092,4 +1092,4 @@ void plot_blob_list(ScrollView* win, // window to draw in
it.data()->plot(win, body_colour, child_colour);
}
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED

View File

@ -846,5 +846,5 @@ void plot_blob_list(ScrollView* win, // window to draw in
BLOBNBOX_LIST *list, // blob list
ScrollView::Color body_colour, // colour to draw
ScrollView::Color child_colour); // colour of child
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
#endif

View File

@ -275,7 +275,7 @@ void TESSLINE::plot(ScrollView* window, ScrollView::Color color,
window->DrawTo(pt->pos.x, pt->pos.y);
} while (pt != loop);
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
// Returns the first non-hidden EDGEPT that has a different src_outline to
// its predecessor, or, if all the same, the lowest indexed point.
@ -512,7 +512,7 @@ void TBLOB::plot(ScrollView* window, ScrollView::Color color,
outline = outline->next)
outline->plot(window, color, child_color);
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
// Computes the center of mass and second moments for the old baseline and
// 2nd moment normalizations. Returns the outline length.
@ -900,7 +900,7 @@ void TWERD::plot(ScrollView* window) {
color = WERD::NextColor(color);
}
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
/**********************************************************************
* divisible_blob

View File

@ -261,7 +261,7 @@ struct TESSLINE {
#ifndef GRAPHICS_DISABLED
void plot(ScrollView* window, ScrollView::Color color,
ScrollView::Color child_color);
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
// Returns the first outline point that has a different src_outline to its
// predecessor, or, if all the same, the lowest indexed point.
@ -366,7 +366,7 @@ struct TBLOB {
#ifndef GRAPHICS_DISABLED
void plot(ScrollView* window, ScrollView::Color color,
ScrollView::Color child_color);
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
int BBArea() const {
int total_area = 0;

View File

@ -254,7 +254,7 @@ class DLLSYM C_OUTLINE:public ELIST_LINK {
// making use of sub-pixel accurate information if available.
void plot_normed(const DENORM& denorm, ScrollView::Color colour,
ScrollView* window) const;
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
C_OUTLINE& operator=(const C_OUTLINE& source);

View File

@ -285,9 +285,10 @@ int ImageData::MemoryUsed() const {
return image_data_.size();
}
#ifndef GRAPHICS_DISABLED
// Draws the data in a new window.
void ImageData::Display() const {
#ifndef GRAPHICS_DISABLED
const int kTextSize = 64;
// Draw the image.
Pix* pix = GetPix();
@ -319,9 +320,10 @@ void ImageData::Display() const {
}
win->Update();
win->Wait();
#endif
}
#endif
// Adds the supplied boxes and transcriptions that correspond to the correct
// page number.
void ImageData::AddBoxes(const GenericVector<TBOX>& boxes,

View File

@ -214,7 +214,7 @@ void ROW::plot( //draw it
word->plot (window); //in rainbow colours
}
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
/**********************************************************************
* ROW::operator=

View File

@ -140,7 +140,7 @@ class ROW:public ELIST_LINK
//draw it
baseline.plot (window, colour);
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
ROW& operator= (const ROW & source);
private:

View File

@ -85,7 +85,7 @@ class PDBLK {
///@param serial serial number
///@param colour colour to draw in
void plot(ScrollView *window, int32_t serial, ScrollView::Color colour);
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
/// assignment
///@param source from this

View File

@ -414,4 +414,4 @@ ScrollView::Color POLY_BLOCK::ColorForPolyBlockType(PolyBlockType type) {
}
return ScrollView::WHITE;
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED

View File

@ -62,7 +62,7 @@ class DLLSYM POLY_BLOCK {
#ifndef GRAPHICS_DISABLED
void fill(ScrollView* window, ScrollView::Color colour);
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
// Returns true if other is inside this.
bool contains(POLY_BLOCK *other);
@ -79,7 +79,7 @@ class DLLSYM POLY_BLOCK {
// Static utility functions to handle the PolyBlockType.
// Returns a color to draw the given type.
static ScrollView::Color ColorForPolyBlockType(PolyBlockType type);
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
private:
ICOORDELT_LIST vertices; // vertices

View File

@ -758,10 +758,11 @@ void WERD_CHOICE::print_state(const char *msg) const {
tprintf("\n");
}
#ifndef GRAPHICS_DISABLED
// Displays the segmentation state of *this (if not the same as the last
// one displayed) and waits for a click in the window.
void WERD_CHOICE::DisplaySegmentation(TWERD* word) {
#ifndef GRAPHICS_DISABLED
// Number of different colors to draw with.
const int kNumColors = 6;
static ScrollView *segm_window = nullptr;
@ -800,9 +801,9 @@ void WERD_CHOICE::DisplaySegmentation(TWERD* word) {
bbox.right(), bbox.bottom());
segm_window->Update();
segm_window->Wait();
#endif
}
#endif // !GRAPHICS_DISABLED
bool EqualIgnoringCaseAndTerminalPunct(const WERD_CHOICE &word1,
const WERD_CHOICE &word2) {

View File

@ -136,7 +136,7 @@ class STATS {
float xscale, // size of one unit
float yscale, // size of one uint
ScrollView::Color colour) const; // colour to draw in
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
private:
int32_t rangemin_ = 0; // min of range

View File

@ -107,7 +107,7 @@ class C_BLOB:public ELIST_LINK
ScrollView::Color blob_colour,
ScrollView::Color child_colour,
ScrollView* window);
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
C_BLOB& operator= (const C_BLOB & source) {
if (!outlines.empty ())

View File

@ -323,7 +323,7 @@ void WERD::plot_rej_blobs(ScrollView* window) {
it.data()->plot(window, ScrollView::GREY, ScrollView::GREY);
}
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
/**
* WERD::shallow_copy()

View File

@ -148,7 +148,7 @@ class WERD : public ELIST2_LINK {
// plot rejected blobs in a rainbow of colours
void plot_rej_blobs(ScrollView* window);
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
// Removes noise from the word by moving small outlines to the rej_cblobs
// list, based on the size_threshold.

View File

@ -220,11 +220,12 @@ void Classify::AdaptiveClassifier(TBLOB *Blob, BLOB_CHOICE_LIST *Choices) {
delete Results;
} /* AdaptiveClassifier */
#ifndef GRAPHICS_DISABLED
// If *win is nullptr, sets it to a new ScrollView() object with title msg.
// Clears the window and draws baselines.
void Classify::RefreshDebugWindow(ScrollView **win, const char *msg,
int y_offset, const TBOX &wbox) {
#ifndef GRAPHICS_DISABLED
const int kSampleSpaceWidth = 500;
if (*win == nullptr) {
*win = new ScrollView(msg, 100, y_offset, kSampleSpaceWidth * 2, 200,
@ -238,9 +239,10 @@ void Classify::RefreshDebugWindow(ScrollView **win, const char *msg,
kSampleSpaceWidth, kBlnXHeight + kBlnBaselineOffset);
(*win)->ZoomToRectangle(wbox.left(), wbox.top(),
wbox.right(), wbox.bottom());
#endif // GRAPHICS_DISABLED
}
#endif // !GRAPHICS_DISABLED
// Learns the given word using its chopped_word, seam_array, denorm,
// box_word, best_state, and correct_text to learn both correctly and
// incorrectly segmented blobs. If fontname is not nullptr, then LearnBlob
@ -279,7 +281,7 @@ void Classify::LearnWord(const char* fontname, WERD_RES* word) {
word->chopped_word->plot(learn_fragmented_word_debug_win_);
ScrollView::Update();
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
for (int ch = 0; ch < word_len; ++ch) {
if (classify_debug_character_fragments) {
@ -404,7 +406,7 @@ void Classify::LearnPieces(const char* fontname, int start, int length,
ScrollView::BLUE, ScrollView::BROWN);
learn_fragments_debug_win_->Update();
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
if (fontname != nullptr) {
classify_norm_method.set_value(character); // force char norm spc 30/11/93
@ -754,8 +756,10 @@ void Classify::InitAdaptedClass(TBLOB *Blob,
if (classify_learning_debug_level >= 1) {
tprintf("Added new class '%s' with class id %d and %d protos.\n",
unicharset.id_to_unichar(ClassId), ClassId, NumFeatures);
#ifndef GRAPHICS_DISABLED
if (classify_learning_debug_level > 1)
DisplayAdaptedChar(Blob, IClass);
#endif
}
if (IsEmptyAdaptedClass(Class))
@ -920,8 +924,10 @@ void Classify::AdaptToChar(TBLOB* Blob, CLASS_ID ClassId, int FontinfoId,
if (classify_learning_debug_level >= 1) {
tprintf("Found poor match to temp config %d = %4.1f%%.\n",
int_result.config, int_result.rating * 100.0);
#ifndef GRAPHICS_DISABLED
if (classify_learning_debug_level > 2)
DisplayAdaptedChar(Blob, IClass);
#endif
}
NewTempConfigId =
MakeNewTemporaryConfig(adaptive_templates, ClassId, FontinfoId,
@ -942,8 +948,9 @@ void Classify::AdaptToChar(TBLOB* Blob, CLASS_ID ClassId, int FontinfoId,
}
} /* AdaptToChar */
void Classify::DisplayAdaptedChar(TBLOB* blob, INT_CLASS_STRUCT* int_class) {
#ifndef GRAPHICS_DISABLED
void Classify::DisplayAdaptedChar(TBLOB* blob, INT_CLASS_STRUCT* int_class) {
INT_FX_RESULT_STRUCT fx_info;
GenericVector<INT_FEATURE_STRUCT> bl_features;
TrainingSample* sample =
@ -970,9 +977,10 @@ void Classify::DisplayAdaptedChar(TBLOB* blob, INT_CLASS_STRUCT* int_class) {
}
delete sample;
#endif
}
#endif
/**
* This routine adds the result of a classification into
* Results. If the new rating is much worse than the current
@ -2147,6 +2155,8 @@ void Classify::SetAdaptiveThreshold(float Threshold) {
ClipToRange<int>(255 * Threshold, 0, 255));
} /* SetAdaptiveThreshold */
#ifndef GRAPHICS_DISABLED
/*---------------------------------------------------------------------------*/
/**
* This routine displays debug information for the best config
@ -2160,7 +2170,6 @@ void Classify::SetAdaptiveThreshold(float Threshold) {
void Classify::ShowBestMatchFor(int shape_id,
const INT_FEATURE_STRUCT* features,
int num_features) {
#ifndef GRAPHICS_DISABLED
uint32_t config_mask;
if (UnusedClassIdIn(PreTrainedTemplates, shape_id)) {
tprintf("No built-in templates for class/shape %d\n", shape_id);
@ -2187,9 +2196,10 @@ void Classify::ShowBestMatchFor(int shape_id,
classify_adapt_feature_threshold, matcher_debug_flags,
matcher_debug_separate_windows);
UpdateMatchDisplay();
#endif // GRAPHICS_DISABLED
} /* ShowBestMatchFor */
#endif // !GRAPHICS_DISABLED
// Returns a string for the classifier class_id: either the corresponding
// unicharset debug_str or the shape_table_ debug str.
STRING Classify::ClassIDToDebugStr(const INT_TEMPLATES_STRUCT* templates,

View File

@ -162,16 +162,18 @@ void RenderIntProto(ScrollView *window,
INT_CLASS Class,
PROTO_ID ProtoId,
ScrollView::Color color);
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
/*-----------------------------------------------------------------------------
Global Data Definitions and Declarations
-----------------------------------------------------------------------------*/
#ifndef GRAPHICS_DISABLED
/* global display lists used to display proto and feature match information*/
static ScrollView* IntMatchWindow = nullptr;
static ScrollView* FeatureDisplayWindow = nullptr;
static ScrollView* ProtoDisplayWindow = nullptr;
#endif
/*-----------------------------------------------------------------------------
Variables
@ -1751,4 +1753,4 @@ void InitFeatureDisplayWindowIfReqd() {
ScrollView* CreateFeatureSpaceWindow(const char* name, int xpos, int ypos) {
return new ScrollView(name, xpos, ypos, 520, 520, 260, 260, true);
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED

View File

@ -258,6 +258,6 @@ void InitFeatureDisplayWindowIfReqd();
// Creates a window of the appropriate size for displaying elements
// in feature space.
ScrollView* CreateFeatureSpaceWindow(const char* name, int xpos, int ypos);
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
#endif

View File

@ -88,6 +88,8 @@ const UNICHARSET& ShapeClassifier::GetUnicharset() const {
return GetShapeTable()->unicharset();
}
#ifndef GRAPHICS_DISABLED
// Visual debugger classifies the given sample, displays the results and
// solicits user input to display other classifications. Returns when
// the user has finished with debugging the sample.
@ -96,7 +98,6 @@ const UNICHARSET& ShapeClassifier::GetUnicharset() const {
void ShapeClassifier::DebugDisplay(const TrainingSample& sample,
Pix* page_pix,
UNICHAR_ID unichar_id) {
#ifndef GRAPHICS_DISABLED
static ScrollView* terminator = nullptr;
if (terminator == nullptr) {
terminator = new ScrollView("XIT", 0, 0, 50, 50, 50, 50, true);
@ -152,9 +153,10 @@ void ShapeClassifier::DebugDisplay(const TrainingSample& sample,
ev_type != SVET_CLICK && ev_type != SVET_DESTROY);
} while (ev_type != SVET_CLICK && ev_type != SVET_DESTROY);
delete debug_win;
#endif // GRAPHICS_DISABLED
}
#endif // !GRAPHICS_DISABLED
// Displays classification as the given shape_id. Creates as many windows
// as it feels fit, using index as a guide for placement. Adds any created
// windows to the windows output and returns a new index that may be used

View File

@ -1,11 +1,8 @@
// Copyright 2011 Google Inc. All Rights Reserved.
// Author: rays@google.com (Ray Smith)
///////////////////////////////////////////////////////////////////////
// File: shapeclassifier.h
// Description: Base interface class for classifiers that return a
// shape index.
// Author: Ray Smith
// Created: Tue Sep 13 11:26:32 PDT 2011
//
// (C) Copyright 2011, Google Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
@ -93,8 +90,8 @@ class ShapeClassifier {
// the user has finished with debugging the sample.
// Probably doesn't need to be overridden if the subclass provides
// DisplayClassifyAs.
virtual void DebugDisplay(const TrainingSample& sample, Pix* page_pix,
UNICHAR_ID unichar_id);
void DebugDisplay(const TrainingSample& sample, Pix* page_pix,
UNICHAR_ID unichar_id);
// Displays classification as the given unichar_id. Creates as many windows

View File

@ -1,10 +1,7 @@
// Copyright 2011 Google Inc. All Rights Reserved.
// Author: rays@google.com (Ray Smith)
///////////////////////////////////////////////////////////////////////
// File: tessclassifier.cpp
// Description: Tesseract implementation of a ShapeClassifier.
// Author: Ray Smith
// Created: Tue Nov 22 14:16:25 PST 2011
//
// (C) Copyright 2011, Google Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
@ -77,8 +74,10 @@ int TessClassifier::DisplayClassifyAs(
tprintf("No built-in templates for class/shape %d\n", shape_id);
return index;
}
#ifndef GRAPHICS_DISABLED
classify_->ShowBestMatchFor(shape_id, sample.features(),
sample.num_features());
#endif
return index;
}

View File

@ -312,16 +312,18 @@ Pix* TrainingSample::RenderToPix(const UNICHARSET* unicharset) const {
return pix;
}
#ifndef GRAPHICS_DISABLED
// Displays the features in the given window with the given color.
void TrainingSample::DisplayFeatures(ScrollView::Color color,
ScrollView* window) const {
#ifndef GRAPHICS_DISABLED
for (uint32_t f = 0; f < num_features_; ++f) {
RenderIntFeature(window, &features_[f], color);
}
#endif // GRAPHICS_DISABLED
}
#endif // !GRAPHICS_DISABLED
// Returns a pix of the original sample image. The pix is padded all round
// by padding wherever possible.
// The returned Pix must be pixDestroyed after use.

View File

@ -4,7 +4,6 @@
// and pulls in random data to fill out-of-input inputs.
// Output is therefore same size as its input, but deeper.
// Author: Ray Smith
// Created: Tue Mar 18 16:56:06 PST 2014
//
// (C) Copyright 2014, Google Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
@ -18,6 +17,10 @@
// limitations under the License.
///////////////////////////////////////////////////////////////////////
#ifdef HAVE_CONFIG_H
#include "config_auto.h"
#endif
#include "convolve.h"
#include "networkscratch.h"
@ -76,7 +79,9 @@ void Convolve::Forward(bool debug, const NetworkIO& input,
}
}
} while (dest_index.Increment());
#ifndef GRAPHICS_DISABLED
if (debug) DisplayForward(*output);
#endif
}
// Runs backward propagation of errors on the deltas line.

View File

@ -15,6 +15,10 @@
// limitations under the License.
///////////////////////////////////////////////////////////////////////
#ifdef HAVE_CONFIG_H
#include "config_auto.h"
#endif
#include "fullyconnected.h"
#ifdef _OPENMP
@ -165,7 +169,9 @@ void FullyConnected::Forward(bool debug, const NetworkIO& input,
tprintf("F Output:%s\n", name_.c_str());
output->Print(10);
#endif
#ifndef GRAPHICS_DISABLED
if (debug) DisplayForward(*output);
#endif
}
// Components of Forward so FullyConnected can be reused inside LSTM.
@ -220,7 +226,9 @@ void FullyConnected::ForwardTimeStep(const int8_t* i_input,
bool FullyConnected::Backward(bool debug, const NetworkIO& fwd_deltas,
NetworkScratch* scratch,
NetworkIO* back_deltas) {
#ifndef GRAPHICS_DISABLED
if (debug) DisplayBackward(fwd_deltas);
#endif
back_deltas->Resize(fwd_deltas, ni_);
GenericVector<NetworkScratch::FloatVec> errors;
errors.init_to_size(kNumThreads, NetworkScratch::FloatVec());

View File

@ -15,6 +15,10 @@
// limitations under the License.
///////////////////////////////////////////////////////////////////////
#ifdef HAVE_CONFIG_H
#include "config_auto.h"
#endif
#include "lstm.h"
#ifdef _OPENMP
@ -432,7 +436,9 @@ void LSTM::Forward(bool debug, const NetworkIO& input,
tprintf("Output:%s\n", name_.c_str());
output->Print(10);
#endif
#ifndef GRAPHICS_DISABLED
if (debug) DisplayForward(*output);
#endif
}
// Runs backward propagation of errors on the deltas line.
@ -440,7 +446,9 @@ void LSTM::Forward(bool debug, const NetworkIO& input,
bool LSTM::Backward(bool debug, const NetworkIO& fwd_deltas,
NetworkScratch* scratch,
NetworkIO* back_deltas) {
#ifndef GRAPHICS_DISABLED
if (debug) DisplayBackward(fwd_deltas);
#endif
back_deltas->ResizeToMap(fwd_deltas.int_mode(), input_map_, ni_);
// ======Scratch space.======
// Output errors from deltas with recurrence from sourceerr.

View File

@ -322,7 +322,9 @@ bool LSTMRecognizer::RecognizeLine(const ImageData& image_data, bool invert,
if (debug) {
GenericVector<int> labels, coords;
LabelsFromOutputs(*outputs, &labels, &coords);
#ifndef GRAPHICS_DISABLED
DisplayForward(*inputs, labels, coords, "LSTMForward", &debug_win_);
#endif
DebugActivationPath(*outputs, labels, coords);
}
return true;
@ -343,6 +345,8 @@ STRING LSTMRecognizer::DecodeLabels(const GenericVector<int>& labels) {
return result;
}
#ifndef GRAPHICS_DISABLED
// Displays the forward results in a window with the characters and
// boundaries as determined by the labels and label_coords.
void LSTMRecognizer::DisplayForward(const NetworkIO& inputs,
@ -350,13 +354,11 @@ void LSTMRecognizer::DisplayForward(const NetworkIO& inputs,
const GenericVector<int>& label_coords,
const char* window_name,
ScrollView** window) {
#ifndef GRAPHICS_DISABLED // do nothing if there's no graphics
Pix* input_pix = inputs.ToPix();
Network::ClearWindow(false, window_name, pixGetWidth(input_pix),
pixGetHeight(input_pix), window);
int line_height = Network::DisplayImage(input_pix, *window);
DisplayLSTMOutput(labels, label_coords, line_height, *window);
#endif // GRAPHICS_DISABLED
}
// Displays the labels and cuts at the corresponding xcoords.
@ -364,7 +366,6 @@ void LSTMRecognizer::DisplayForward(const NetworkIO& inputs,
void LSTMRecognizer::DisplayLSTMOutput(const GenericVector<int>& labels,
const GenericVector<int>& xcoords,
int height, ScrollView* window) {
#ifndef GRAPHICS_DISABLED // do nothing if there's no graphics
int x_scale = network_->XScaleFactor();
window->TextAttributes("Arial", height / 4, false, false, false);
int end = 1;
@ -383,9 +384,10 @@ void LSTMRecognizer::DisplayLSTMOutput(const GenericVector<int>& labels,
window->Line(xpos, 0, xpos, height * 3 / 2);
}
window->Update();
#endif // GRAPHICS_DISABLED
}
#endif // !GRAPHICS_DISABLED
// Prints debug output detailing the activation path that is implied by the
// label_coords.
void LSTMRecognizer::DebugActivationPath(const NetworkIO& outputs,

View File

@ -283,31 +283,28 @@ double Network::Random(double range) {
return randomizer_->SignedRand(range);
}
#ifndef GRAPHICS_DISABLED
// === Debug image display methods. ===
// Displays the image of the matrix to the forward window.
void Network::DisplayForward(const NetworkIO& matrix) {
#ifndef GRAPHICS_DISABLED // do nothing if there's no graphics
Pix* image = matrix.ToPix();
ClearWindow(false, name_.c_str(), pixGetWidth(image),
pixGetHeight(image), &forward_win_);
DisplayImage(image, forward_win_);
forward_win_->Update();
#endif // GRAPHICS_DISABLED
}
// Displays the image of the matrix to the backward window.
void Network::DisplayBackward(const NetworkIO& matrix) {
#ifndef GRAPHICS_DISABLED // do nothing if there's no graphics
Pix* image = matrix.ToPix();
STRING window_name = name_ + "-back";
ClearWindow(false, window_name.c_str(), pixGetWidth(image),
pixGetHeight(image), &backward_win_);
DisplayImage(image, backward_win_);
backward_win_->Update();
#endif // GRAPHICS_DISABLED
}
#ifndef GRAPHICS_DISABLED
// Creates the window if needed, otherwise clears it.
void Network::ClearWindow(bool tess_coords, const char* window_name,
int width, int height, ScrollView** window) {
@ -338,6 +335,6 @@ int Network::DisplayImage(Pix* pix, ScrollView* window) {
pixDestroy(&pix);
return height;
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
} // namespace tesseract.

View File

@ -2,7 +2,6 @@
// File: parallel.cpp
// Description: Runs networks in parallel on the same input.
// Author: Ray Smith
// Created: Thu May 02 08:06:06 PST 2013
//
// (C) Copyright 2013, Google Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
@ -16,6 +15,10 @@
// limitations under the License.
///////////////////////////////////////////////////////////////////////
#ifdef HAVE_CONFIG_H
#include "config_auto.h"
#endif
#include "parallel.h"
#ifdef _OPENMP
@ -100,9 +103,11 @@ void Parallel::Forward(bool debug, const NetworkIO& input,
out_offset = output->CopyPacking(*result, out_offset);
}
}
#ifndef GRAPHICS_DISABLED
if (parallel_debug) {
DisplayForward(*output);
}
#endif
}
// Runs backward propagation of errors on the deltas line.
@ -113,7 +118,9 @@ bool Parallel::Backward(bool debug, const NetworkIO& fwd_deltas,
// If this parallel is a replicator of convolvers, or holds a 1-d LSTM pair,
// or a 2-d LSTM quad, do debug locally, and don't pass the flag on.
if (debug && type_ != NT_PARALLEL) {
#ifndef GRAPHICS_DISABLED
DisplayBackward(fwd_deltas);
#endif
debug = false;
}
int stack_size = stack_.size();

View File

@ -154,10 +154,11 @@ bool AlignedBlob::WithinTestRegion(int detail_level, int x, int y) {
y <= textord_testregion_top && y >= textord_testregion_bottom;
}
#ifndef GRAPHICS_DISABLED
// Display the tab codes of the BLOBNBOXes in this grid.
ScrollView* AlignedBlob::DisplayTabs(const char* window_name,
ScrollView* tab_win) {
#ifndef GRAPHICS_DISABLED
if (tab_win == nullptr)
tab_win = MakeWindow(0, 50, window_name);
// For every tab in the grid, display it.
@ -196,10 +197,11 @@ ScrollView* AlignedBlob::DisplayTabs(const char* window_name,
}
}
tab_win->Update();
#endif
return tab_win;
}
#endif // !GRAPHICS_DISABLED
// Helper returns true if the total number of line_crossings of all the blobs
// in the list is at least 2.
static bool AtLeast2LineCrossings(BLOBNBOX_CLIST* blobs) {

View File

@ -577,10 +577,11 @@ void BaselineBlock::FitBaselineSplines(bool enable_splines,
restore_underlined_blobs(block_);
}
#ifndef GRAPHICS_DISABLED
// Draws the (straight) baselines and final blobs colored according to
// what was discarded as noise and what is associated with each row.
void BaselineBlock::DrawFinalRows(const ICOORD& page_tr) {
#ifndef GRAPHICS_DISABLED
if (non_text_block_) return;
double gradient = tan(skew_angle_);
FCOORD rotation(1.0f, 0.0f);
@ -601,9 +602,10 @@ void BaselineBlock::DrawFinalRows(const ICOORD& page_tr) {
if (block_->blobs.length() > 0)
tprintf("%d blobs discarded as noise\n", block_->blobs.length());
draw_meanlines(block_, gradient, left_edge, ScrollView::WHITE, rotation);
#endif
}
#endif // !GRAPHICS_DISABLED
void BaselineBlock::DrawPixSpline(Pix* pix_in) {
if (non_text_block_) return;
TO_ROW_IT row_it = block_->get_rows();
@ -856,9 +858,11 @@ void BaselineDetect::ComputeBaselineSplinesAndXheights(const ICOORD& page_tr,
if (enable_splines)
bl_block->PrepareForSplineFitting(page_tr, remove_noise);
bl_block->FitBaselineSplines(enable_splines, show_final_rows, textord);
#ifndef GRAPHICS_DISABLED
if (show_final_rows) {
bl_block->DrawFinalRows(page_tr);
}
#endif
}
}

View File

@ -583,25 +583,24 @@ template<class G> class TabEventHandler : public SVEventHandler {
G* grid_;
};
#ifndef GRAPHICS_DISABLED
// Make a window of an appropriate size to display things in the grid.
// Position the window at the given x,y.
template<class BBC, class BBC_CLIST, class BBC_C_IT>
ScrollView* BBGrid<BBC, BBC_CLIST, BBC_C_IT>::MakeWindow(
int x, int y, const char* window_name) {
ScrollView* tab_win = nullptr;
#ifndef GRAPHICS_DISABLED
tab_win = new ScrollView(window_name, x, y,
tright_.x() - bleft_.x(),
tright_.y() - bleft_.y(),
tright_.x() - bleft_.x(),
tright_.y() - bleft_.y(),
true);
auto tab_win = new ScrollView(window_name, x, y,
tright_.x() - bleft_.x(),
tright_.y() - bleft_.y(),
tright_.x() - bleft_.x(),
tright_.y() - bleft_.y(),
true);
auto* handler =
new TabEventHandler<BBGrid<BBC, BBC_CLIST, BBC_C_IT> >(this);
tab_win->AddEventHandler(handler);
tab_win->Pen(ScrollView::GREY);
tab_win->Rectangle(0, 0, tright_.x() - bleft_.x(), tright_.y() - bleft_.y());
#endif
return tab_win;
}
@ -611,7 +610,6 @@ ScrollView* BBGrid<BBC, BBC_CLIST, BBC_C_IT>::MakeWindow(
// ScrollView::Color BBC::BoxColor() const.
template<class BBC, class BBC_CLIST, class BBC_C_IT>
void BBGrid<BBC, BBC_CLIST, BBC_C_IT>::DisplayBoxes(ScrollView* tab_win) {
#ifndef GRAPHICS_DISABLED
tab_win->Pen(ScrollView::BLUE);
tab_win->Brush(ScrollView::NONE);
@ -630,9 +628,10 @@ void BBGrid<BBC, BBC_CLIST, BBC_C_IT>::DisplayBoxes(ScrollView* tab_win) {
tab_win->Rectangle(left_x, bottom_y, right_x, top_y);
}
tab_win->Update();
#endif
}
#endif // !GRAPHICS_DISABLED
// ASSERT_HOST that every cell contains no more than one copy of each entry.
template<class BBC, class BBC_CLIST, class BBC_C_IT>
void BBGrid<BBC, BBC_CLIST, BBC_C_IT>::AssertNoDuplicates() {

View File

@ -112,7 +112,7 @@ Pix* CCNonTextDetect::ComputeNonTextMask(bool debug, Pix* photo_map,
if (debug) {
win = MakeWindow(0, 400, "Photo Mask Blobs");
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
// Large and medium blobs are not text if they overlap with "a lot" of small
// blobs.
MarkAndDeleteNonTextBlobs(&blob_block->large_blobs,
@ -137,12 +137,12 @@ Pix* CCNonTextDetect::ComputeNonTextMask(bool debug, Pix* photo_map,
if (debug) {
#ifndef GRAPHICS_DISABLED
win->Update();
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
pixWrite("junkccphotomask.png", pix, IFF_PNG);
#ifndef GRAPHICS_DISABLED
delete win->AwaitEvent(SVET_DESTROY);
delete win;
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
}
return pix;
}
@ -262,7 +262,7 @@ void CCNonTextDetect::MarkAndDeleteNonTextBlobs(BLOBNBOX_LIST* blobs,
#ifndef GRAPHICS_DISABLED
if (win != nullptr)
blob->plot(win, ok_color, ok_color);
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
} else {
if (noise_density_->AnyZeroInRect(box)) {
// There is a danger that the bounding box may overlap real text, so
@ -286,7 +286,7 @@ void CCNonTextDetect::MarkAndDeleteNonTextBlobs(BLOBNBOX_LIST* blobs,
#ifndef GRAPHICS_DISABLED
if (win != nullptr)
blob->plot(win, ScrollView::RED, ScrollView::RED);
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
// It is safe to delete the cblob now, as it isn't used by the grid
// or BlobOverlapsTooMuch, and the BLOBNBOXes will go away with the
// dead_blobs list.

View File

@ -53,17 +53,21 @@ const double kMinGutterWidthGrid = 0.5;
// adding noise blobs.
const double kMaxDistToPartSizeRatio = 1.5;
#ifndef GRAPHICS_DISABLED
static BOOL_VAR(textord_tabfind_show_initial_partitions,
false, "Show partition bounds");
static BOOL_VAR(textord_tabfind_show_reject_blobs,
false, "Show blobs rejected as noise");
static INT_VAR(textord_tabfind_show_partitions, 0,
"Show partition bounds, waiting if >1");
static BOOL_VAR(textord_tabfind_show_columns, false, "Show column bounds");
static BOOL_VAR(textord_tabfind_show_blocks, false, "Show final block bounds");
"Show partition bounds, waiting if >1 (ScrollView)");
static BOOL_VAR(textord_tabfind_show_columns, false, "Show column bounds (ScrollView)");
static BOOL_VAR(textord_tabfind_show_blocks, false, "Show final block bounds (ScrollView)");
#endif
static BOOL_VAR(textord_tabfind_find_tables, true, "run table detection");
#ifndef GRAPHICS_DISABLED
ScrollView* ColumnFinder::blocks_win_ = nullptr;
#endif
// Gridsize is an estimate of the text size in the image. A suitable value
// is in TO_BLOCK::line_size after find_components has been used to make
@ -152,7 +156,7 @@ void ColumnFinder::SetupAndFilterNoise(PageSegMode pageseg_mode,
input_blobs_win_ = MakeWindow(0, 0, "Filtered Input Blobs");
input_block->plot_graded_blobs(input_blobs_win_);
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
SetBlockRuleEdges(input_block);
pixDestroy(&nontext_map_);
// Run a preliminary strokewidth neighbour detection on the medium blobs.
@ -381,7 +385,7 @@ int ColumnFinder::FindBlocks(PageSegMode pageseg_mode, Pix* scaled_color,
ScrollView* rej_win = MakeWindow(500, 300, "Rejected blobs");
input_block->plot_graded_blobs(rej_win);
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
InsertBlobsToGrid(false, false, &image_bblobs_, this);
InsertBlobsToGrid(true, true, &input_block->blobs, this);
@ -402,12 +406,13 @@ int ColumnFinder::FindBlocks(PageSegMode pageseg_mode, Pix* scaled_color,
part_grid_.GridFindMargins(best_columns_);
SetPartitionTypes();
}
#ifndef GRAPHICS_DISABLED
if (textord_tabfind_show_initial_partitions) {
ScrollView* part_win = MakeWindow(100, 300, "InitialPartitions");
part_grid_.DisplayBoxes(part_win);
DisplayTabVectors(part_win);
}
#endif
if (!PSM_SPARSE(pageseg_mode)) {
if (equation_detect_) {
equation_detect_->FindEquationParts(&part_grid_, best_columns_);
@ -446,7 +451,7 @@ int ColumnFinder::FindBlocks(PageSegMode pageseg_mode, Pix* scaled_color,
}
}
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
part_grid_.AssertNoDuplicates();
}
// Ownership of the ColPartitions moves from part_sets_ to part_grid_ here,
@ -466,7 +471,9 @@ int ColumnFinder::FindBlocks(PageSegMode pageseg_mode, Pix* scaled_color,
blocks->length(), to_blocks->length());
}
#ifndef GRAPHICS_DISABLED
DisplayBlocks(blocks);
#endif
RotateAndReskewBlocks(input_is_rtl, to_blocks);
int result = 0;
#ifndef GRAPHICS_DISABLED
@ -488,7 +495,7 @@ int ColumnFinder::FindBlocks(PageSegMode pageseg_mode, Pix* scaled_color,
delete event;
} while (waiting);
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
return result;
}
@ -505,9 +512,10 @@ void ColumnFinder::SetEquationDetect(EquationDetectBase* detect) {
//////////////// PRIVATE CODE /////////////////////////
#ifndef GRAPHICS_DISABLED
// Displays the blob and block bounding boxes in a window called Blocks.
void ColumnFinder::DisplayBlocks(BLOCK_LIST* blocks) {
#ifndef GRAPHICS_DISABLED
if (textord_tabfind_show_blocks) {
if (blocks_win_ == nullptr)
blocks_win_ = MakeWindow(700, 300, "Blocks");
@ -525,13 +533,11 @@ void ColumnFinder::DisplayBlocks(BLOCK_LIST* blocks) {
}
blocks_win_->Update();
}
#endif
}
// Displays the column edges at each grid y coordinate defined by
// best_columns_.
void ColumnFinder::DisplayColumnBounds(PartSetVector* sets) {
#ifndef GRAPHICS_DISABLED
ScrollView* col_win = MakeWindow(50, 300, "Columns");
DisplayBoxes(col_win);
col_win->Pen(textord_debug_printable ? ScrollView::BLUE : ScrollView::GREEN);
@ -540,9 +546,10 @@ void ColumnFinder::DisplayColumnBounds(PartSetVector* sets) {
if (columns != nullptr)
columns->DisplayColumnEdges(i * gridsize_, (i + 1) * gridsize_, col_win);
}
#endif
}
#endif // !GRAPHICS_DISABLED
// Sets up column_sets_ (the determined column layout at each horizontal
// slice). Returns false if the page is empty.
bool ColumnFinder::MakeColumns(bool single_column) {
@ -589,9 +596,11 @@ bool ColumnFinder::MakeColumns(bool single_column) {
if (has_columns) {
// Divide the page into sections of uniform column layout.
bool any_multi_column = AssignColumns(part_sets);
#ifndef GRAPHICS_DISABLED
if (textord_tabfind_show_columns) {
DisplayColumnBounds(&part_sets);
}
#endif
ComputeMeanColumnGap(any_multi_column);
}
for (int i = 0; i < part_sets.size(); ++i) {

View File

@ -1787,7 +1787,7 @@ ScrollView::Color ColPartition::BoxColor() const {
return BLOBNBOX::TextlineColor(blob_type_, flow_);
return POLY_BLOCK::ColorForPolyBlockType(type_);
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
// Keep in sync with BlobRegionType.
static char kBlobTypes[BRT_COUNT + 1] = "NHSRIUVT";

View File

@ -687,7 +687,7 @@ class ColPartition : public ELIST2_LINK {
#ifndef GRAPHICS_DISABLED
// Provides a color for BBGrid to draw the rectangle.
ScrollView::Color BoxColor() const;
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
// Prints debug information on this.
void Print() const;

View File

@ -381,19 +381,21 @@ void ColPartitionSet::GetColumnBoxes(int y_bottom, int y_top,
}
}
#ifndef GRAPHICS_DISABLED
// Display the edges of the columns at the given y coords.
void ColPartitionSet::DisplayColumnEdges(int y_bottom, int y_top,
ScrollView* win) {
#ifndef GRAPHICS_DISABLED
ColPartition_IT it(&parts_);
for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
ColPartition* part = it.data();
win->Line(part->LeftAtY(y_top), y_top, part->LeftAtY(y_bottom), y_bottom);
win->Line(part->RightAtY(y_top), y_top, part->RightAtY(y_bottom), y_bottom);
}
#endif // GRAPHICS_DISABLED
}
#endif // !GRAPHICS_DISABLED
// Return the ColumnSpanningType that best explains the columns overlapped
// by the given coords(left,right,y), with the given margins.
// Also return the first and last column index touched by the coords and

View File

@ -34,12 +34,13 @@ BOOL_VAR (textord_show_fixed_cuts, false,
ScrollView* to_win = nullptr;
#ifndef GRAPHICS_DISABLED
/**********************************************************************
* create_to_win
*
* Create the to window used to show the fit.
**********************************************************************/
#ifndef GRAPHICS_DISABLED
ScrollView* create_to_win(ICOORD page_tr) {
if (to_win != nullptr) return to_win;
@ -414,4 +415,4 @@ void plot_row_cells( //draw words
}
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED

View File

@ -1354,10 +1354,12 @@ void ImageFind::FindImagePartitions(Pix* image_pix, const FCOORD& rotation,
boxaDestroy(&boxa);
pixaDestroy(&pixa);
DeleteSmallImages(part_grid);
#ifndef GRAPHICS_DISABLED
if (textord_tabfind_show_images) {
ScrollView* images_win_ = part_grid->MakeWindow(1000, 400, "With Images");
part_grid->DisplayBoxes(images_win_);
}
#endif
}

View File

@ -37,7 +37,11 @@
namespace tesseract {
#ifndef GRAPHICS_DISABLED
static INT_VAR(textord_tabfind_show_strokewidths, 0, "Show stroke widths (ScrollView)");
#else
static INT_VAR(textord_tabfind_show_strokewidths, 0, "Show stroke widths");
#endif
static BOOL_VAR(textord_tabfind_only_strokewidths, false, "Only run stroke widths");
/** Allowed proportional change in stroke width to be the same font. */
@ -123,7 +127,7 @@ StrokeWidth::~StrokeWidth() {
if (widths_win_ != nullptr) {
#ifndef GRAPHICS_DISABLED
delete widths_win_->AwaitEvent(SVET_DESTROY);
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
if (textord_tabfind_only_strokewidths)
exit(0);
delete widths_win_;
@ -319,7 +323,7 @@ void StrokeWidth::RemoveLineResidue(ColPartition_LIST* big_part_list) {
leaders_win_->Rectangle(box.left(), box.bottom(),
box.right(), box.top());
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
ColPartition::MakeBigPartition(bbox, big_part_list);
}
}
@ -359,11 +363,13 @@ void StrokeWidth::GradeBlobsIntoPartitions(
}
FindTextlineFlowDirection(pageseg_mode, false);
projection_->ConstructProjection(block, rerotation, nontext_map_);
#ifndef GRAPHICS_DISABLED
if (textord_tabfind_show_strokewidths) {
ScrollView* line_blobs_win = MakeWindow(0, 0, "Initial textline Blobs");
projection_->PlotGradedBlobs(&block->blobs, line_blobs_win);
projection_->PlotGradedBlobs(&block->small_blobs, line_blobs_win);
}
#endif
projection_->MoveNonTextlineBlobs(&block->blobs, &block->noise_blobs);
projection_->MoveNonTextlineBlobs(&block->small_blobs, &block->noise_blobs);
// Clear and re Insert to take advantage of the removed diacritics.
@ -476,9 +482,11 @@ void StrokeWidth::FindLeadersAndMarkNoise(TO_BLOCK* block,
delete part;
}
}
#ifndef GRAPHICS_DISABLED
if (textord_tabfind_show_strokewidths) {
leaders_win_ = DisplayGoodBlobs("LeaderNeighbours", 0, 0);
}
#endif
// Move any non-leaders from the small to the blobs list, as they are
// most likely dashes or broken characters.
BLOBNBOX_IT blob_it(&block->blobs);
@ -554,7 +562,7 @@ void StrokeWidth::MarkLeaderNeighbours(const ColPartition* part,
leaders_win_->Rectangle(blob_box.left(), blob_box.bottom(),
blob_box.right(), blob_box.top());
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
}
}
@ -823,10 +831,12 @@ void StrokeWidth::FindTextlineFlowDirection(PageSegMode pageseg_mode,
SetNeighbourFlows(bbox);
}
}
#ifndef GRAPHICS_DISABLED
if ((textord_tabfind_show_strokewidths && display_if_debugging) ||
textord_tabfind_show_strokewidths > 1) {
initial_widths_win_ = DisplayGoodBlobs("InitialStrokewidths", 400, 0);
}
#endif
// Improve flow direction with neighbours.
gsearch.StartFullSearch();
while ((bbox = gsearch.NextFullSearch()) != nullptr) {
@ -842,10 +852,12 @@ void StrokeWidth::FindTextlineFlowDirection(PageSegMode pageseg_mode,
while ((bbox = gsearch.NextFullSearch()) != nullptr) {
SmoothNeighbourTypes(pageseg_mode, true, bbox);
}
#ifndef GRAPHICS_DISABLED
if ((textord_tabfind_show_strokewidths && display_if_debugging) ||
textord_tabfind_show_strokewidths > 1) {
widths_win_ = DisplayGoodBlobs("ImprovedStrokewidths", 800, 0);
}
#endif
}
// Sets the neighbours and good_stroke_neighbours members of the blob by
@ -1252,11 +1264,13 @@ PartitionFindResult StrokeWidth::FindInitialPartitions(
FCOORD* skew_angle) {
if (!FindingHorizontalOnly(pageseg_mode)) FindVerticalTextChains(part_grid);
if (!FindingVerticalOnly(pageseg_mode)) FindHorizontalTextChains(part_grid);
#ifndef GRAPHICS_DISABLED
if (textord_tabfind_show_strokewidths) {
chains_win_ = MakeWindow(0, 400, "Initial text chains");
part_grid->DisplayBoxes(chains_win_);
projection_->DisplayProjection();
}
#endif
if (find_problems) {
// TODO(rays) Do something to find skew, set skew_angle and return if there
// is some.
@ -1277,11 +1291,13 @@ PartitionFindResult StrokeWidth::FindInitialPartitions(
diacritic_blobs)) {
return PFR_NOISE;
}
#ifndef GRAPHICS_DISABLED
if (textord_tabfind_show_strokewidths) {
textlines_win_ = MakeWindow(400, 400, "GoodTextline blobs");
part_grid->DisplayBoxes(textlines_win_);
diacritics_win_ = DisplayDiacritics("Diacritics", 0, 0, block);
}
#endif
PartitionRemainingBlobs(pageseg_mode, part_grid);
part_grid->SplitOverlappingPartitions(big_parts);
EasyMerges(part_grid);
@ -1292,10 +1308,12 @@ PartitionFindResult StrokeWidth::FindInitialPartitions(
// Now eliminate strong stuff in a sea of the opposite.
while (part_grid->GridSmoothNeighbours(BTFT_STRONG_CHAIN, nontext_map_,
grid_box, rerotation));
#ifndef GRAPHICS_DISABLED
if (textord_tabfind_show_strokewidths) {
smoothed_win_ = MakeWindow(800, 400, "Smoothed blobs");
part_grid->DisplayBoxes(smoothed_win_);
}
#endif
return PFR_OK;
}
@ -1315,10 +1333,12 @@ bool StrokeWidth::DetectAndRemoveNoise(int pre_overlap, const TBOX& grid_box,
if (post_overlap > pre_overlap * kNoiseOverlapGrowthFactor &&
post_overlap > grid_box.area() * kNoiseOverlapAreaFactor) {
// This is noisy enough to fix.
#ifndef GRAPHICS_DISABLED
if (textord_tabfind_show_strokewidths) {
ScrollView* noise_win = MakeWindow(1000, 500, "Noise Areas");
noise_grid->DisplayBoxes(noise_win);
}
#endif
part_grid->DeleteNonLeaderParts();
BLOBNBOX_IT blob_it(&block->noise_blobs);
ColPartitionGridSearch rsearch(noise_grid);
@ -1919,14 +1939,14 @@ bool StrokeWidth::NoNoiseInBetween(const TBOX& box1, const TBOX& box2) const {
nontext_map_);
}
#ifndef GRAPHICS_DISABLED
/** Displays the blobs colored according to the number of good neighbours
* and the vertical/horizontal flow.
*/
ScrollView* StrokeWidth::DisplayGoodBlobs(const char* window_name,
int x, int y) {
ScrollView* window = nullptr;
#ifndef GRAPHICS_DISABLED
window = MakeWindow(x, y, window_name);
auto window = MakeWindow(x, y, window_name);
// For every blob in the grid, display it.
window->Brush(ScrollView::NONE);
@ -1959,26 +1979,21 @@ ScrollView* StrokeWidth::DisplayGoodBlobs(const char* window_name,
window->Rectangle(left_x, bottom_y, right_x, top_y);
}
window->Update();
#endif
return window;
}
static void DrawDiacriticJoiner(const BLOBNBOX* blob, ScrollView* window) {
#ifndef GRAPHICS_DISABLED
const TBOX& blob_box(blob->bounding_box());
int top = std::max(static_cast<int>(blob_box.top()), blob->base_char_top());
int bottom = std::min(static_cast<int>(blob_box.bottom()), blob->base_char_bottom());
int x = (blob_box.left() + blob_box.right()) / 2;
window->Line(x, top, x, bottom);
#endif // GRAPHICS_DISABLED
}
// Displays blobs colored according to whether or not they are diacritics.
ScrollView* StrokeWidth::DisplayDiacritics(const char* window_name,
int x, int y, TO_BLOCK* block) {
ScrollView* window = nullptr;
#ifndef GRAPHICS_DISABLED
window = MakeWindow(x, y, window_name);
auto window = MakeWindow(x, y, window_name);
// For every blob in the grid, display it.
window->Brush(ScrollView::NONE);
@ -2007,8 +2022,9 @@ ScrollView* StrokeWidth::DisplayDiacritics(const char* window_name,
window->Rectangle(box.left(), box. bottom(), box.right(), box.top());
}
window->Update();
#endif
return window;
}
#endif // !GRAPHICS_DISABLED
} // namespace tesseract.

View File

@ -443,7 +443,7 @@ bool TabFind::FindTabVectors(TabVector_LIST* hlines,
DisplayTabs("FinalTabs", tab_win);
tab_win = DisplayTabVectors(tab_win);
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
return true;
}
@ -481,7 +481,7 @@ void TabFind::TidyBlobs(TO_BLOCK* block) {
block->plot_graded_blobs(rej_win);
block->plot_noise_blobs(rej_win);
rej_win->Update();
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
}
block->DeleteUnownedNoise();
}
@ -494,8 +494,9 @@ void TabFind::SetupTabSearch(int x, int y, int* min_key, int* max_key) {
*max_key = std::max(key1, key2);
}
ScrollView* TabFind::DisplayTabVectors(ScrollView* tab_win) {
#ifndef GRAPHICS_DISABLED
ScrollView* TabFind::DisplayTabVectors(ScrollView* tab_win) {
// For every vector, display it.
TabVector_IT it(&vectors_);
for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
@ -503,10 +504,11 @@ ScrollView* TabFind::DisplayTabVectors(ScrollView* tab_win) {
vector->Display(tab_win);
}
tab_win->Update();
#endif
return tab_win;
}
#endif
// PRIVATE CODE.
//
// First part of FindTabVectors, which may be used twice if the text
@ -515,10 +517,12 @@ ScrollView* TabFind::FindInitialTabVectors(BLOBNBOX_LIST* image_blobs,
int min_gutter_width,
double tabfind_aligned_gap_fraction,
TO_BLOCK* block) {
#ifndef GRAPHICS_DISABLED
if (textord_tabfind_show_initialtabs) {
ScrollView* line_win = MakeWindow(0, 0, "VerticalLines");
line_win = DisplayTabVectors(line_win);
}
#endif
// Prepare the grid.
if (image_blobs != nullptr)
InsertBlobsToGrid(true, false, image_blobs, this);
@ -530,16 +534,19 @@ ScrollView* TabFind::FindInitialTabVectors(BLOBNBOX_LIST* image_blobs,
TabVector::MergeSimilarTabVectors(vertical_skew_, &vectors_, this);
SortVectors();
EvaluateTabs();
#ifndef GRAPHICS_DISABLED
if (textord_tabfind_show_initialtabs && initial_win != nullptr)
initial_win = DisplayTabVectors(initial_win);
#endif
MarkVerticalText();
return initial_win;
}
#ifndef GRAPHICS_DISABLED
// Helper displays all the boxes in the given vector on the given window.
static void DisplayBoxVector(const GenericVector<BLOBNBOX*>& boxes,
ScrollView* win) {
#ifndef GRAPHICS_DISABLED
for (int i = 0; i < boxes.size(); ++i) {
TBOX box = boxes[i]->bounding_box();
int left_x = box.left();
@ -551,9 +558,10 @@ static void DisplayBoxVector(const GenericVector<BLOBNBOX*>& boxes,
win->Rectangle(left_x, bottom_y, right_x, top_y);
}
win->Update();
#endif // GRAPHICS_DISABLED
}
#endif // !GRAPHICS_DISABLED
// For each box in the grid, decide whether it is a candidate tab-stop,
// and if so add it to the left/right tab boxes.
ScrollView* TabFind::FindTabBoxes(int min_gutter_width,
@ -588,7 +596,7 @@ ScrollView* TabFind::FindTabBoxes(int min_gutter_width,
DisplayBoxVector(right_tab_boxes_, tab_win);
tab_win = DisplayTabs("Tabs", tab_win);
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
return tab_win;
}
@ -952,7 +960,7 @@ void TabFind::ComputeColumnWidths(ScrollView* tab_win,
#ifndef GRAPHICS_DISABLED
if (tab_win != nullptr)
tab_win->Pen(ScrollView::WHITE);
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
// Accumulate column sections into a STATS
int col_widths_size = (tright_.x() - bleft_.x()) / kColumnWidthFactor;
STATS col_widths(0, col_widths_size + 1);
@ -961,7 +969,7 @@ void TabFind::ComputeColumnWidths(ScrollView* tab_win,
if (tab_win != nullptr) {
tab_win->Update();
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
if (textord_debug_tabfind > 1)
col_widths.print();
// Now make a list of column widths.

View File

@ -139,11 +139,13 @@ const double kMaxXProjectionGapFactor = 2.0;
const double kStrokeWidthFractionalTolerance = 0.25;
const double kStrokeWidthConstantTolerance = 2.0;
static BOOL_VAR(textord_show_tables, false, "Show table regions");
#ifndef GRAPHICS_DISABLED
static BOOL_VAR(textord_show_tables, false, "Show table regions (ScrollView)");
static BOOL_VAR(textord_tablefind_show_mark, false,
"Debug table marking steps in detail");
"Debug table marking steps in detail (ScrollView)");
static BOOL_VAR(textord_tablefind_show_stats, false,
"Show page stats used in table finding");
"Show page stats used in table finding (ScrollView)");
#endif
static BOOL_VAR(textord_tablefind_recognize_tables, false,
"Enables the table recognizer for table layout and filtering.");
@ -275,7 +277,7 @@ void TableFinder::LocateTables(ColPartitionGrid* grid,
table_win = MakeWindow(100, 300, "Fragmented Text");
DisplayColPartitions(table_win, &fragmented_text_grid_, ScrollView::BLUE);
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
// mark, filter, and smooth candidate table partitions
MarkTablePartitions();
@ -311,7 +313,7 @@ void TableFinder::LocateTables(ColPartitionGrid* grid,
DisplayColSegments(table_win, &table_columns, ScrollView::DARK_TURQUOISE);
DisplayColSegments(table_win, &table_regions, ScrollView::YELLOW);
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
// Merge table regions across columns for tables spanning multiple
// columns
@ -334,7 +336,7 @@ void TableFinder::LocateTables(ColPartitionGrid* grid,
DisplayColSegments(table_win, &table_columns, ScrollView::KHAKI);
table_grid_.DisplayBoxes(table_win);
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
// Find table grid structure and reject tables that are malformed.
RecognizeTables();
@ -348,7 +350,7 @@ void TableFinder::LocateTables(ColPartitionGrid* grid,
ScrollView::BLUE, ScrollView::BLUE);
table_grid_.DisplayBoxes(table_win);
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
} else {
// Remove false alarms consisting of a single column
// TODO(nbeato): verify this is a NOP after structured table rejection.
@ -363,7 +365,7 @@ void TableFinder::LocateTables(ColPartitionGrid* grid,
ScrollView::BLUE, ScrollView::BLUE);
table_grid_.DisplayBoxes(table_win);
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
}
// Merge all colpartitions in table regions to make them a single
@ -515,9 +517,11 @@ bool TableFinder::AllowBlob(const BLOBNBOX& blob) const {
// The only downside is that window messages will be caught by
// clean_part_grid_ instead of a useful object. This is a temporary solution
// for the debug windows created by the TableFinder.
#ifndef GRAPHICS_DISABLED
ScrollView* TableFinder::MakeWindow(int x, int y, const char* window_name) {
return clean_part_grid_.MakeWindow(x, y, window_name);
}
#endif
// Make single-column blocks from good_columns_ partitions.
void TableFinder::GetColumnBlocks(ColPartitionSet** all_columns,
@ -750,7 +754,7 @@ void TableFinder::SetGlobalSpacings(ColPartitionGrid* grid) {
width_stats.plot(stats_win, 10, 200, 2, 15, ScrollView::GREEN);
ledding_stats.plot(stats_win, 10, 200, 2, 15, ScrollView::BLUE);
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
}
void TableFinder::set_global_median_xheight(int xheight) {
@ -788,33 +792,41 @@ void TableFinder::FindNeighbors() {
// a good sampling of the table partitions.
void TableFinder::MarkTablePartitions() {
MarkPartitionsUsingLocalInformation();
#ifndef GRAPHICS_DISABLED
if (textord_tablefind_show_mark) {
ScrollView* table_win = MakeWindow(300, 300, "Initial Table Partitions");
DisplayColPartitions(table_win, &clean_part_grid_, ScrollView::BLUE);
DisplayColPartitions(table_win, &leader_and_ruling_grid_,
ScrollView::AQUAMARINE);
}
#endif
FilterFalseAlarms();
#ifndef GRAPHICS_DISABLED
if (textord_tablefind_show_mark) {
ScrollView* table_win = MakeWindow(600, 300, "Filtered Table Partitions");
DisplayColPartitions(table_win, &clean_part_grid_, ScrollView::BLUE);
DisplayColPartitions(table_win, &leader_and_ruling_grid_,
ScrollView::AQUAMARINE);
}
#endif
SmoothTablePartitionRuns();
#ifndef GRAPHICS_DISABLED
if (textord_tablefind_show_mark) {
ScrollView* table_win = MakeWindow(900, 300, "Smoothed Table Partitions");
DisplayColPartitions(table_win, &clean_part_grid_, ScrollView::BLUE);
DisplayColPartitions(table_win, &leader_and_ruling_grid_,
ScrollView::AQUAMARINE);
}
#endif
FilterFalseAlarms();
#ifndef GRAPHICS_DISABLED
if (textord_tablefind_show_mark || textord_show_tables) {
ScrollView* table_win = MakeWindow(900, 300, "Final Table Partitions");
DisplayColPartitions(table_win, &clean_part_grid_, ScrollView::BLUE);
DisplayColPartitions(table_win, &leader_and_ruling_grid_,
ScrollView::AQUAMARINE);
}
#endif
}
// These types of partitions are marked as table partitions:
@ -1816,13 +1828,14 @@ bool TableFinder::GapInXProjection(int* xprojection, int length) {
// Overall, this just needs some more work.
void TableFinder::RecognizeTables() {
ScrollView* table_win = nullptr;
#ifndef GRAPHICS_DISABLED
if (textord_show_tables) {
table_win = MakeWindow(0, 0, "Table Structure");
DisplayColPartitions(table_win, &fragmented_text_grid_,
ScrollView::BLUE, ScrollView::LIGHT_BLUE);
// table_grid_.DisplayBoxes(table_win);
}
#endif
TableRecognizer recognizer;
recognizer.Init();
@ -1849,9 +1862,11 @@ void TableFinder::RecognizeTables() {
// Process a table. Good tables are inserted into the grid again later on
// We can't change boxes in the grid while it is running a search.
if (table_structure != nullptr) {
#ifndef GRAPHICS_DISABLED
if (textord_show_tables) {
table_structure->Display(table_win, ScrollView::LIME_GREEN);
}
#endif
found_table->set_bounding_box(table_structure->bounding_box());
delete table_structure;
good_it.add_after_then_move(found_table);
@ -1867,11 +1882,12 @@ void TableFinder::RecognizeTables() {
table_grid_.InsertBBox(true, true, good_it.extract());
}
#ifndef GRAPHICS_DISABLED
// Displays the column segments in some window.
void TableFinder::DisplayColSegments(ScrollView* win,
ColSegment_LIST *segments,
ScrollView::Color color) {
#ifndef GRAPHICS_DISABLED
win->Pen(color);
win->Brush(ScrollView::NONE);
ColSegment_IT it(segments);
@ -1885,29 +1901,6 @@ void TableFinder::DisplayColSegments(ScrollView* win,
win->Rectangle(left_x, bottom_y, right_x, top_y);
}
win->UpdateWindow();
#endif
}
void TableFinder::DisplayColSegmentGrid(ScrollView* win, ColSegmentGrid* grid,
ScrollView::Color color) {
#ifndef GRAPHICS_DISABLED
// Iterate the ColPartitions in the grid.
GridSearch<ColSegment, ColSegment_CLIST, ColSegment_C_IT>
gsearch(grid);
gsearch.StartFullSearch();
ColSegment* seg = nullptr;
while ((seg = gsearch.NextFullSearch()) != nullptr) {
const TBOX& box = seg->bounding_box();
int left_x = box.left();
int right_x = box.right();
int top_y = box.top();
int bottom_y = box.bottom();
win->Brush(ScrollView::NONE);
win->Pen(color);
win->Rectangle(left_x, bottom_y, right_x, top_y);
}
win->UpdateWindow();
#endif
}
// Displays the colpartitions using a new coloring on an existing window.
@ -1917,7 +1910,6 @@ void TableFinder::DisplayColPartitions(ScrollView* win,
ColPartitionGrid* grid,
ScrollView::Color default_color,
ScrollView::Color table_color) {
#ifndef GRAPHICS_DISABLED
ScrollView::Color color = default_color;
// Iterate the ColPartitions in the grid.
GridSearch<ColPartition, ColPartition_CLIST, ColPartition_C_IT>
@ -1939,8 +1931,8 @@ void TableFinder::DisplayColPartitions(ScrollView* win,
win->Rectangle(left_x, bottom_y, right_x, top_y);
}
win->UpdateWindow();
#endif
}
void TableFinder::DisplayColPartitions(ScrollView* win,
ColPartitionGrid* grid,
ScrollView::Color default_color) {
@ -1951,7 +1943,6 @@ void TableFinder::DisplayColPartitionConnections(
ScrollView* win,
ColPartitionGrid* grid,
ScrollView::Color color) {
#ifndef GRAPHICS_DISABLED
// Iterate the ColPartitions in the grid.
GridSearch<ColPartition, ColPartition_CLIST, ColPartition_C_IT>
gsearch(grid);
@ -1988,9 +1979,10 @@ void TableFinder::DisplayColPartitionConnections(
}
}
win->UpdateWindow();
#endif
}
#endif
// Merge all colpartitions in table regions to make them a single
// colpartition and revert types of isolated table cells not
// assigned to any table to their original types.

View File

@ -385,8 +385,6 @@ class TableFinder {
void DisplayColPartitionConnections(ScrollView* win,
ColPartitionGrid* grid,
ScrollView::Color default_color);
void DisplayColSegmentGrid(ScrollView* win, ColSegmentGrid* grid,
ScrollView::Color color);
// Merge all colpartitions in table regions to make them a single
// colpartition and revert types of isolated table cells not

View File

@ -286,8 +286,9 @@ double StructuredTable::CalculateCellFilledPercentage(int row, int column) {
return std::min(1.0, area_covered / current_area);
}
void StructuredTable::Display(ScrollView* window, ScrollView::Color color) {
#ifndef GRAPHICS_DISABLED
void StructuredTable::Display(ScrollView* window, ScrollView::Color color) {
window->Brush(ScrollView::NONE);
window->Pen(color);
window->Rectangle(bounding_box_.left(), bounding_box_.bottom(),
@ -301,9 +302,10 @@ void StructuredTable::Display(ScrollView* window, ScrollView::Color color) {
bounding_box_.right(), cell_y_[i]);
}
window->UpdateWindow();
#endif
}
#endif
// Clear structure information.
void StructuredTable::ClearStructure() {
cell_x_.clear();

View File

@ -535,9 +535,10 @@ void TabVector::Debug(const char* prefix) {
}
}
#ifndef GRAPHICS_DISABLED
// Draw this tabvector in place in the given window.
void TabVector::Display(ScrollView* tab_win) {
#ifndef GRAPHICS_DISABLED
if (textord_debug_printable)
tab_win->Pen(ScrollView::BLUE);
else if (alignment_ == TA_LEFT_ALIGNED)
@ -558,9 +559,10 @@ void TabVector::Display(ScrollView* tab_win) {
snprintf(score_buf, sizeof(score_buf), "%d", percent_score_);
tab_win->TextAttributes("Times", 50, false, false, false);
tab_win->Text(startpt_.x(), startpt_.y(), score_buf);
#endif
}
#endif
// Refit the line and/or re-evaluate the vector if the dirty flags are set.
void TabVector::FitAndEvaluateIfNeeded(const ICOORD& vertical,
TabFind* finder) {

View File

@ -80,10 +80,11 @@ void TextlineProjection::ConstructProjection(TO_BLOCK* input_block,
pix_ = final_pix;
}
#ifndef GRAPHICS_DISABLED
// Display the blobs in the window colored according to textline quality.
void TextlineProjection::PlotGradedBlobs(BLOBNBOX_LIST* blobs,
ScrollView* win) {
#ifndef GRAPHICS_DISABLED
BLOBNBOX_IT it(blobs);
for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
BLOBNBOX* blob = it.data();
@ -96,9 +97,10 @@ void TextlineProjection::PlotGradedBlobs(BLOBNBOX_LIST* blobs,
win->Rectangle(box.left(), box.bottom(), box.right(), box.top());
}
win->Update();
#endif // GRAPHICS_DISABLED
}
#endif // !GRAPHICS_DISABLED
// Moves blobs that look like they don't sit well on a textline from the
// input blobs list to the output small_blobs list.
// This gets them away from initial textline finding to stop diacritics
@ -119,9 +121,10 @@ void TextlineProjection::MoveNonTextlineBlobs(
}
}
#ifndef GRAPHICS_DISABLED
// Create a window and display the projection in it.
void TextlineProjection::DisplayProjection() const {
#ifndef GRAPHICS_DISABLED
int width = pixGetWidth(pix_);
int height = pixGetHeight(pix_);
Pix* pixc = pixCreate(width, height, 32);
@ -147,9 +150,10 @@ void TextlineProjection::DisplayProjection() const {
win->Image(pixc, 0, 0);
win->Update();
pixDestroy(&pixc);
#endif // GRAPHICS_DISABLED
}
#endif // !GRAPHICS_DISABLED
// Compute the distance of the box from the partition using curved projection
// space. As DistanceOfBoxFromBox, except that the direction is taken from
// the ColPartition and the median bounds of the ColPartition are used as

View File

@ -256,7 +256,7 @@ void Textord::filter_blobs(ICOORD page_tr, // top right
#ifndef GRAPHICS_DISABLED
if (to_win != nullptr)
to_win->Clear();
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
for (block_it.mark_cycle_pt(); !block_it.cycled_list();
block_it.forward()) {
@ -288,7 +288,7 @@ void Textord::filter_blobs(ICOORD page_tr, // top right
plot_box_list(to_win, &block->large_blobs, ScrollView::WHITE);
plot_box_list(to_win, &block->blobs, ScrollView::WHITE);
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
}
}

View File

@ -12,6 +12,11 @@
// limitations under the License.
//
///////////////////////////////////////////////////////////////////////
#ifdef HAVE_CONFIG_H
#include "config_auto.h"
#endif
#include <algorithm>
#include <ctime>
@ -78,7 +83,9 @@ double ErrorCounter::ComputeErrorRate(ShapeClassifier* classifier,
tprintf("Error on sample %d: %s Classifier debug output:\n",
it->GlobalSampleIndex(),
it->sample_set()->SampleToString(*mutable_sample).c_str());
#ifndef GRAPHICS_DISABLED
classifier->DebugDisplay(*mutable_sample, page_pix, correct_id);
#endif
--error_samples;
}
++total_samples;
@ -141,7 +148,9 @@ void ErrorCounter::DebugNewErrors(
new_classifier->UnicharClassifySample(*mutable_sample, page_pix, 1,
correct_id, &results);
if (results.size() > 0 && error_samples > 0) {
#ifndef GRAPHICS_DISABLED
new_classifier->DebugDisplay(*mutable_sample, page_pix, correct_id);
#endif
--error_samples;
}
}

View File

@ -757,7 +757,7 @@ Trainability LSTMTrainer::TrainOnLine(const ImageData* trainingdata,
if (debug_interval_ == 1 && debug_win_ != nullptr) {
delete debug_win_->AwaitEvent(SVET_CLICK);
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
// Roll the memory of past means.
RollErrorBuffers();
return trainable;
@ -1026,20 +1026,23 @@ bool LSTMTrainer::DebugLSTMTraining(const NetworkIO& inputs,
tprintf("TRAINING activation path for truth string %s\n",
truth_text.c_str());
DebugActivationPath(outputs, labels, xcoords);
#ifndef GRAPHICS_DISABLED
DisplayForward(inputs, labels, xcoords, "LSTMTraining", &align_win_);
if (OutputLossType() == LT_CTC) {
DisplayTargets(fwd_outputs, "CTC Outputs", &ctc_win_);
DisplayTargets(outputs, "CTC Targets", &target_win_);
}
#endif
}
}
return true;
}
#ifndef GRAPHICS_DISABLED
// Displays the network targets as line a line graph.
void LSTMTrainer::DisplayTargets(const NetworkIO& targets,
const char* window_name, ScrollView** window) {
#ifndef GRAPHICS_DISABLED // do nothing if there's no graphics.
int width = targets.Width();
int num_features = targets.NumFeatures();
Network::ClearWindow(true, window_name, width * kTargetXScale, kTargetYScale,
@ -1069,9 +1072,10 @@ void LSTMTrainer::DisplayTargets(const NetworkIO& targets,
}
}
(*window)->Update();
#endif // GRAPHICS_DISABLED
}
#endif // !GRAPHICS_DISABLED
// Builds a no-compromises target where the first positions should be the
// truth labels and the rest is padded with the null_char_.
bool LSTMTrainer::ComputeTextTargets(const NetworkIO& outputs,

View File

@ -743,7 +743,7 @@ void MasterTrainer::DisplaySamples(const char* unichar_str1, int cloud_font,
delete ev;
} while (ev_type != SVET_DESTROY);
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
void MasterTrainer::TestClassifierVOld(bool replicate_samples,
ShapeClassifier* test_classifier,

View File

@ -209,7 +209,7 @@ class MasterTrainer {
// will display the samples that have that feature in a separate window.
void DisplaySamples(const char* unichar_str1, int cloud_font,
const char* unichar_str2, int canonical_font);
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
void TestClassifierVOld(bool replicate_samples,
ShapeClassifier* test_classifier,

View File

@ -88,7 +88,7 @@ static void DisplayProtoList(const char* ch, LIST protolist) {
}
window->Update();
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
// Helper to run clustering on a single config.
// Mostly copied from the old mftraining, but with renamed variables.
@ -111,7 +111,7 @@ static LIST ClusterOneConfig(int shape_id, const char* class_label,
#ifndef GRAPHICS_DISABLED
if (strcmp(FLAGS_test_ch.c_str(), class_label) == 0)
DisplayProtoList(FLAGS_test_ch.c_str(), proto_list);
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
// Delete the protos that will not be used in the inttemp output file.
proto_list = RemoveInsignificantProtos(proto_list, true,
false,

View File

@ -62,7 +62,7 @@ int main(int argc, char **argv) {
FLAGS_display_cloud_font,
FLAGS_canonical_class2.c_str(),
FLAGS_display_canonical_font);
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
return 0;
} else if (!FLAGS_canonical_class1.empty()) {
trainer->DebugCanonical(FLAGS_canonical_class1.c_str(),

View File

@ -13,6 +13,12 @@
//
///////////////////////////////////////////////////////////////////////
#ifdef HAVE_CONFIG_H
#include "config_auto.h"
#endif
#include <algorithm>
#include "trainingsampleset.h"
#include "allheaders.h"
#include "boxread.h"
@ -25,8 +31,6 @@
#include "trainingsample.h"
#include "unicity_table.h"
#include <algorithm>
namespace tesseract {
const int kTestChar = -1; // 37;
@ -738,6 +742,8 @@ void TrainingSampleSet::AddAllFontsForClass(int class_id, Shape* shape) const {
}
}
#ifndef GRAPHICS_DISABLED
// Display the samples with the given indexed feature that also match
// the given shape.
void TrainingSampleSet::DisplaySamplesWithFeature(int f_index,
@ -760,5 +766,6 @@ void TrainingSampleSet::DisplaySamplesWithFeature(int f_index,
}
}
#endif // !GRAPHICS_DISABLED
} // namespace tesseract.

View File

@ -356,7 +356,7 @@ void ScrollView::StartEventHandler() {
// The thread should run as long as its associated window is alive.
}
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
ScrollView::~ScrollView() {
#ifndef GRAPHICS_DISABLED
@ -385,7 +385,7 @@ ScrollView::~ScrollView() {
for (auto & i : event_table_) {
delete i;
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
}
#ifndef GRAPHICS_DISABLED
@ -842,4 +842,4 @@ char ScrollView::Wait() {
return ret;
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED

View File

@ -409,7 +409,7 @@ class ScrollView {
// Semaphore to the thread belonging to this window.
SVSemaphore* semaphore_;
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
};
#endif // OCR_SCROLLVIEW_H__

View File

@ -140,4 +140,4 @@ void SVMenuNode::BuildMenu(ScrollView* sv, bool menu_bar) {
}
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED

View File

@ -232,4 +232,4 @@ int main(int argc, char** argv) {
if (argc > 1) { server_name = argv[1]; } else { server_name = "localhost"; }
SVPaint svp(server_name);
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED

View File

@ -336,4 +336,4 @@ SVNetwork::~SVNetwork() {
delete[] msg_buffer_in_;
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED

View File

@ -67,7 +67,7 @@ void clear_fx_win() { //make features win
kBlnXHeight + kBlnBaselineOffset);
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED
/**********************************************************************
* create_fxdebug_win

View File

@ -120,7 +120,7 @@ LanguageModel::LanguageModel(const UnicityTable<FontInfo> *fontinfo_table,
dict->getCCUtil()->params()),
double_MEMBER(language_model_penalty_increment, 0.01, "Penalty increment",
dict->getCCUtil()->params()),
INT_MEMBER(wordrec_display_segmentations, 0, "Display Segmentations",
INT_MEMBER(wordrec_display_segmentations, 0, "Display Segmentations (ScrollView)",
dict->getCCUtil()->params()),
BOOL_INIT_MEMBER(language_model_use_sigmoidal_certainty, false,
"Use sigmoidal score for certainty",
@ -1333,9 +1333,11 @@ void LanguageModel::UpdateBestChoice(
vse->dawg_info != nullptr && vse->top_choice_flags);
}
}
#ifndef GRAPHICS_DISABLED
if (wordrec_display_segmentations && word_res->chopped_word != nullptr) {
word->DisplaySegmentation(word_res->chopped_word);
}
#endif
}
void LanguageModel::ExtractFeaturesFromPath(

View File

@ -107,4 +107,4 @@ void mark_outline(EDGEPT *edgept) { /* Start of point list */
window->Update();
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED

View File

@ -124,4 +124,4 @@ void render_outline(ScrollView* window, TESSLINE* outline,
render_outline (window, outline->next, color);
}
#endif // GRAPHICS_DISABLED
#endif // !GRAPHICS_DISABLED