tesseract  4.00.00dev
tesseract::ParagraphModelSmearer Class Reference

#include <paragraphs_internal.h>

Public Member Functions

 ParagraphModelSmearer (GenericVector< RowScratchRegisters > *rows, int row_start, int row_end, ParagraphTheory *theory)
 
void Smear ()
 

Detailed Description

Definition at line 234 of file paragraphs_internal.h.

Constructor & Destructor Documentation

◆ ParagraphModelSmearer()

tesseract::ParagraphModelSmearer::ParagraphModelSmearer ( GenericVector< RowScratchRegisters > *  rows,
int  row_start,
int  row_end,
ParagraphTheory theory 
)

Definition at line 1310 of file paragraphs.cpp.

1313  : theory_(theory), rows_(rows), row_start_(row_start),
1314  row_end_(row_end) {
1315  if (!AcceptableRowArgs(0, 0, __func__, rows, row_start, row_end)) {
1316  row_start_ = 0;
1317  row_end_ = 0;
1318  return;
1319  }
1320  SetOfModels no_models;
1321  for (int row = row_start - 1; row <= row_end; row++) {
1322  open_models_.push_back(no_models);
1323  }
1324 }
GenericVectorEqEq< const ParagraphModel * > SetOfModels

Member Function Documentation

◆ Smear()

void tesseract::ParagraphModelSmearer::Smear ( )

Definition at line 1357 of file paragraphs.cpp.

1357  {
1358  CalculateOpenModels(row_start_, row_end_);
1359 
1360  // For each row which we're unsure about (that is, it is LT_UNKNOWN or
1361  // we have multiple LT_START hypotheses), see if there's a model that
1362  // was recently used (an "open" model) which might model it well.
1363  for (int i = row_start_; i < row_end_; i++) {
1364  RowScratchRegisters &row = (*rows_)[i];
1365  if (row.ri_->num_words == 0)
1366  continue;
1367 
1368  // Step One:
1369  // Figure out if there are "open" models which are left-alined or
1370  // right-aligned. This is important for determining whether the
1371  // "first" word in a row would fit at the "end" of the previous row.
1372  bool left_align_open = false;
1373  bool right_align_open = false;
1374  for (int m = 0; m < OpenModels(i).size(); m++) {
1375  switch (OpenModels(i)[m]->justification()) {
1376  case JUSTIFICATION_LEFT: left_align_open = true; break;
1377  case JUSTIFICATION_RIGHT: right_align_open = true; break;
1378  default: left_align_open = right_align_open = true;
1379  }
1380  }
1381  // Step Two:
1382  // Use that knowledge to figure out if this row is likely to
1383  // start a paragraph.
1384  bool likely_start;
1385  if (i == 0) {
1386  likely_start = true;
1387  } else {
1388  if ((left_align_open && right_align_open) ||
1389  (!left_align_open && !right_align_open)) {
1390  likely_start = LikelyParagraphStart((*rows_)[i - 1], row,
1391  JUSTIFICATION_LEFT) ||
1392  LikelyParagraphStart((*rows_)[i - 1], row,
1394  } else if (left_align_open) {
1395  likely_start = LikelyParagraphStart((*rows_)[i - 1], row,
1397  } else {
1398  likely_start = LikelyParagraphStart((*rows_)[i - 1], row,
1400  }
1401  }
1402 
1403  // Step Three:
1404  // If this text line seems like an obvious first line of an
1405  // open model, or an obvious continuation of an existing
1406  // modelled paragraph, mark it up.
1407  if (likely_start) {
1408  // Add Start Hypotheses for all Open models that fit.
1409  for (int m = 0; m < OpenModels(i).size(); m++) {
1410  if (ValidFirstLine(rows_, i, OpenModels(i)[m])) {
1411  row.AddStartLine(OpenModels(i)[m]);
1412  }
1413  }
1414  } else {
1415  // Add relevant body line hypotheses.
1416  SetOfModels last_line_models;
1417  if (i > 0) {
1418  (*rows_)[i - 1].StrongHypotheses(&last_line_models);
1419  } else {
1420  theory_->NonCenteredModels(&last_line_models);
1421  }
1422  for (int m = 0; m < last_line_models.size(); m++) {
1423  const ParagraphModel *model = last_line_models[m];
1424  if (ValidBodyLine(rows_, i, model))
1425  row.AddBodyLine(model);
1426  }
1427  }
1428 
1429  // Step Four:
1430  // If we're still quite unsure about this line, go through all
1431  // models in our theory and see if this row could be the start
1432  // of any of our models.
1433  if (row.GetLineType() == LT_UNKNOWN ||
1434  (row.GetLineType() == LT_START && !row.UniqueStartHypothesis())) {
1435  SetOfModels all_models;
1436  theory_->NonCenteredModels(&all_models);
1437  for (int m = 0; m < all_models.size(); m++) {
1438  if (ValidFirstLine(rows_, i, all_models[m])) {
1439  row.AddStartLine(all_models[m]);
1440  }
1441  }
1442  }
1443  // Step Five:
1444  // Since we may have updated the hypotheses about this row, we need
1445  // to recalculate the Open models for the rest of rows[i + 1, row_end)
1446  if (row.GetLineType() != LT_UNKNOWN) {
1447  CalculateOpenModels(i + 1, row_end_);
1448  }
1449  }
1450 }
bool ValidFirstLine(const GenericVector< RowScratchRegisters > *rows, int row, const ParagraphModel *model)
bool LikelyParagraphStart(const RowScratchRegisters &before, const RowScratchRegisters &after)
int size() const
Definition: genericvector.h:72
GenericVectorEqEq< const ParagraphModel * > SetOfModels
bool ValidBodyLine(const GenericVector< RowScratchRegisters > *rows, int row, const ParagraphModel *model)
void NonCenteredModels(SetOfModels *models)

The documentation for this class was generated from the following files: