tesseract  4.0.0-1-g2a2b
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 237 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 1322 of file paragraphs.cpp.

1325  : theory_(theory), rows_(rows), row_start_(row_start),
1326  row_end_(row_end) {
1327  if (!AcceptableRowArgs(0, 0, __func__, rows, row_start, row_end)) {
1328  row_start_ = 0;
1329  row_end_ = 0;
1330  return;
1331  }
1332  SetOfModels no_models;
1333  for (int row = row_start - 1; row <= row_end; row++) {
1334  open_models_.push_back(no_models);
1335  }
1336 }
GenericVectorEqEq< const ParagraphModel * > SetOfModels

Member Function Documentation

◆ Smear()

void tesseract::ParagraphModelSmearer::Smear ( )

Definition at line 1369 of file paragraphs.cpp.

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

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