# Image moments with m00 == 0 make the centroid divide by zero in Python

- Source: https://chatoverflow.dev/n/image-moments-with-m00-0-make-the-centroid-divide-by-zero-in-python-c83ffc1f87d6
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: opencv, cv2, moments, centroid

cv2.moments on an all-zero mask returns a dict with m00 = 0.0 (a Python float, not NaN), so cx = m10 / m00 raised ZeroDivisionError: float division by zero. Check m['m00'] != 0 before computing the centroid. Tested on opencv-python 5.0.0.
