本文整理汇总了C++中TBOX类的典型用法代码示例。如果您正苦于以下问题:C++ TBOX类的具体用法?C++ TBOX怎么用?C++ TBOX使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TBOX类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetupNonLinear
// Sets up the DENORM to execute a non-linear transformation based on
// preserving an even distribution of stroke edges. The transformation
// operates only within the given box.
// x_coords is a collection of the x-coords of vertical edges for each
// y-coord starting at box.bottom().
// y_coords is a collection of the y-coords of horizontal edges for each
// x-coord starting at box.left().
// Eg x_coords[0] is a collection of the x-coords of edges at y=bottom.
// Eg x_coords[1] is a collection of the x-coords of edges at y=bottom + 1.
// The second-level vectors must all be sorted in ascending order.
// See comments on the helper functions above for more details.
void DENORM::SetupNonLinear(
const DENORM* predecessor, const TBOX& box, float target_width,
float target_height, float final_xshift, float final_yshift,
const GenericVector<GenericVector<int> >& x_coords,
const GenericVector<GenericVector<int> >& y_coords) {
Clear();
predecessor_ = predecessor;
// x_map_ and y_map_ store a mapping from input x and y coordinate to output
// x and y coordinate, based on scaling to the supplied target_width and
// target_height.
x_map_ = new GenericVector<float>;
y_map_ = new GenericVector<float>;
// Set a 2-d image array to the run lengths at each pixel.
int width = box.width();
int height = box.height();
GENERIC_2D_ARRAY<int> minruns(width, height, 0);
ComputeRunlengthImage(box, x_coords, y_coords, &minruns);
// Edge density is the sum of the inverses of the run lengths. Compute
// edge density projection profiles.
ComputeEdgeDensityProfiles(box, minruns, x_map_, y_map_);
// Convert the edge density profiles to the coordinates by multiplying by
// the desired size and accumulating.
(*x_map_)[width] = target_width;
for (int x = width - 1; x >= 0; --x) {
(*x_map_)[x] = (*x_map_)[x + 1] - (*x_map_)[x] * target_width;
}
(*y_map_)[height] = target_height;
for (int y = height - 1; y >= 0; --y) {
(*y_map_)[y] = (*y_map_)[y + 1] - (*y_map_)[y] * target_height;
}
x_origin_ = box.left();
y_origin_ = box.bottom();
final_xshift_ = final_xshift;
final_yshift_ = final_yshift;
}
示例2: EvaluateBox
// Evaluates the textlineiness of a ColPartition. Uses EvaluateBox below,
// but uses the median top/bottom for horizontal and median left/right for
// vertical instead of the bounding box edges.
// Evaluates for both horizontal and vertical and returns the best result,
// with a positive value for horizontal and a negative value for vertical.
int TextlineProjection::EvaluateColPartition(const ColPartition& part,
const DENORM* denorm,
bool debug) const {
if (part.IsSingleton())
return EvaluateBox(part.bounding_box(), denorm, debug);
// Test vertical orientation.
TBOX box = part.bounding_box();
// Use the partition median for left/right.
box.set_left(part.median_left());
box.set_right(part.median_right());
int vresult = EvaluateBox(box, denorm, debug);
// Test horizontal orientation.
box = part.bounding_box();
// Use the partition median for top/bottom.
box.set_top(part.median_top());
box.set_bottom(part.median_bottom());
int hresult = EvaluateBox(box, denorm, debug);
if (debug) {
tprintf("Partition hresult=%d, vresult=%d from:", hresult, vresult);
part.bounding_box().print();
part.Print();
}
return hresult >= -vresult ? hresult : vresult;
}
示例3: bounding_box
// Swaps the outlines of *this and next if needed to keep the centers in
// increasing x.
void TBLOB::CorrectBlobOrder(TBLOB* next) {
TBOX box = bounding_box();
TBOX next_box = next->bounding_box();
if (box.x_middle() > next_box.x_middle()) {
Swap(&outlines, &next->outlines);
}
}
示例4: 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());
}
示例5: 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());
}
}
}
}
}
示例6: ComputeEdgeDensityProfiles
// Converts the run-length image (see above to the edge density profiles used
// for scaling, thus:
// ______________
// |7 1_1_1_1_1 7| = 5.28
// |1|5 5 1 5 5|1| = 3.8
// |1|2 2|1|2 2|1| = 5
// |1|2 2|1|2 2|1| = 5
// |1|2 2|1|2 2|1| = 5
// |1|2 2|1|2 2|1| = 5
// |1|5_5_1_5_5|1| = 3.8
// |7_1_1_1_1_1_7| = 5.28
// 6 4 4 8 4 4 6
// . . . . . . .
// 2 4 4 0 4 4 2
// 8 8
// Each profile is the sum of the reciprocals of the pixels in the image in
// the appropriate row or column, and these are then normalized to sum to 1.
// On output hx, hy contain an extra element, which will eventually be used
// to guarantee that the top/right edge of the box (and anything beyond) always
// gets mapped to the maximum target coordinate.
static void ComputeEdgeDensityProfiles(const TBOX& box,
const GENERIC_2D_ARRAY<int>& minruns,
GenericVector<float>* hx,
GenericVector<float>* hy) {
int width = box.width();
int height = box.height();
hx->init_to_size(width + 1, 0.0);
hy->init_to_size(height + 1, 0.0);
double total = 0.0;
for (int iy = 0; iy < height; ++iy) {
for (int ix = 0; ix < width; ++ix) {
int run = minruns(ix, iy);
if (run == 0) run = 1;
float density = 1.0f / run;
(*hx)[ix] += density;
(*hy)[iy] += density;
}
total += (*hy)[iy];
}
// Normalize each profile to sum to 1.
if (total > 0.0) {
for (int ix = 0; ix < width; ++ix) {
(*hx)[ix] /= total;
}
for (int iy = 0; iy < height; ++iy) {
(*hy)[iy] /= total;
}
}
// There is an extra element in each array, so initialize to 1.
(*hx)[width] = 1.0f;
(*hy)[height] = 1.0f;
}
示例7: 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());
}
示例8: GetRectImage
// Returns an Imagedata containing the image of the given box,
// and ground truth boxes/truth text if available in the input.
// The image is not normalized in any way.
ImageData* Tesseract::GetLineData(const TBOX& line_box,
const GenericVector<TBOX>& boxes,
const GenericVector<STRING>& texts,
int start_box, int end_box,
const BLOCK& block) {
TBOX revised_box;
ImageData* image_data = GetRectImage(line_box, block, kImagePadding,
&revised_box);
if (image_data == NULL) return NULL;
image_data->set_page_number(applybox_page);
// Copy the boxes and shift them so they are relative to the image.
FCOORD block_rotation(block.re_rotation().x(), -block.re_rotation().y());
ICOORD shift = -revised_box.botleft();
GenericVector<TBOX> line_boxes;
GenericVector<STRING> line_texts;
for (int b = start_box; b < end_box; ++b) {
TBOX box = boxes[b];
box.rotate(block_rotation);
box.move(shift);
line_boxes.push_back(box);
line_texts.push_back(texts[b]);
}
GenericVector<int> page_numbers;
page_numbers.init_to_size(line_boxes.size(), applybox_page);
image_data->AddBoxes(line_boxes, line_texts, page_numbers);
return image_data;
}
示例9: fixspace_dbg
void fixspace_dbg(WERD_RES *word) {
TBOX box = word->word->bounding_box ();
BOOL8 show_map_detail = FALSE;
inT16 i;
box.print ();
#ifndef SECURE_NAMES
tprintf (" \"%s\" ", word->best_choice->string ().string ());
tprintf ("Blob count: %d (word); %d/%d (outword)\n",
word->word->gblob_list ()->length (),
word->outword->gblob_list ()->length (),
word->outword->rej_blob_list ()->length ());
word->reject_map.print (debug_fp);
tprintf ("\n");
if (show_map_detail) {
tprintf ("\"%s\"\n", word->best_choice->string ().string ());
for (i = 0; word->best_choice->string ()[i] != '\0'; i++) {
tprintf ("**** \"%c\" ****\n", word->best_choice->string ()[i]);
word->reject_map[i].full_print (debug_fp);
}
}
tprintf ("Tess Accepted: %s\n", word->tess_accepted ? "TRUE" : "FALSE");
tprintf ("Done flag: %s\n\n", word->done ? "TRUE" : "FALSE");
#endif
}
示例10: it
// Find a set of blobs that are aligned in the given vertical
// direction with the given blob. Returns a list of aligned
// blobs and the number in the list.
// For other parameters see FindAlignedBlob below.
int AlignedBlob::AlignTabs(const AlignedBlobParams& params,
bool top_to_bottom, BLOBNBOX* bbox,
BLOBNBOX_CLIST* good_points, int* end_y) {
int ptcount = 0;
BLOBNBOX_C_IT it(good_points);
TBOX box = bbox->bounding_box();
int x_start = params.right_tab ? box.right() : box.left();
while (bbox != NULL) {
// Add the blob to the list if the appropriate side is a tab candidate,
// or if we are working on a ragged tab.
if (((params.right_tab && bbox->right_tab_type() != TT_NONE) ||
(!params.right_tab && bbox->left_tab_type() != TT_NONE) ||
params.ragged) &&
(it.empty() || it.data() != bbox)) {
if (top_to_bottom)
it.add_before_then_move(bbox);
else
it.add_after_then_move(bbox);
++ptcount;
}
// Find the next blob that is aligned with the current one.
// FindAlignedBlob guarantees that forward progress will be made in the
// top_to_bottom direction, and therefore eventually it will return NULL,
// making this while (bbox != NULL) loop safe.
bbox = FindAlignedBlob(params, top_to_bottom, bbox, x_start, end_y);
if (bbox != NULL) {
box = bbox->bounding_box();
if (!params.ragged)
x_start = params.right_tab ? box.right() : box.left();
}
}
return ptcount;
}
示例11: radsearch
/** Handles a click event in a display window. */
void StrokeWidth::HandleClick(int x, int y) {
BBGrid<BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT>::HandleClick(x, y);
// Run a radial search for blobs that overlap.
BlobGridSearch radsearch(this);
radsearch.StartRadSearch(x, y, 1);
BLOBNBOX* neighbour;
FCOORD click(static_cast<float>(x), static_cast<float>(y));
while ((neighbour = radsearch.NextRadSearch()) != NULL) {
TBOX nbox = neighbour->bounding_box();
if (nbox.contains(click) && neighbour->cblob() != NULL) {
PrintBoxWidths(neighbour);
if (neighbour->neighbour(BND_LEFT) != NULL)
PrintBoxWidths(neighbour->neighbour(BND_LEFT));
if (neighbour->neighbour(BND_RIGHT) != NULL)
PrintBoxWidths(neighbour->neighbour(BND_RIGHT));
if (neighbour->neighbour(BND_ABOVE) != NULL)
PrintBoxWidths(neighbour->neighbour(BND_ABOVE));
if (neighbour->neighbour(BND_BELOW) != NULL)
PrintBoxWidths(neighbour->neighbour(BND_BELOW));
int gaps[BND_COUNT];
neighbour->NeighbourGaps(gaps);
tprintf("Left gap=%d, right=%d, above=%d, below=%d, horz=%d, vert=%d\n"
"Good= %d %d %d %d\n",
gaps[BND_LEFT], gaps[BND_RIGHT],
gaps[BND_ABOVE], gaps[BND_BELOW],
neighbour->horz_possible(),
neighbour->vert_possible(),
neighbour->good_stroke_neighbour(BND_LEFT),
neighbour->good_stroke_neighbour(BND_RIGHT),
neighbour->good_stroke_neighbour(BND_ABOVE),
neighbour->good_stroke_neighbour(BND_BELOW));
break;
}
}
}
示例12: 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;
}
示例13: IntCastRounded
// Computes the DENORMS for bl(baseline) and cn(character) normalization
// during feature extraction. The input denorm describes the current state
// of the blob, which is usually a baseline-normalized word.
// The Transforms setup are as follows:
// Baseline Normalized (bl) Output:
// We center the grapheme by aligning the x-coordinate of its centroid with
// x=128 and leaving the already-baseline-normalized y as-is.
//
// Character Normalized (cn) Output:
// We align the grapheme's centroid at the origin and scale it
// asymmetrically in x and y so that the 2nd moments are a standard value
// (51.2) ie the result is vaguely square.
// If classify_nonlinear_norm is true:
// A non-linear normalization is setup that attempts to evenly distribute
// edges across x and y.
//
// Some of the fields of fx_info are also setup:
// Length: Total length of outline.
// Rx: Rounded y second moment. (Reversed by convention.)
// Ry: rounded x second moment.
// Xmean: Rounded x center of mass of the blob.
// Ymean: Rounded y center of mass of the blob.
void Classify::SetupBLCNDenorms(const TBLOB& blob, bool nonlinear_norm,
DENORM* bl_denorm, DENORM* cn_denorm,
INT_FX_RESULT_STRUCT* fx_info) {
// Compute 1st and 2nd moments of the original outline.
FCOORD center, second_moments;
int length = blob.ComputeMoments(¢er, &second_moments);
if (fx_info != nullptr) {
fx_info->Length = length;
fx_info->Rx = IntCastRounded(second_moments.y());
fx_info->Ry = IntCastRounded(second_moments.x());
fx_info->Xmean = IntCastRounded(center.x());
fx_info->Ymean = IntCastRounded(center.y());
}
// Setup the denorm for Baseline normalization.
bl_denorm->SetupNormalization(nullptr, nullptr, &blob.denorm(), center.x(), 128.0f,
1.0f, 1.0f, 128.0f, 128.0f);
// Setup the denorm for character normalization.
if (nonlinear_norm) {
GenericVector<GenericVector<int> > x_coords;
GenericVector<GenericVector<int> > y_coords;
TBOX box;
blob.GetPreciseBoundingBox(&box);
box.pad(1, 1);
blob.GetEdgeCoords(box, &x_coords, &y_coords);
cn_denorm->SetupNonLinear(&blob.denorm(), box, UINT8_MAX, UINT8_MAX,
0.0f, 0.0f, x_coords, y_coords);
} else {
cn_denorm->SetupNormalization(nullptr, nullptr, &blob.denorm(),
center.x(), center.y(),
51.2f / second_moments.x(),
51.2f / second_moments.y(),
128.0f, 128.0f);
}
}
示例14: extract_result
// Extract the OCR results, costs (penalty points for uncertainty),
// and the bounding boxes of the characters.
static void extract_result(ELIST_ITERATOR *out,
PAGE_RES* page_res) {
PAGE_RES_IT page_res_it(page_res);
int word_count = 0;
while (page_res_it.word() != NULL) {
WERD_RES *word = page_res_it.word();
const char *str = word->best_choice->string().string();
const char *len = word->best_choice->lengths().string();
if (word_count)
add_space(out);
TBOX bln_rect;
PBLOB_LIST *blobs = word->outword->blob_list();
PBLOB_IT it(blobs);
int n = strlen(len);
TBOX** boxes_to_fix = new TBOX*[n];
for (int i = 0; i < n; i++) {
PBLOB *blob = it.data();
TBOX current = pblob_get_bbox(blob);
bln_rect.bounding_union(current);
TESS_CHAR *tc = new TESS_CHAR(rating_to_cost(word->best_choice->rating()),
str, *len);
tc->box = current;
boxes_to_fix[i] = &tc->box;
out->add_after_then_move(tc);
it.forward();
str += *len;
len++;
}
// Find the word bbox before normalization.
// Here we can't use the C_BLOB bboxes directly,
// since connected letters are not yet cut.
TBOX real_rect = c_blob_list_get_bbox(word->word->cblob_list());
// Denormalize boxes by transforming the bbox of the whole bln word
// into the denorm bbox (`real_rect') of the whole word.
double x_stretch = double(real_rect.width()) / bln_rect.width();
double y_stretch = double(real_rect.height()) / bln_rect.height();
for (int j = 0; j < n; j++) {
TBOX *box = boxes_to_fix[j];
int x0 = int(real_rect.left() +
x_stretch * (box->left() - bln_rect.left()) + 0.5);
int x1 = int(real_rect.left() +
x_stretch * (box->right() - bln_rect.left()) + 0.5);
int y0 = int(real_rect.bottom() +
y_stretch * (box->bottom() - bln_rect.bottom()) + 0.5);
int y1 = int(real_rect.bottom() +
y_stretch * (box->top() - bln_rect.bottom()) + 0.5);
*box = TBOX(ICOORD(x0, y0), ICOORD(x1, y1));
}
delete [] boxes_to_fix;
page_res_it.forward();
word_count++;
}
}
示例15: BoxMissMetric
/// Helper to compute the dispute resolution metric.
/// Disputed blob resolution. The aim is to give the blob to the most
/// appropriate boxfile box. Most of the time it is obvious, but if
/// two boxfile boxes overlap significantly it is not. If a small boxfile
/// box takes most of the blob, and a large boxfile box does too, then
/// we want the small boxfile box to get it, but if the small box
/// is much smaller than the blob, we don't want it to get it.
/// Details of the disputed blob resolution:
/// Given a box with area A, and a blob with area B, with overlap area C,
/// then the miss metric is (A-C)(B-C)/(AB) and the box with minimum
/// miss metric gets the blob.
static double BoxMissMetric(const TBOX& box1, const TBOX& box2) {
int overlap_area = box1.intersection(box2).area();
double miss_metric = box1.area()- overlap_area;
miss_metric /= box1.area();
miss_metric *= box2.area() - overlap_area;
miss_metric /= box2.area();
return miss_metric;
}