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.
| 533 | // The input denorm should be the normalizations that have been applied from |
| 534 | // the image to the current state of this TBLOB. |
| 535 | int 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. |
no test coverage detected