Mirrored from upstream: opencv#28222
Original author: @PierreChatelier · created 2025-12-18T07:41:27Z
Upstream labels: category: core, category: documentation
Selection: mirrored by mirror-issues.py
System Information
OpenCV 4.12.0
Windows 7
MSVC 2019+
Detailed description
std::vector<cv::Point> contour = {...};
cv::Moments m = cv::moments(contour);
as documented, cv:moments() can be used to determine the mass center of a set of points : $\bar{x}=\frac{m_{10}}{m_{00}}$, $\bar{y}=\frac{m_{01}}{m_{00}}$
However, it fails if :
- the contour is a single point
- the contour is a set of aligned points
in that case, m00 will be 0
I undersand that 2nd and 3rd order might be ill defined in that case, but my main use case if the mass center, and it's a pity to see it fail there.
Should it be fixed or only documented ?
Steps to reproduce
cv::vectorcv::Point p1 = {{1, 2}};
cv::vectorcv::Point ps = {{1, 2}, {2, 2}, {3, 2}};
cv::Moment m1 = cv::moments(p1); //m1.m00 is 0
cv::Moment ms = cv::moments(ps); //ms.m00 is 0
Issue submission checklist
System Information
OpenCV 4.12.0
Windows 7
MSVC 2019+
Detailed description
as documented,$\bar{x}=\frac{m_{10}}{m_{00}}$ , $\bar{y}=\frac{m_{01}}{m_{00}}$
cv:moments()can be used to determine the mass center of a set of points :However, it fails if :
in that case,
m00will be 0I undersand that 2nd and 3rd order might be ill defined in that case, but my main use case if the mass center, and it's a pity to see it fail there.
Should it be fixed or only documented ?
Steps to reproduce
cv::vectorcv::Point p1 = {{1, 2}};
cv::vectorcv::Point ps = {{1, 2}, {2, 2}, {3, 2}};
cv::Moment m1 = cv::moments(p1); //m1.m00 is 0
cv::Moment ms = cv::moments(ps); //ms.m00 is 0
Issue submission checklist