Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions
tesseract::SearchNode Class Reference

`#include <search_node.h>`

List of all members.

## Public Member Functions
| SearchNode (CubeRecoContext *cntxt, SearchNode *parent_node, int char_reco_cost, LangModEdge *edge, int col_idx)
| ~SearchNode ()
bool | UpdateParent (SearchNode *new_parent, int new_reco_cost, LangModEdge *new_edge)
char_32 * | PathString ()
const char_32 * | NodeString ()
void | SetString (char_32 *str)
int | CharRecoCost ()
int | BestPathRecoCost ()
int | BestPathLength ()
int | BestCost ()
int | BestRecoCost ()
int | ColIdx ()
SearchNode * | ParentNode ()
LangModEdge * | LangModelEdge ()
int | LangModCost ()

## Static Public Member Functions
static bool | IdenticalPath (SearchNode *node1, SearchNode *node2)
static int | SearchNodeComparer (const void *node1, const void *node2)

## Detailed Description

Definition at line 35 of file search_node.h.

## Constructor & Destructor Documentation

tesseract::SearchNode::SearchNode | ( | CubeRecoContext * | cntxt,
|  | SearchNode * | parent_node,
|  | int | char_reco_cost,
|  | LangModEdge * | edge,
|  | int | col_idx
| ) |  |

Definition at line 32 of file search_node.cpp.

{
// copy data members
cntxt_ = cntxt;
lang_mod_edge_ = edge;
col_idx_ = col_idx;
parent_node_ = parent_node;
char_reco_cost_ = char_reco_cost;
// the string of this node is the same as that of the language model edge
str_ = (edge == NULL ? NULL : edge->EdgeString());
// compute best path total reco cost
best_path_reco_cost_ = (parent_node_ == NULL) ? 0 :
parent_node_->CharRecoCost() + parent_node_->BestPathRecoCost();
// update best path length
best_path_len_ = (parent_node_ == NULL) ?
1 : parent_node_->BestPathLength() + 1;
if (edge != NULL && edge->IsRoot() && parent_node_ != NULL) {
best_path_len_++;
}
// compute best reco cost mean cost
mean_char_reco_cost_ = static_cast<int>(
(best_path_reco_cost_ + char_reco_cost_) /
static_cast<double>(best_path_len_));
// get language model cost
int lm_cost = LangModCost(lang_mod_edge_, parent_node_);
// compute aggregate best cost
best_cost_ = static_cast<int>(cntxt_->Params()->RecoWgt() *
(best_path_reco_cost_ + char_reco_cost_) /
static_cast<double>(best_path_len_)
) + lm_cost;
}

tesseract::SearchNode::~SearchNode | ( |  | ) |

Definition at line 70 of file search_node.cpp.

{
if (lang_mod_edge_ != NULL) {
delete lang_mod_edge_;
}
}

## Member Function Documentation

int tesseract::SearchNode::BestCost | ( |  | ) |
| inline

Definition at line 63 of file search_node.h.

{ return best_cost_; }

int tesseract::SearchNode::BestPathLength | ( |  | ) |
| inline

Definition at line 60 of file search_node.h.

{ return best_path_len_; }

int tesseract::SearchNode::BestPathRecoCost | ( |  | ) |
| inline

Definition at line 58 of file search_node.h.

{ return best_path_reco_cost_; }

int tesseract::SearchNode::BestRecoCost | ( |  | ) |
| inline

Definition at line 66 of file search_node.h.

{ return mean_char_reco_cost_ ; }

int tesseract::SearchNode::CharRecoCost | ( |  | ) |
| inline

Definition at line 55 of file search_node.h.

{ return char_reco_cost_; }

int tesseract::SearchNode::ColIdx | ( |  | ) |
| inline

Definition at line 68 of file search_node.h.

{ return col_idx_; }

bool tesseract::SearchNode::IdenticalPath | ( | SearchNode * | node1,
|  | SearchNode * | node2
| ) |  |
| static

Definition at line 178 of file search_node.cpp.

{
if (node1 != NULL && node2 != NULL &&
node1->best_path_len_ != node2->best_path_len_) {
return false;
}
// backtrack until either a root or a NULL edge is reached
while (node1 != NULL && node2 != NULL) {
if (node1->str_ != node2->str_) {
return false;
}
// stop if either nodes is a root
if (node1->LangModelEdge()->IsRoot() || node2->LangModelEdge()->IsRoot()) {
break;
}
node1 = node1->parent_node_;
node2 = node2->parent_node_;
}
return ((node1 == NULL && node2 == NULL) ||
(node1 != NULL && node1->LangModelEdge()->IsRoot() &&
node2 != NULL && node2->LangModelEdge()->IsRoot()));
}

int tesseract::SearchNode::LangModCost | ( |  | ) |
| inline

Definition at line 71 of file search_node.h.

{ return LangModCost(lang_mod_edge_, parent_node_); }

LangModEdge* tesseract::SearchNode::LangModelEdge | ( |  | ) |
| inline

Definition at line 70 of file search_node.h.

{ return lang_mod_edge_;}

const char_32* tesseract::SearchNode::NodeString | ( |  | ) |
| inline

Definition at line 51 of file search_node.h.

{ return str_; }

SearchNode* tesseract::SearchNode::ParentNode | ( |  | ) |
| inline

Definition at line 69 of file search_node.h.

{ return parent_node_; }

char_32 * tesseract::SearchNode::PathString | ( |  | ) |

Definition at line 129 of file search_node.cpp.

{
SearchNode *node = this;
// compute string length
int len = 0;
while (node != NULL) {
if (node->str_ != NULL) {
len += CubeUtils::StrLen(node->str_);
}
// if the edge is a root and does not have a NULL parent, account for space
LangModEdge *lm_edge = node->LangModelEdge();
if (lm_edge != NULL && lm_edge->IsRoot() && node->ParentNode() != NULL) {
len++;
}
node = node->parent_node_;
}
char_32 *char_ptr = new char_32[len + 1];
if (char_ptr == NULL) {
return NULL;
}
int ch_idx = len;
node = this;
char_ptr[ch_idx--] = 0;
while (node != NULL) {
int str_len = ((node->str_ == NULL) ? 0 : CubeUtils::StrLen(node->str_));
while (str_len > 0) {
char_ptr[ch_idx--] = node->str_[--str_len];
}
// if the edge is a root and does not have a NULL parent, insert a space
LangModEdge *lm_edge = node->LangModelEdge();
if (lm_edge != NULL && lm_edge->IsRoot() && node->ParentNode() != NULL) {
char_ptr[ch_idx--] = (char_32)' ';
}
node = node->parent_node_;
}
return char_ptr;
}

static int tesseract::SearchNode::SearchNodeComparer | ( | const void * | node1,
|  | const void * | node2
| ) |  |
| inline static

Definition at line 75 of file search_node.h.

{
return (*(reinterpret_cast<SearchNode * const *>(node1)))->best_cost_ -
(*(reinterpret_cast<SearchNode * const *>(node2)))->best_cost_;
}

void tesseract::SearchNode::SetString | ( | char_32 * | str | ) |
| inline

Definition at line 52 of file search_node.h.

{ str_ = str; }

bool tesseract::SearchNode::UpdateParent | ( | SearchNode * | new_parent,
|  | int | new_reco_cost,
|  | LangModEdge * | new_edge
| ) |  |

Definition at line 77 of file search_node.cpp.

{
if (lang_mod_edge_ == NULL) {
if (new_edge != NULL) {
return false;
}
} else {
// to update the parent_node, we have to have the same target
// state and char
if (new_edge == NULL || !lang_mod_edge_->IsIdentical(new_edge) ||
!SearchNode::IdenticalPath(parent_node_, new_parent)) {
return false;
}
}
// compute the path cost and combined cost of the new path
int new_best_path_reco_cost;
int new_cost;
int new_best_path_len;
new_best_path_reco_cost = (new_parent == NULL) ?
0 : new_parent->BestPathRecoCost() + new_parent->CharRecoCost();
new_best_path_len =
(new_parent == NULL) ? 1 : new_parent->BestPathLength() + 1;
// compute the new language model cost
int new_lm_cost = LangModCost(new_edge, new_parent);
new_cost = static_cast<int>(cntxt_->Params()->RecoWgt() *
(new_best_path_reco_cost + new_reco_cost) /
static_cast<double>(new_best_path_len)
) + new_lm_cost;
// update if it is better (less) than the current one
if (best_cost_ > new_cost) {
parent_node_ = new_parent;
char_reco_cost_ = new_reco_cost;
best_path_reco_cost_ = new_best_path_reco_cost;
best_path_len_ = new_best_path_len;
mean_char_reco_cost_ = static_cast<int>(
(best_path_reco_cost_ + char_reco_cost_) /
static_cast<double>(best_path_len_));
best_cost_ = static_cast<int>(cntxt_->Params()->RecoWgt() *
(best_path_reco_cost_ + char_reco_cost_) /
static_cast<double>(best_path_len_)
) + new_lm_cost;
return true;
}
return false;
}

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

- /mnt/data/src/tesseract-ocr/cube/search_node.h
- /mnt/data/src/tesseract-ocr/cube/search_node.cpp