roboflow/supervision · error · ValueError

The magnitude of the vector cannot be zero.

Error message

The magnitude of the vector cannot be zero.

What it means

LineZone's internal _calculate_region_of_interest_limits computes a unit vector and its perpendicular from the zone's direction vector; a zero-magnitude vector (start point equals end point) makes the division undefined, so a ValueError is raised. A degenerate line has no direction to cross, so the geometry cannot be built.

Source

Thrown at src/supervision/detection/line_zone.py:239

    def _evict_stale_crossing_history(self, current_keys: set[int]) -> None:
        for key in list(self.crossing_state_history):
            if key in current_keys:
                self._tracker_frames_absent.pop(key, None)
            else:
                absent = self._tracker_frames_absent.get(key, 0) + 1
                if absent >= self.crossing_history_length:
                    del self.crossing_state_history[key]
                    self._tracker_frames_absent.pop(key, None)
                else:
                    self._tracker_frames_absent[key] = absent

    @staticmethod
    def _calculate_region_of_interest_limits(vector: Vector) -> tuple[Vector, Vector]:
        magnitude = vector.magnitude

        if magnitude == 0:
            raise ValueError("The magnitude of the vector cannot be zero.")

        delta_x = vector.end.x - vector.start.x
        delta_y = vector.end.y - vector.start.y

        unit_vector_x = delta_x / magnitude
        unit_vector_y = delta_y / magnitude

        perpendicular_vector_x = -unit_vector_y
        perpendicular_vector_y = unit_vector_x

        start_region_limit = Vector(
            start=vector.start,
            end=Point(
                x=vector.start.x + perpendicular_vector_x,
                y=vector.start.y + perpendicular_vector_y,
            ),
        )
        end_region_limit = Vector(

View on GitHub (pinned to 7f254d9784)

Solutions

  1. Ensure start and end differ in at least one coordinate before constructing LineZone.
  2. Check the source frame dimensions when endpoints are computed as fractions of frame size.
  3. When zones are user-drawn, reject clicks where start == end and prompt again.

Example fix

# before
 zone = sv.LineZone(
     start=sv.Point(x=cx, y=cy), end=sv.Point(x=cx, y=cy)
 )

# after
 if start == end:
     raise ValueError("LineZone start and end must differ")
 zone = sv.LineZone(start=start, end=end)
Defensive patterns

Strategy: validation

Validate before calling

if start.x == end.x and start.y == end.y:
    raise ValueError("LineZone start and end must not be the same point")
zone = sv.LineZone(start=start, end=end)

Type guard

def is_degenerate_line(start: sv.Point, end: sv.Point) -> bool:
    return start.x == end.x and start.y == end.y

Prevention

When it happens

Trigger: sv.LineZone(start=Point(x=100, y=200), end=Point(x=100, y=200)) — identical start and end; or a line built from computed points (e.g. percentage offsets of frame size) that collapse to the same coordinate due to rounding or a zero-size frame.

Common situations: Generating line endpoints from percentages of a frame that failed to load (width=height=0); rounding both endpoints to the same pixel; dynamically drawn zones where the user clicked the same point twice.

Related errors


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