MCPcopy Create free account
hub / github.com/creatale/node-dv / ComputeMoments

Method ComputeMoments

deps/tesseract/ccstruct/blobs.cpp:535–550  ·  view source on GitHub ↗

Computes the center of mass and second moments for the old baseline and 2nd moment normalizations. Returns the outline length. The input denorm should be the normalizations that have been applied from the image to the current state of this TBLOB.

Source from the content-addressed store, hash-verified

533// The input denorm should be the normalizations that have been applied from
534// the image to the current state of this TBLOB.
535int TBLOB::ComputeMoments(FCOORD* center, FCOORD* second_moments) const {
536 // Compute 1st and 2nd moments of the original outline.
537 LLSQ accumulator;
538 TBOX box = bounding_box();
539 // Iterate the outlines, accumulating edges relative the box.botleft().
540 CollectEdges(box, NULL, &accumulator, NULL, NULL);
541 *center = accumulator.mean_point() + box.botleft();
542 // The 2nd moments are just the standard deviation of the point positions.
543 double x2nd = sqrt(accumulator.x_variance());
544 double y2nd = sqrt(accumulator.y_variance());
545 if (x2nd < 1.0) x2nd = 1.0;
546 if (y2nd < 1.0) y2nd = 1.0;
547 second_moments->set_x(x2nd);
548 second_moments->set_y(y2nd);
549 return accumulator.count();
550}
551
552// Computes the precise bounding box of the coords that are generated by
553// GetEdgeCoords. This may be different from the bounding box of the polygon.

Callers 1

SetupBLCNDenormsMethod · 0.80

Calls 8

sqrtFunction · 0.85
mean_pointMethod · 0.80
x_varianceMethod · 0.80
y_varianceMethod · 0.80
set_xMethod · 0.80
set_yMethod · 0.80
bounding_boxFunction · 0.70
countMethod · 0.45

Tested by

no test coverage detected