1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 00:03:03 +04:00

Merge pull request #28227 from dheeraj25406:docs-moments-degenerate

docs(imgproc): clarify cv::moments behavior for degenerate contours #28227

relates to https://github.com/opencv/opencv/issues/28222
Clarifies that for degenerate contours (single point or collinear points),
cv::moments() returns m00 == 0 and centroid is undefined.
Documents common workarounds such as boundingRect center or point averaging.
This commit is contained in:
Dheeraj Alamuri
2025-12-23 23:23:43 +05:30
committed by GitHub
parent 4705320496
commit d3c539bf71
2 changed files with 27 additions and 0 deletions
+15
View File
@@ -593,5 +593,20 @@ TEST(Imgproc_PointPolygonTest, regression_10222)
EXPECT_GT(result, 0) << "Desired result: point is inside polygon - actual result: point is not inside polygon";
}
TEST(Imgproc_Moments, degenerateContours)
{
std::vector<cv::Point> c1;
c1.push_back(cv::Point(10,10));
cv::Moments m1 = cv::moments(c1, false);
EXPECT_EQ(m1.m00, 0);
std::vector<cv::Point> c2;
c2.push_back(cv::Point(0,0));
c2.push_back(cv::Point(5,5));
c2.push_back(cv::Point(10,10));
cv::Moments m2 = cv::moments(c2, false);
EXPECT_EQ(m2.m00, 0);
}
}} // namespace
/* End of file. */