本文整理汇总了C++中BLOBNBOX::left_tab_type方法的典型用法代码示例。如果您正苦于以下问题:C++ BLOBNBOX::left_tab_type方法的具体用法?C++ BLOBNBOX::left_tab_type怎么用?C++ BLOBNBOX::left_tab_type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BLOBNBOX
的用法示例。
在下文中一共展示了BLOBNBOX::left_tab_type方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FindHorizontalLines
// Finds horizontal line objects in the given pix.
// Uses the given resolution to determine size thresholds instead of any
// that may be present in the pix.
// The output vectors are owned by the list and Frozen (cannot refit) by
// having no boxes, as there is no need to refit or merge separator lines.
void LineFinder::FindHorizontalLines(int resolution, Pix* pix,
TabVector_LIST* vectors) {
#ifdef HAVE_LIBLEPT
Pix* line_pix;
Boxa* boxes = GetHLineBoxes(resolution, pix, &line_pix);
C_BLOB_LIST line_cblobs;
int width = pixGetWidth(pix);
int height = pixGetHeight(pix);
ConvertBoxaToBlobs(height, width, &boxes, &line_cblobs);
// Make the BLOBNBOXes from the C_BLOBs.
BLOBNBOX_LIST line_bblobs;
C_BLOB_IT blob_it(&line_cblobs);
BLOBNBOX_IT bbox_it(&line_bblobs);
for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
C_BLOB* cblob = blob_it.data();
BLOBNBOX* bblob = new BLOBNBOX(cblob);
bbox_it.add_to_end(bblob);
}
ICOORD bleft(0, 0);
ICOORD tright(height, width);
int vertical_x, vertical_y;
FindLineVectors(bleft, tright, &line_bblobs, &vertical_x, &vertical_y,
vectors);
if (!vectors->empty()) {
// Some lines were found, so erase the unused blobs from the line image
// and then subtract the line image from the source.
bbox_it.move_to_first();
for (bbox_it.mark_cycle_pt(); !bbox_it.cycled_list(); bbox_it.forward()) {
BLOBNBOX* blob = bbox_it.data();
if (blob->left_tab_type() == TT_UNCONFIRMED) {
const TBOX& box = blob->bounding_box();
// Coords are in tess format so filp x and y and then covert
// to leptonica by height -y.
Box* pixbox = boxCreate(box.bottom(), height - box.right(),
box.height(), box.width());
pixClearInRect(line_pix, pixbox);
boxDestroy(&pixbox);
}
}
pixDilateBrick(line_pix, line_pix, 3, 1);
pixSubtract(pix, pix, line_pix);
if (textord_tabfind_show_vlines)
pixWrite("hlinesclean.png", line_pix, IFF_PNG);
ICOORD vertical;
vertical.set_with_shrink(vertical_x, vertical_y);
TabVector::MergeSimilarTabVectors(vertical, vectors, NULL);
// Iterate the vectors to flip them.
TabVector_IT h_it(vectors);
for (h_it.mark_cycle_pt(); !h_it.cycled_list(); h_it.forward()) {
h_it.data()->XYFlip();
}
}
pixDestroy(&line_pix);
#endif
}
示例2: FindLineVectors
// Finds vertical lines in the given list of BLOBNBOXes. bleft and tright
// are the bounds of the image on which the input line_bblobs were found.
// The input line_bblobs list is const really.
// The output vertical_x and vertical_y are the total of all the vectors.
// The output list of TabVector makes no reference to the input BLOBNBOXes.
void LineFinder::FindLineVectors(const ICOORD& bleft, const ICOORD& tright,
BLOBNBOX_LIST* line_bblobs,
int* vertical_x, int* vertical_y,
TabVector_LIST* vectors) {
BLOBNBOX_IT bbox_it(line_bblobs);
int b_count = 0;
// Put all the blobs into the grid to find the lines, and move the blobs
// to the output lists.
AlignedBlob blob_grid(kLineFindGridSize, bleft, tright);
for (bbox_it.mark_cycle_pt(); !bbox_it.cycled_list(); bbox_it.forward()) {
BLOBNBOX* bblob = bbox_it.data();
bblob->set_left_tab_type(TT_UNCONFIRMED);
bblob->set_left_rule(bleft.x());
bblob->set_right_rule(tright.x());
bblob->set_left_crossing_rule(bleft.x());
bblob->set_right_crossing_rule(tright.x());
blob_grid.InsertBBox(false, true, bblob);
++b_count;
}
if (textord_debug_tabfind)
tprintf("Inserted %d line blobs into grid\n", b_count);
if (b_count == 0)
return;
// Search the entire grid, looking for vertical line vectors.
GridSearch<BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT> lsearch(&blob_grid);
BLOBNBOX* bbox;
TabVector_IT vector_it(vectors);
*vertical_x = 0;
*vertical_y = 1;
lsearch.StartFullSearch();
while ((bbox = lsearch.NextFullSearch()) != NULL) {
if (bbox->left_tab_type() == TT_UNCONFIRMED) {
const TBOX& box = bbox->bounding_box();
if (AlignedBlob::WithinTestRegion(2, box.left(), box.bottom()))
tprintf("Finding line vector starting at bbox (%d,%d)\n",
box.left(), box.bottom());
AlignedBlobParams align_params(*vertical_x, *vertical_y, box.width());
TabVector* vector = blob_grid.FindVerticalAlignment(align_params, bbox,
vertical_x,
vertical_y);
if (vector != NULL) {
vector->Freeze();
vector_it.add_to_end(vector);
}
}
}
ScrollView* line_win = NULL;
if (textord_tabfind_show_vlines) {
line_win = blob_grid.MakeWindow(0, 50, "Vlines");
blob_grid.DisplayBoxes(line_win);
line_win = blob_grid.DisplayTabs("Vlines", line_win);
}
}
示例3: FindVerticalLines
// Finds vertical line objects in the given pix.
// Uses the given resolution to determine size thresholds instead of any
// that may be present in the pix.
// The output vertical_x and vertical_y contain a sum of the output vectors,
// thereby giving the mean vertical direction.
// The output vectors are owned by the list and Frozen (cannot refit) by
// having no boxes, as there is no need to refit or merge separator lines.
void LineFinder::FindVerticalLines(int resolution, Pix* pix,
int* vertical_x, int* vertical_y,
TabVector_LIST* vectors) {
#ifdef HAVE_LIBLEPT
Pix* line_pix;
Boxa* boxes = GetVLineBoxes(resolution, pix, &line_pix);
C_BLOB_LIST line_cblobs;
int width = pixGetWidth(pix);
int height = pixGetHeight(pix);
ConvertBoxaToBlobs(width, height, &boxes, &line_cblobs);
// Make the BLOBNBOXes from the C_BLOBs.
BLOBNBOX_LIST line_bblobs;
C_BLOB_IT blob_it(&line_cblobs);
BLOBNBOX_IT bbox_it(&line_bblobs);
for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
C_BLOB* cblob = blob_it.data();
BLOBNBOX* bblob = new BLOBNBOX(cblob);
bbox_it.add_to_end(bblob);
}
ICOORD bleft(0, 0);
ICOORD tright(width, height);
FindLineVectors(bleft, tright, &line_bblobs, vertical_x, vertical_y, vectors);
if (!vectors->empty()) {
// Some lines were found, so erase the unused blobs from the line image
// and then subtract the line image from the source.
bbox_it.move_to_first();
for (bbox_it.mark_cycle_pt(); !bbox_it.cycled_list(); bbox_it.forward()) {
BLOBNBOX* blob = bbox_it.data();
if (blob->left_tab_type() == TT_UNCONFIRMED) {
const TBOX& box = blob->bounding_box();
Box* pixbox = boxCreate(box.left(), height - box.top(),
box.width(), box.height());
pixClearInRect(line_pix, pixbox);
boxDestroy(&pixbox);
}
}
pixDilateBrick(line_pix, line_pix, 1, 3);
pixSubtract(pix, pix, line_pix);
if (textord_tabfind_show_vlines)
pixWrite("vlinesclean.png", line_pix, IFF_PNG);
ICOORD vertical;
vertical.set_with_shrink(*vertical_x, *vertical_y);
TabVector::MergeSimilarTabVectors(vertical, vectors, NULL);
}
pixDestroy(&line_pix);
#endif
}
示例4: DisplayTabs
// 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.
GridSearch<BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT> gsearch(this);
gsearch.StartFullSearch();
BLOBNBOX* bbox;
while ((bbox = gsearch.NextFullSearch()) != nullptr) {
const TBOX& box = bbox->bounding_box();
int left_x = box.left();
int right_x = box.right();
int top_y = box.top();
int bottom_y = box.bottom();
TabType tabtype = bbox->left_tab_type();
if (tabtype != TT_NONE) {
if (tabtype == TT_MAYBE_ALIGNED)
tab_win->Pen(ScrollView::BLUE);
else if (tabtype == TT_MAYBE_RAGGED)
tab_win->Pen(ScrollView::YELLOW);
else if (tabtype == TT_CONFIRMED)
tab_win->Pen(ScrollView::GREEN);
else
tab_win->Pen(ScrollView::GREY);
tab_win->Line(left_x, top_y, left_x, bottom_y);
}
tabtype = bbox->right_tab_type();
if (tabtype != TT_NONE) {
if (tabtype == TT_MAYBE_ALIGNED)
tab_win->Pen(ScrollView::MAGENTA);
else if (tabtype == TT_MAYBE_RAGGED)
tab_win->Pen(ScrollView::ORANGE);
else if (tabtype == TT_CONFIRMED)
tab_win->Pen(ScrollView::RED);
else
tab_win->Pen(ScrollView::GREY);
tab_win->Line(right_x, top_y, right_x, bottom_y);
}
}
tab_win->Update();
#endif
return tab_win;
}
示例5: FindAlignedBlob
//.........这里部分代码省略.........
nbox.left(), nbox.bottom(), nbox.right(), nbox.top());
break; // Gone far enough.
}
// It is CRITICAL to ensure that forward progress is made, (strictly
// in/decreasing n_y) or the caller could loop infinitely, while
// waiting for a sequence of blobs in a line to end.
// NextVerticalSearch alone does not guarantee this, as there may be
// more than one blob in a grid cell. See comment in AlignTabs.
if ((n_y < start_y) != top_to_bottom || nbox.y_overlap(box))
continue; // Only look in the required direction.
if (result != nullptr && result->bounding_box().y_gap(nbox) > gridsize())
return result; // This result is clear.
if (backup_result != nullptr && p.ragged && result == nullptr &&
backup_result->bounding_box().y_gap(nbox) > gridsize())
return backup_result; // This result is clear.
// If the neighbouring blob is the wrong side of a separator line, then it
// "doesn't exist" as far as we are concerned.
int x_at_n_y = x_start + (n_y - start_y) * p.vertical.x() / p.vertical.y();
if (x_at_n_y < neighbour->left_crossing_rule() ||
x_at_n_y > neighbour->right_crossing_rule())
continue; // Separator line in the way.
int n_left = nbox.left();
int n_right = nbox.right();
int n_x = p.right_tab ? n_right : n_left;
if (WithinTestRegion(2, x_start, start_y))
tprintf("neighbour at (%d,%d)->(%d,%d), n_x=%d, n_y=%d, xatn=%d\n",
nbox.left(), nbox.bottom(), nbox.right(), nbox.top(),
n_x, n_y, x_at_n_y);
if (p.right_tab &&
n_left < x_at_n_y + p.min_gutter &&
n_right > x_at_n_y + p.r_align_tolerance &&
(p.ragged || n_left < x_at_n_y + p.gutter_fraction * nbox.height())) {
// In the gutter so end of line.
if (bbox->right_tab_type() >= TT_MAYBE_ALIGNED)
bbox->set_right_tab_type(TT_DELETED);
*end_y = top_to_bottom ? nbox.top() : nbox.bottom();
if (WithinTestRegion(2, x_start, start_y))
tprintf("gutter\n");
return nullptr;
}
if (!p.right_tab &&
n_left < x_at_n_y - p.l_align_tolerance &&
n_right > x_at_n_y - p.min_gutter &&
(p.ragged || n_right > x_at_n_y - p.gutter_fraction * nbox.height())) {
// In the gutter so end of line.
if (bbox->left_tab_type() >= TT_MAYBE_ALIGNED)
bbox->set_left_tab_type(TT_DELETED);
*end_y = top_to_bottom ? nbox.top() : nbox.bottom();
if (WithinTestRegion(2, x_start, start_y))
tprintf("gutter\n");
return nullptr;
}
if ((p.right_tab && neighbour->leader_on_right()) ||
(!p.right_tab && neighbour->leader_on_left()))
continue; // Neighbours of leaders are not allowed to be used.
if (n_x <= x_at_n_y + p.r_align_tolerance &&
n_x >= x_at_n_y - p.l_align_tolerance) {
// Aligned so keep it. If it is a marked tab save it as result,
// otherwise keep it as backup_result to return in case of later failure.
if (WithinTestRegion(2, x_start, start_y))
tprintf("aligned, seeking%d, l=%d, r=%d\n",
p.right_tab, neighbour->left_tab_type(),
neighbour->right_tab_type());
TabType n_type = p.right_tab ? neighbour->right_tab_type()
: neighbour->left_tab_type();
if (n_type != TT_NONE && (p.ragged || n_type != TT_MAYBE_RAGGED)) {
if (result == nullptr) {
result = neighbour;
} else {
// Keep the closest neighbour by Euclidean distance.
// This prevents it from picking a tab blob in another column.
const TBOX& old_box = result->bounding_box();
int x_diff = p.right_tab ? old_box.right() : old_box.left();
x_diff -= x_at_n_y;
int y_diff = (old_box.top() + old_box.bottom()) / 2 - start_y;
int old_dist = x_diff * x_diff + y_diff * y_diff;
x_diff = n_x - x_at_n_y;
y_diff = n_y - start_y;
int new_dist = x_diff * x_diff + y_diff * y_diff;
if (new_dist < old_dist)
result = neighbour;
}
} else if (backup_result == nullptr) {
if (WithinTestRegion(2, x_start, start_y))
tprintf("Backup\n");
backup_result = neighbour;
} else {
TBOX backup_box = backup_result->bounding_box();
if ((p.right_tab && backup_box.right() < nbox.right()) ||
(!p.right_tab && backup_box.left() > nbox.left())) {
if (WithinTestRegion(2, x_start, start_y))
tprintf("Better backup\n");
backup_result = neighbour;
}
}
}
}
return result != nullptr ? result : backup_result;
}