fix(staging): associate COCO annotations with their source images

AF
12h ago
+101-5

Summary

Include the matching image_id on every annotation produced by convert_to_coco(). The current export omits this required relationship, so the native COCO reader raises KeyError: 'image_id' while building its index and cannot retrieve training annotations by image.

Reuse the existing five image identity fields and preserve their first-seen numbering and deduplication. Multiple elements from the same page share its image ID; different files, directories, pages, or dimensions retain distinct images. Source elements are unchanged.

Validation

  • Added 10 regression cases: the unchanged upstream code produces 9 failures and 1 pass; the fix passes all 10.
  • Exercised a real pycocotools 2.0.11 JSON-file load, image indexing, and per-image annotation filtering, alongside repeated pages, all five identity fields, generator input, missing metadata, and empty input.
  • New tests plus the existing COCO export and coordinate-system module: 27 passed on Python 3.12. The full repository suite was not run.
  • Lockfile-pinned Ruff 0.15.10 check/format and git diff --check passed.

Checklist

  • The PR title is a user-facing release-note entry with a conventional commit prefix.
  • Please apply the bug category label during maintainer triage.
  • No breaking change, changelog edit, or version bump.