roboflow/supervision · error · ValueError

Cannot use `Position.CENTER_OF_MASS` without a detection mas

Error message

Cannot use `Position.CENTER_OF_MASS` without a detection mask.

What it means

Error "Cannot use `Position.CENTER_OF_MASS` without a detection mask." thrown in roboflow/supervision.

Source

Thrown at src/supervision/detection/core.py:2589

                    np.asarray(self.data[ORIENTED_BOX_COORDINATES]), anchor
                ),
            )

        xyxy = self.xyxy

        def coordinates(
            x: npt.NDArray[np.number], y: npt.NDArray[np.number]
        ) -> npt.NDArray[np.generic]:
            return cast(npt.NDArray[np.generic], np.array([x, y]).transpose())

        if anchor == Position.CENTER:
            return coordinates(
                (xyxy[:, 0] + xyxy[:, 2]) / 2,
                (xyxy[:, 1] + xyxy[:, 3]) / 2,
            )
        elif anchor == Position.CENTER_OF_MASS:
            if self.mask is None:
                raise ValueError(
                    "Cannot use `Position.CENTER_OF_MASS` without a detection mask."
                )
            return calculate_masks_centroids(masks=self.mask)
        elif anchor == Position.CENTER_LEFT:
            return coordinates(xyxy[:, 0], (xyxy[:, 1] + xyxy[:, 3]) / 2)
        elif anchor == Position.CENTER_RIGHT:
            return coordinates(xyxy[:, 2], (xyxy[:, 1] + xyxy[:, 3]) / 2)
        elif anchor == Position.BOTTOM_CENTER:
            return coordinates((xyxy[:, 0] + xyxy[:, 2]) / 2, xyxy[:, 3])
        elif anchor == Position.BOTTOM_LEFT:
            return coordinates(xyxy[:, 0], xyxy[:, 3])
        elif anchor == Position.BOTTOM_RIGHT:
            return coordinates(xyxy[:, 2], xyxy[:, 3])
        elif anchor == Position.TOP_CENTER:
            return coordinates((xyxy[:, 0] + xyxy[:, 2]) / 2, xyxy[:, 1])
        elif anchor == Position.TOP_LEFT:
            return coordinates(xyxy[:, 0], xyxy[:, 1])
        elif anchor == Position.TOP_RIGHT:

View on GitHub (pinned to 7f254d9784)

Solutions

  1. Use Position.CENTER_OF_MASS only with Detections that include a mask; otherwise choose a box-based position such as Position.CENTER.
  2. If masks are available from your model, make sure they are passed into the Detections constructor.

When it happens

Trigger: Thrown at src/supervision/detection/core.py:2589 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of roboflow/supervision@7f254d9784 (2026-08-15). Data as JSON: /api/errors/517df3e980a95b13. Report an issue: GitHub.