Skip to content

Fix wrong COCO bbox area in vector object-detection export - #885

Open
jaideeppyne wants to merge 1 commit into
superannotateai:masterfrom
jaideeppyne:fix/coco-object-detection-bbox-area
Open

Fix wrong COCO bbox area in vector object-detection export#885
jaideeppyne wants to merge 1 commit into
superannotateai:masterfrom
jaideeppyne:fix/coco-object-detection-bbox-area

Conversation

@jaideeppyne

Copy link
Copy Markdown

Problem

In sa_vector_to_coco_object_detection (SA → COCO vector export), the annotation area is computed as:

area = int((points["x2"] - points["x1"]) * points["y2"] - points["y1"])

Operator precedence parses this as ((x2 - x1) * y2) - y1, not the COCO bounding-box area (x2 - x1) * (y2 - y1) (width × height). The missing parentheses around (y2 - y1) make the error term exactly y1 * (width - 1), so the exported area is wrong for every bbox that isn't flush against the top edge (y1 == 0).

On this repo's own export golden box {x1: 437.16, y1: 341.5, x2: 465.23, y2: 357.09}:

  • current code → area = 9682
  • correct w * h437 (which is exactly what the shipped golden TestVectorAnnotationImage.json lists)

The sibling paths already do it right — instance-segmentation uses int(_area(mask)) and keypoint uses bbox[2] * bbox[3] — so the intent is unambiguous.

Fix

-        area = int((points["x2"] - points["x1"]) * points["y2"] - points["y1"])
+        area = int(bbox[2] * bbox[3])

bbox is already (x, y, width, height), so this reuses the computed width/height and mirrors the keypoint path.

Tests

Adds tests/unit/test_coco_object_detection_area.py, asserting area == int(width * height) (and == 437 for the golden box). It fails on the current code (assert 9682 == 437) and passes with the fix.

The existing export tests never caught this because they only assert output filename equality (filecmp.dircmp left_only/right_only) and never compare file contents — so the wrong area values were never checked.

`sa_vector_to_coco_object_detection` computed the annotation `area` as
`(x2 - x1) * y2 - y1`. Operator precedence makes that `((x2 - x1) * y2) - y1`
instead of the COCO box area `(x2 - x1) * (y2 - y1)` (width * height). The error
term is `y1 * (width - 1)`, so `area` is wrong for every exported bbox that does
not sit against the top edge (`y1 == 0`). On the repo's own export golden box
`{x1:437.16, y1:341.5, x2:465.23, y2:357.09}` the old code yields 9682 while the
correct area is 437 (~22x off).

Reuse the already-computed `bbox` width/height (`int(bbox[2] * bbox[3])`),
matching the keypoint path and the instance-segmentation path. Intent is
unambiguous: the shipped golden fixture encodes width*height.

Adds a unit test asserting `area == int(width * height)` (and == 437 for that
box). It fails on the current code (9682) and passes with the fix. The existing
export tests never caught this because they only assert output filename equality
(`filecmp.dircmp`), never file contents.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant