本文整理汇总了C++中TBOX::top方法的典型用法代码示例。如果您正苦于以下问题:C++ TBOX::top方法的具体用法?C++ TBOX::top怎么用?C++ TBOX::top使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TBOX
的用法示例。
在下文中一共展示了TBOX::top方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: EvaluateBoxInternal
// Internal version of EvaluateBox returns the unclipped gradients as well
// as the result of EvaluateBox.
// hgrad1 and hgrad2 are the gradients for the horizontal textline.
int TextlineProjection::EvaluateBoxInternal(const TBOX& box,
const DENORM* denorm, bool debug,
int* hgrad1, int* hgrad2,
int* vgrad1, int* vgrad2) const {
int top_gradient = BestMeanGradientInRow(denorm, box.left(), box.right(),
box.top(), true);
int bottom_gradient = -BestMeanGradientInRow(denorm, box.left(), box.right(),
box.bottom(), false);
int left_gradient = BestMeanGradientInColumn(denorm, box.left(), box.bottom(),
box.top(), true);
int right_gradient = -BestMeanGradientInColumn(denorm, box.right(),
box.bottom(), box.top(),
false);
int top_clipped = MAX(top_gradient, 0);
int bottom_clipped = MAX(bottom_gradient, 0);
int left_clipped = MAX(left_gradient, 0);
int right_clipped = MAX(right_gradient, 0);
if (debug) {
tprintf("Gradients: top = %d, bottom = %d, left= %d, right= %d for box:",
top_gradient, bottom_gradient, left_gradient, right_gradient);
box.print();
}
int result = MAX(top_clipped, bottom_clipped) -
MAX(left_clipped, right_clipped);
if (hgrad1 != NULL && hgrad2 != NULL) {
*hgrad1 = top_gradient;
*hgrad2 = bottom_gradient;
}
if (vgrad1 != NULL && vgrad2 != NULL) {
*vgrad1 = left_gradient;
*vgrad2 = right_gradient;
}
return result;
}
示例2: DistanceOfBoxFromBox
// Compute the distance from the from_box to the to_box using curved
// projection space. Separation that involves a decrease in projection
// density (moving from the from_box to the to_box) is weighted more heavily
// than constant density, and an increase is weighted less.
// If horizontal_textline is true, then curved space is used vertically,
// as for a diacritic on the edge of a textline.
// The projection uses original image coords, so denorm is used to get
// back to the image coords from box/part space.
// How the calculation works: Think of a diacritic near a textline.
// Distance is measured from the far side of the from_box to the near side of
// the to_box. Shown is the horizontal textline case.
// |------^-----|
// | from | box |
// |------|-----|
// perpendicular |
// <------v-------->|--------------------|
// parallel | to box |
// |--------------------|
// Perpendicular distance uses "curved space" See VerticalDistance below.
// Parallel distance is linear.
// Result is perpendicular_gap + parallel_gap / kParaPerpDistRatio.
int TextlineProjection::DistanceOfBoxFromBox(const TBOX& from_box,
const TBOX& to_box,
bool horizontal_textline,
const DENORM* denorm,
bool debug) const {
// The parallel_gap is the horizontal gap between a horizontal textline and
// the box. Analogous for vertical.
int parallel_gap = 0;
// start_pt is the box end of the line to be modified for curved space.
TPOINT start_pt;
// end_pt is the partition end of the line to be modified for curved space.
TPOINT end_pt;
if (horizontal_textline) {
parallel_gap = from_box.x_gap(to_box) + from_box.width();
start_pt.x = (from_box.left() + from_box.right()) / 2;
end_pt.x = start_pt.x;
if (from_box.top() - to_box.top() >= to_box.bottom() - from_box.bottom()) {
start_pt.y = from_box.top();
end_pt.y = MIN(to_box.top(), start_pt.y);
} else {
start_pt.y = from_box.bottom();
end_pt.y = MAX(to_box.bottom(), start_pt.y);
}
} else {
parallel_gap = from_box.y_gap(to_box) + from_box.height();
if (from_box.right() - to_box.right() >= to_box.left() - from_box.left()) {
start_pt.x = from_box.right();
end_pt.x = MIN(to_box.right(), start_pt.x);
} else {
start_pt.x = from_box.left();
end_pt.x = MAX(to_box.left(), start_pt.x);
}
start_pt.y = (from_box.bottom() + from_box.top()) / 2;
end_pt.y = start_pt.y;
}
// The perpendicular gap is the max vertical distance gap out of:
// top of from_box to to_box top and bottom of from_box to to_box bottom.
// This value is then modified for curved projection space.
// Analogous for vertical.
int perpendicular_gap = 0;
// If start_pt == end_pt, then the from_box lies entirely within the to_box
// (in the perpendicular direction), so we don't need to calculate the
// perpendicular_gap.
if (start_pt.x != end_pt.x || start_pt.y != end_pt.y) {
if (denorm != NULL) {
// Denormalize the start and end.
denorm->DenormTransform(NULL, start_pt, &start_pt);
denorm->DenormTransform(NULL, end_pt, &end_pt);
}
if (abs(start_pt.y - end_pt.y) >= abs(start_pt.x - end_pt.x)) {
perpendicular_gap = VerticalDistance(debug, start_pt.x, start_pt.y,
end_pt.y);
} else {
perpendicular_gap = HorizontalDistance(debug, start_pt.x, end_pt.x,
start_pt.y);
}
}
// The parallel_gap weighs less than the perpendicular_gap.
return perpendicular_gap + parallel_gap / kParaPerpDistRatio;
}
示例3: printTBOX
QString printTBOX(TBOX box,int height, bool eol)
{
if (eol)
return QString ("Bounding box=(%1,%2)->(%3,%4)\n").arg(box.left())
.arg(height - box.top()).arg(box.right()).arg(height - box.bottom());
else
return QString ("Bounding box=(%1,%2)->(%3,%4)").arg(box.left())
.arg(height - box.top()).arg(box.right()).arg(height - box.bottom());
}
示例4: MarkAndDeleteNonTextBlobs
// Tests each blob in the list to see if it is certain non-text using 2
// conditions:
// 1. blob overlaps a cell with high value in noise_density_ (previously set
// by ComputeNoiseDensity).
// OR 2. The blob overlaps more than max_blob_overlaps in *this grid. This
// condition is disabled with max_blob_overlaps == -1.
// If it does, the blob is declared non-text, and is used to mark up the
// nontext_mask. Such blobs are fully deleted, and non-noise blobs have their
// neighbours reset, as they may now point to deleted data.
// WARNING: The blobs list blobs may be in the *this grid, but they are
// not removed. If any deleted blobs might be in *this, then this must be
// Clear()ed immediately after MarkAndDeleteNonTextBlobs is called.
// If the win is not NULL, deleted blobs are drawn on it in red, and kept
// blobs are drawn on it in ok_color.
void CCNonTextDetect::MarkAndDeleteNonTextBlobs(BLOBNBOX_LIST* blobs,
int max_blob_overlaps,
ScrollView* win,
ScrollView::Color ok_color,
Pix* nontext_mask) {
int imageheight = tright().y() - bleft().x();
BLOBNBOX_IT blob_it(blobs);
BLOBNBOX_LIST dead_blobs;
BLOBNBOX_IT dead_it(&dead_blobs);
for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
BLOBNBOX* blob = blob_it.data();
TBOX box = blob->bounding_box();
if (!noise_density_->RectMostlyOverThreshold(box, max_noise_count_) &&
(max_blob_overlaps < 0 ||
!BlobOverlapsTooMuch(blob, max_blob_overlaps))) {
blob->ClearNeighbours();
#ifndef GRAPHICS_DISABLED
if (win != NULL)
blob->plot(win, ok_color, ok_color);
#endif // GRAPHICS_DISABLED
} else {
if (noise_density_->AnyZeroInRect(box)) {
// There is a danger that the bounding box may overlap real text, so
// we need to render the outline.
Pix* blob_pix = blob->cblob()->render_outline();
pixRasterop(nontext_mask, box.left(), imageheight - box.top(),
box.width(), box.height(), PIX_SRC | PIX_DST,
blob_pix, 0, 0);
pixDestroy(&blob_pix);
} else {
if (box.area() < gridsize() * gridsize()) {
// It is a really bad idea to make lots of small components in the
// photo mask, so try to join it to a bigger area by expanding the
// box in a way that does not touch any zero noise density cell.
box = AttemptBoxExpansion(box, *noise_density_, gridsize());
}
// All overlapped cells are non-zero, so just mark the rectangle.
pixRasterop(nontext_mask, box.left(), imageheight - box.top(),
box.width(), box.height(), PIX_SET, NULL, 0, 0);
}
#ifndef GRAPHICS_DISABLED
if (win != NULL)
blob->plot(win, ScrollView::RED, ScrollView::RED);
#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.
// TODO(rays) delete the delete when the BLOBNBOX destructor deletes
// the cblob.
delete blob->cblob();
dead_it.add_to_end(blob_it.extract());
}
}
}
示例5: ICOORDELT
// Initialize from box coordinates.
POLY_BLOCK::POLY_BLOCK(const TBOX& box, PolyBlockType t) {
vertices.clear();
ICOORDELT_IT v = &vertices;
v.move_to_first();
v.add_to_end(new ICOORDELT(box.left(), box.top()));
v.add_to_end(new ICOORDELT(box.left(), box.bottom()));
v.add_to_end(new ICOORDELT(box.right(), box.bottom()));
v.add_to_end(new ICOORDELT(box.right(), box.top()));
compute_bb();
type = t;
}
示例6: start_seam_list
/**
* @name start_seam_list
*
* Initialize a list of seams that match the original number of blobs
* present in the starting segmentation. Each of the seams created
* by this routine have location information only.
*/
void start_seam_list(TWERD *word, GenericVector<SEAM*>* seam_array) {
seam_array->truncate(0);
TPOINT location;
for (int b = 1; b < word->NumBlobs(); ++b) {
TBOX bbox = word->blobs[b - 1]->bounding_box();
TBOX nbox = word->blobs[b]->bounding_box();
location.x = (bbox.right() + nbox.left()) / 2;
location.y = (bbox.bottom() + bbox.top() + nbox.bottom() + nbox.top()) / 4;
seam_array->push_back(new SEAM(0.0f, location, NULL, NULL, NULL));
}
}
示例7: bad_box
bool PIXROW::bad_box( //return true if box exceeds image
int xsize,
int ysize) const {
TBOX bbox = bounding_box ();
if (bbox.left () < 0 || bbox.right () > xsize
|| bbox.top () > ysize || bbox.bottom () < 0) {
tprintf("Box (%d,%d)->(%d,%d) bad compared to %d,%d\n",
bbox.left(),bbox.bottom(), bbox.right(), bbox.top(),
xsize, ysize);
return true;
}
return false;
}
示例8: render_segmentation
/**********************************************************************
* render_segmentation
*
* Create a list of line segments that represent the list of chunks
* using the correct segmentation that was supplied as input.
**********************************************************************/
void render_segmentation(ScrollView *window,
TBLOB *chunks,
SEARCH_STATE segmentation) {
TBLOB *blob;
C_COL color = Black;
int char_num = -1;
int chunks_left = 0;
TBOX bbox;
if (chunks) bbox = chunks->bounding_box();
for (blob = chunks; blob != NULL; blob = blob->next) {
bbox += blob->bounding_box();
if (chunks_left-- == 0) {
color = color_list[++char_num % NUM_COLORS];
if (char_num < segmentation[0])
chunks_left = segmentation[char_num + 1];
else
chunks_left = MAX_INT32;
}
render_outline(window, blob->outlines, color);
}
window->ZoomToRectangle(bbox.left(), bbox.top(),
bbox.right(), bbox.bottom());
}
示例9: blob_noise_score
float blob_noise_score(PBLOB *blob) {
OUTLINE_IT outline_it;
TBOX box; //BB of outline
inT16 outline_count = 0;
inT16 max_dimension;
inT16 largest_outline_dimension = 0;
outline_it.set_to_list (blob->out_list ());
for (outline_it.mark_cycle_pt ();
!outline_it.cycled_list (); outline_it.forward ()) {
outline_count++;
box = outline_it.data ()->bounding_box ();
if (box.height () > box.width ())
max_dimension = box.height ();
else
max_dimension = box.width ();
if (largest_outline_dimension < max_dimension)
largest_outline_dimension = max_dimension;
}
if (fixsp_noise_score_fixing) {
if (outline_count > 5)
//penalise LOTS of blobs
largest_outline_dimension *= 2;
box = blob->bounding_box ();
if ((box.bottom () > bln_baseline_offset * 4) ||
(box.top () < bln_baseline_offset / 2))
//Lax blob is if high or low
largest_outline_dimension /= 2;
}
return largest_outline_dimension;
}
示例10: PrintBoxWidths
static void PrintBoxWidths(BLOBNBOX* neighbour) {
TBOX nbox = neighbour->bounding_box();
tprintf("Box (%d,%d)->(%d,%d): h-width=%.1f, v-width=%.1f p-width=%1.f\n",
nbox.left(), nbox.bottom(), nbox.right(), nbox.top(),
neighbour->horz_stroke_width(), neighbour->vert_stroke_width(),
2.0 * neighbour->cblob()->area()/neighbour->cblob()->perimeter());
}
示例11: ProjectBlobs
// Inserts a list of blobs into the projection.
// Rotation is a multiple of 90 degrees to get from blob coords to
// nontext_map coords, nontext_map_box is the bounds of the nontext_map.
// Blobs are spread horizontally or vertically according to their internal
// flags, but the spreading is truncated by set pixels in the nontext_map
// and also by the horizontal rule line limits on the blobs.
void TextlineProjection::ProjectBlobs(BLOBNBOX_LIST* blobs,
const FCOORD& rotation,
const TBOX& nontext_map_box,
Pix* nontext_map) {
BLOBNBOX_IT blob_it(blobs);
for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
BLOBNBOX* blob = blob_it.data();
TBOX bbox = blob->bounding_box();
ICOORD middle((bbox.left() + bbox.right()) / 2,
(bbox.bottom() + bbox.top()) / 2);
bool spreading_horizontally = PadBlobBox(blob, &bbox);
// Rotate to match the nontext_map.
bbox.rotate(rotation);
middle.rotate(rotation);
if (rotation.x() == 0.0f)
spreading_horizontally = !spreading_horizontally;
// Clip to the image before applying the increments.
bbox &= nontext_map_box; // This is in-place box intersection.
// Check for image pixels before spreading.
TruncateBoxToMissNonText(middle.x(), middle.y(), spreading_horizontally,
nontext_map, &bbox);
if (bbox.area() > 0) {
IncrementRectangle8Bit(bbox);
}
}
}
示例12: extract_children
void OL_BUCKETS::extract_children( // recursive count
C_OUTLINE *outline, // parent outline
C_OUTLINE_IT *it // destination iterator
) {
inT16 xmin, xmax; // coord limits
inT16 ymin, ymax;
inT16 xindex, yindex; // current bucket
TBOX olbox;
C_OUTLINE_IT child_it; // search iterator
olbox = outline->bounding_box();
xmin =(olbox.left() - bl.x()) / BUCKETSIZE;
xmax =(olbox.right() - bl.x()) / BUCKETSIZE;
ymin =(olbox.bottom() - bl.y()) / BUCKETSIZE;
ymax =(olbox.top() - bl.y()) / BUCKETSIZE;
for (yindex = ymin; yindex <= ymax; yindex++) {
for (xindex = xmin; xindex <= xmax; xindex++) {
child_it.set_to_list(&buckets[yindex * bxdim + xindex]);
for (child_it.mark_cycle_pt(); !child_it.cycled_list();
child_it.forward()) {
if (*child_it.data() < *outline) {
it->add_after_then_move(child_it.extract());
}
}
}
}
}
示例13: blob_noise_score
float Tesseract::blob_noise_score(TBLOB *blob) {
TBOX box; // BB of outline
inT16 outline_count = 0;
inT16 max_dimension;
inT16 largest_outline_dimension = 0;
for (TESSLINE* ol = blob->outlines; ol != NULL; ol= ol->next) {
outline_count++;
box = ol->bounding_box();
if (box.height() > box.width()) {
max_dimension = box.height();
} else {
max_dimension = box.width();
}
if (largest_outline_dimension < max_dimension)
largest_outline_dimension = max_dimension;
}
if (outline_count > 5) {
// penalise LOTS of blobs
largest_outline_dimension *= 2;
}
box = blob->bounding_box();
if (box.bottom() > kBlnBaselineOffset * 4 ||
box.top() < kBlnBaselineOffset / 2) {
// Lax blob is if high or low
largest_outline_dimension /= 2;
}
return largest_outline_dimension;
}
示例14: BlobToTrainingSample
// Generates a TrainingSample from a TBLOB. Extracts features and sets
// the bounding box, so classifiers that operate on the image can work.
// TODO(rays) Make BlobToTrainingSample a member of Classify now that
// the FlexFx and FeatureDescription code have been removed and LearnBlob
// is now a member of Classify.
TrainingSample* BlobToTrainingSample(
const TBLOB& blob, bool nonlinear_norm, INT_FX_RESULT_STRUCT* fx_info,
GenericVector<INT_FEATURE_STRUCT>* bl_features) {
GenericVector<INT_FEATURE_STRUCT> cn_features;
Classify::ExtractFeatures(blob, nonlinear_norm, bl_features,
&cn_features, fx_info, nullptr);
// TODO(rays) Use blob->PreciseBoundingBox() instead.
TBOX box = blob.bounding_box();
TrainingSample* sample = nullptr;
int num_features = fx_info->NumCN;
if (num_features > 0) {
sample = TrainingSample::CopyFromFeatures(*fx_info, box, &cn_features[0],
num_features);
}
if (sample != nullptr) {
// Set the bounding box (in original image coordinates) in the sample.
TPOINT topleft, botright;
topleft.x = box.left();
topleft.y = box.top();
botright.x = box.right();
botright.y = box.bottom();
TPOINT original_topleft, original_botright;
blob.denorm().DenormTransform(nullptr, topleft, &original_topleft);
blob.denorm().DenormTransform(nullptr, botright, &original_botright);
sample->set_bounding_box(TBOX(original_topleft.x, original_botright.y,
original_botright.x, original_topleft.y));
}
return sample;
}
示例15: recog_training_segmented
// This function takes tif/box pair of files and runs recognition on the image,
// while making sure that the word bounds that tesseract identified roughly
// match to those specified by the input box file. For each word (ngram in a
// single bounding box from the input box file) it outputs the ocred result,
// the correct label, rating and certainty.
void Tesseract::recog_training_segmented(const STRING &fname,
PAGE_RES *page_res,
volatile ETEXT_DESC *monitor,
FILE *output_file) {
STRING box_fname = fname;
const char *lastdot = strrchr(box_fname.string(), '.');
if (lastdot != NULL) box_fname[lastdot - box_fname.string()] = '\0';
box_fname += ".box";
// read_next_box() will close box_file
FILE *box_file = open_file(box_fname.string(), "r");
PAGE_RES_IT page_res_it;
page_res_it.page_res = page_res;
page_res_it.restart_page();
char label[kBoxReadBufSize];
// Process all the words on this page.
TBOX tbox; // tesseract-identified box
TBOX bbox; // box from the box file
bool keep_going;
int line_number = 0;
do {
keep_going = read_t(&page_res_it, &tbox);
keep_going &= read_b(applybox_page, &line_number, box_file, label, &bbox);
// Align bottom left points of the TBOXes.
while (keep_going &&
!NearlyEqual<int>(tbox.bottom(), bbox.bottom(), kMaxBoxEdgeDiff)) {
keep_going = (bbox.bottom() < tbox.bottom()) ?
read_t(&page_res_it, &tbox) :
read_b(applybox_page, &line_number, box_file, label, &bbox);
}
while (keep_going &&
!NearlyEqual<int>(tbox.left(), bbox.left(), kMaxBoxEdgeDiff)) {
keep_going = (bbox.left() > tbox.left()) ? read_t(&page_res_it, &tbox) :
read_b(applybox_page, &line_number, box_file, label, &bbox);
}
// OCR the word if top right points of the TBOXes are similar.
if (keep_going &&
NearlyEqual<int>(tbox.right(), bbox.right(), kMaxBoxEdgeDiff) &&
NearlyEqual<int>(tbox.top(), bbox.top(), kMaxBoxEdgeDiff)) {
ambigs_classify_and_output(page_res_it.prev_word(),
page_res_it.prev_row(),
page_res_it.prev_block(),
label, output_file);
}
} while (keep_going);
}