John Ho Claude Opus 4.8 (1M context) commited on
Commit
df4e114
·
1 Parent(s): 21ec205

Turn pilbox into a lite bbox annotation module with a CLI

Browse files

Rewrite pilbox.py as a standalone, importable bounding-box annotation
module depending only on numpy + Pillow + loguru (drop the broken
matplotlib.colors reference and add a proper import block).

- annotate(): main entry point using pascal_voc {x0,y0,x1,y1} boxes,
returns an annotated copy, configurable label/color keys
- palette_color()/color_for(): unbounded golden-angle HSV palette
replacing the matplotlib color logic
- im_draw_bbox(): filled label tab above the box top-left corner
- keep im_crop/im_center_crop/im_draw_point/load_pil_font for later

Add annotate_cli.py (typer + loguru) to annotate an image from a JSON
file, tests/ with unit tests + doctests, example assets, and update
CLAUDE.md.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

CLAUDE.md CHANGED
@@ -46,15 +46,38 @@ Space metadata (title, emoji, sdk_version) lives in the YAML front-matter of `RE
46
  - Flash Attention is pip-installed at runtime via a `subprocess.run` at the top of the file
47
  (ZeroGPU quirk), but the zoo currently loads models with `use_flash_attention=False`.
48
 
49
- ## Bounding-box conventions (boxer.py / pilbox.py)
50
 
51
  - Standard bbox dict is `{x0, y0, x1, y1}` (top-left / bottom-right absolute pixels).
52
  Note `boxer()` returns `{x1, x2, y1, y2}` instead — a different key convention.
53
  - `bbox_convert` auto-detects relative vs absolute by testing whether all coords are `<= 1`.
54
  - `bboxes_to_im_mask` and image crops use numpy `[y, x]` (row, col) indexing throughout.
55
- - `pilbox.py` references `os`, `logger`, `warnings`, and PIL (`Image`, `ImageDraw`,
56
- `ImageFont`) but has no import block — it is meant to be spliced into a host module, not
57
- run standalone.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
 
60
  ## Guidelines
 
46
  - Flash Attention is pip-installed at runtime via a `subprocess.run` at the top of the file
47
  (ZeroGPU quirk), but the zoo currently loads models with `use_flash_attention=False`.
48
 
49
+ ## Bounding-box conventions (boxer.py)
50
 
51
  - Standard bbox dict is `{x0, y0, x1, y1}` (top-left / bottom-right absolute pixels).
52
  Note `boxer()` returns `{x1, x2, y1, y2}` instead — a different key convention.
53
  - `bbox_convert` auto-detects relative vs absolute by testing whether all coords are `<= 1`.
54
  - `bboxes_to_im_mask` and image crops use numpy `[y, x]` (row, col) indexing throughout.
55
+
56
+ ## pilbox.py — lite bbox annotation module
57
+
58
+ `pilbox.py` is a standalone, importable annotation module depending only on **numpy +
59
+ Pillow + loguru** (no matplotlib). It uses the **pascal_voc** convention: each box is a
60
+ dict `{x0, y0, x1, y1}` of absolute top-left / bottom-right pixels (matching the
61
+ `boundingBox` in `assets/example_0.json`).
62
+
63
+ - `annotate(image, objects, *, label_key="object_id", color_key="object_id",
64
+ bbox_key="boundingBox", width=3, font=None) -> Image.Image` is the main entry point.
65
+ It returns an annotated **copy** (never mutates the input). Each distinct `color_key`
66
+ value gets its own color; `label_key`'s value is drawn as a filled label tab above the
67
+ box's top-left corner.
68
+ - Colors come from `palette_color(index)` — golden-angle HSV hues, so the palette is
69
+ **unbounded** (never runs out). `color_for(key, mapping)` assigns a stable palette index
70
+ per unique key. (`PIL.ImageColor.colormap` is the named-color alternative.)
71
+ - `annotate_file(image_path, annotations_path, output_path, ...)` wraps load → annotate →
72
+ save for the CLI.
73
+ - `im_crop`, `im_center_crop`, `im_draw_point`, `load_pil_font` are retained helpers.
74
+
75
+ CLI: `annotate_cli.py` (typer + loguru, run separately so `import pilbox` stays lite):
76
+
77
+ ```bash
78
+ uv run python annotate_cli.py assets/example_0_in.jpg assets/example_0.json -o out.jpg
79
+ # options: --label-key --color-key --width --font-size
80
+ ```
81
 
82
 
83
  ## Guidelines
annotate_cli.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Typer CLI to annotate an image with bounding boxes from a JSON file.
2
+
3
+ Run with uv, e.g.::
4
+
5
+ uv run python annotate_cli.py assets/example_0_in.jpg assets/example_0.json
6
+
7
+ The JSON must be a list of object dicts, each with a pascal_voc ``boundingBox``
8
+ (``{x0, y0, x1, y1}``); see ``assets/example_0.json``.
9
+ """
10
+
11
+ from pathlib import Path
12
+ from typing import Optional
13
+
14
+ import typer
15
+ from loguru import logger
16
+
17
+ import pilbox
18
+
19
+ app = typer.Typer(add_completion=False, help=__doc__)
20
+
21
+
22
+ @app.command()
23
+ def main(
24
+ image: Path = typer.Argument(
25
+ ..., exists=True, dir_okay=False, readable=True, help="Source image path."
26
+ ),
27
+ annotations: Path = typer.Argument(
28
+ ..., exists=True, dir_okay=False, readable=True, help="JSON annotations path."
29
+ ),
30
+ output: Optional[Path] = typer.Option(
31
+ None, "--output", "-o", help="Output path (default: <image>_out.jpg)."
32
+ ),
33
+ label_key: str = typer.Option(
34
+ "object_id", "--label-key", help="Object key drawn as each box's label."
35
+ ),
36
+ color_key: str = typer.Option(
37
+ "object_id", "--color-key", help="Object key used to color-group boxes."
38
+ ),
39
+ width: int = typer.Option(3, "--width", help="Box outline width in pixels."),
40
+ font_size: int = typer.Option(20, "--font-size", help="Label font size."),
41
+ ):
42
+ """Draw bounding boxes from ANNOTATIONS onto IMAGE and save the result."""
43
+ out_path = output or image.with_name(f"{image.stem}_out.jpg")
44
+ logger.info(f"annotating {image} with {annotations} -> {out_path}")
45
+ pilbox.annotate_file(
46
+ str(image),
47
+ str(annotations),
48
+ str(out_path),
49
+ label_key=label_key,
50
+ color_key=color_key,
51
+ width=width,
52
+ font_size=font_size,
53
+ )
54
+ logger.info(f"saved {out_path}")
55
+
56
+
57
+ if __name__ == "__main__":
58
+ app()
assets/17078229_3222904-SAM2_tiny_ZeroGPU.json ADDED
@@ -0,0 +1 @@
 
 
1
+ [{"frame": 118, "track_id": 0, "x": 0.5157407407407407, "y": 0.36041666666666666, "w": 0.11944444444444445, "h": 0.16145833333333334, "conf": 1}, {"frame": 118, "track_id": 1, "x": 0.33240740740740743, "y": 0.45, "w": 0.1925925925925926, "h": 0.19010416666666666, "conf": 1}, {"frame": 119, "track_id": 0, "x": 0.5166666666666667, "y": 0.365625, "w": 0.11481481481481481, "h": 0.1609375, "conf": 1}, {"frame": 119, "track_id": 1, "x": 0.3453703703703704, "y": 0.4473958333333333, "w": 0.18518518518518517, "h": 0.18958333333333333, "conf": 1}, {"frame": 120, "track_id": 0, "x": 0.4981481481481482, "y": 0.3734375, "w": 0.12222222222222222, "h": 0.16041666666666668, "conf": 1}, {"frame": 120, "track_id": 1, "x": 0.34814814814814815, "y": 0.4421875, "w": 0.1648148148148148, "h": 0.18854166666666666, "conf": 1}, {"frame": 121, "track_id": 0, "x": 0.4861111111111111, "y": 0.3802083333333333, "w": 0.12685185185185185, "h": 0.15989583333333332, "conf": 1}, {"frame": 121, "track_id": 1, "x": 0.3527777777777778, "y": 0.4390625, "w": 0.14537037037037037, "h": 0.19010416666666666, "conf": 1}, {"frame": 122, "track_id": 0, "x": 0.48148148148148145, "y": 0.38333333333333336, "w": 0.1287037037037037, "h": 0.1609375, "conf": 1}, {"frame": 122, "track_id": 1, "x": 0.362962962962963, "y": 0.4359375, "w": 0.1388888888888889, "h": 0.190625, "conf": 1}, {"frame": 123, "track_id": 0, "x": 0.4759259259259259, "y": 0.38333333333333336, "w": 0.13425925925925927, "h": 0.1609375, "conf": 1}, {"frame": 123, "track_id": 1, "x": 0.3509259259259259, "y": 0.4359375, "w": 0.15092592592592594, "h": 0.1890625, "conf": 1}, {"frame": 124, "track_id": 0, "x": 0.4925925925925926, "y": 0.390625, "w": 0.12222222222222222, "h": 0.15989583333333332, "conf": 1}, {"frame": 124, "track_id": 1, "x": 0.3768518518518518, "y": 0.4328125, "w": 0.1425925925925926, "h": 0.18333333333333332, "conf": 1}, {"frame": 125, "track_id": 0, "x": 0.5083333333333333, "y": 0.3963541666666667, "w": 0.11388888888888889, "h": 0.15677083333333333, "conf": 1}, {"frame": 125, "track_id": 1, "x": 0.4083333333333333, "y": 0.43125, "w": 0.13148148148148148, "h": 0.178125, "conf": 1}, {"frame": 126, "track_id": 0, "x": 0.5027777777777778, "y": 0.4010416666666667, "w": 0.13425925925925927, "h": 0.15677083333333333, "conf": 1}, {"frame": 126, "track_id": 1, "x": 0.43148148148148147, "y": 0.4265625, "w": 0.13703703703703704, "h": 0.178125, "conf": 1}, {"frame": 127, "track_id": 0, "x": 0.5416666666666666, "y": 0.40520833333333334, "w": 0.11666666666666667, "h": 0.15104166666666666, "conf": 1}, {"frame": 127, "track_id": 1, "x": 0.4546296296296296, "y": 0.425, "w": 0.1388888888888889, "h": 0.1734375, "conf": 1}, {"frame": 128, "track_id": 0, "x": 0.5416666666666666, "y": 0.40520833333333334, "w": 0.11666666666666667, "h": 0.1515625, "conf": 1}, {"frame": 128, "track_id": 1, "x": 0.4537037037037037, "y": 0.425, "w": 0.1398148148148148, "h": 0.1734375, "conf": 1}, {"frame": 129, "track_id": 0, "x": 0.5564814814814815, "y": 0.40729166666666666, "w": 0.10555555555555556, "h": 0.15572916666666667, "conf": 1}, {"frame": 129, "track_id": 1, "x": 0.47962962962962963, "y": 0.421875, "w": 0.14074074074074075, "h": 0.171875, "conf": 1}, {"frame": 130, "track_id": 0, "x": 0.5712962962962963, "y": 0.4088541666666667, "w": 0.11388888888888889, "h": 0.15885416666666666, "conf": 1}, {"frame": 130, "track_id": 1, "x": 0.5, "y": 0.4192708333333333, "w": 0.1398148148148148, "h": 0.17135416666666667, "conf": 1}, {"frame": 131, "track_id": 0, "x": 0.5907407407407408, "y": 0.4083333333333333, "w": 0.11018518518518519, "h": 0.16145833333333334, "conf": 1}, {"frame": 131, "track_id": 1, "x": 0.5212962962962963, "y": 0.41302083333333334, "w": 0.14537037037037037, "h": 0.17239583333333333, "conf": 1}, {"frame": 132, "track_id": 0, "x": 0.6027777777777777, "y": 0.4276041666666667, "w": 0.08981481481481482, "h": 0.14427083333333332, "conf": 1}, {"frame": 132, "track_id": 1, "x": 0.5342592592592592, "y": 0.40677083333333336, "w": 0.1425925925925926, "h": 0.175, "conf": 1}, {"frame": 133, "track_id": 0, "x": 0.6027777777777777, "y": 0.4354166666666667, "w": 0.07685185185185185, "h": 0.13697916666666668, "conf": 1}, {"frame": 133, "track_id": 1, "x": 0.5333333333333333, "y": 0.40677083333333336, "w": 0.14444444444444443, "h": 0.175, "conf": 1}, {"frame": 134, "track_id": 0, "x": 0.6064814814814815, "y": 0.4197916666666667, "w": 0.08611111111111111, "h": 0.15260416666666668, "conf": 1}, {"frame": 134, "track_id": 1, "x": 0.5398148148148149, "y": 0.40520833333333334, "w": 0.14166666666666666, "h": 0.175, "conf": 1}, {"frame": 135, "track_id": 0, "x": 0.6092592592592593, "y": 0.5192708333333333, "w": 0.04259259259259259, "h": 0.053125, "conf": 1}, {"frame": 135, "track_id": 1, "x": 0.5462962962962963, "y": 0.4041666666666667, "w": 0.13796296296296295, "h": 0.17291666666666666, "conf": 1}, {"frame": 136, "track_id": 0, "x": 0.6129629629629629, "y": 0.5177083333333333, "w": 0.041666666666666664, "h": 0.05520833333333333, "conf": 1}, {"frame": 136, "track_id": 1, "x": 0.5481481481481482, "y": 0.40572916666666664, "w": 0.14629629629629629, "h": 0.16979166666666667, "conf": 1}, {"frame": 137, "track_id": 0, "x": 0.6231481481481481, "y": 0.5171875, "w": 0.04259259259259259, "h": 0.05572916666666667, "conf": 1}, {"frame": 137, "track_id": 1, "x": 0.5537037037037037, "y": 0.40677083333333336, "w": 0.15555555555555556, "h": 0.16875, "conf": 1}, {"frame": 138, "track_id": 0, "x": 0.6231481481481481, "y": 0.5171875, "w": 0.04259259259259259, "h": 0.05572916666666667, "conf": 1}, {"frame": 138, "track_id": 1, "x": 0.5537037037037037, "y": 0.40625, "w": 0.1574074074074074, "h": 0.16927083333333334, "conf": 1}, {"frame": 139, "track_id": 0, "x": 0.6277777777777778, "y": 0.5182291666666666, "w": 0.04259259259259259, "h": 0.0546875, "conf": 1}, {"frame": 139, "track_id": 1, "x": 0.5583333333333333, "y": 0.40677083333333336, "w": 0.1574074074074074, "h": 0.171875, "conf": 1}, {"frame": 140, "track_id": 0, "x": 0.6305555555555555, "y": 0.5192708333333333, "w": 0.041666666666666664, "h": 0.05364583333333333, "conf": 1}, {"frame": 140, "track_id": 1, "x": 0.5685185185185185, "y": 0.40989583333333335, "w": 0.15555555555555556, "h": 0.17291666666666666, "conf": 1}, {"frame": 141, "track_id": 0, "x": 0.5990740740740741, "y": 0.5208333333333334, "w": 0.07777777777777778, "h": 0.05260416666666667, "conf": 1}, {"frame": 141, "track_id": 1, "x": 0.5842592592592593, "y": 0.4546875, "w": 0.1398148148148148, "h": 0.1328125, "conf": 1}, {"frame": 142, "track_id": 0, "x": 0.6462962962962963, "y": 0.5447916666666667, "w": 0.03425925925925926, "h": 0.028125, "conf": 1}, {"frame": 142, "track_id": 1, "x": 0.600925925925926, "y": 0.5380208333333333, "w": 0.13425925925925927, "h": 0.05364583333333333, "conf": 1}, {"frame": 143, "track_id": 0, "x": 0.6462962962962963, "y": 0.5442708333333334, "w": 0.03425925925925926, "h": 0.029166666666666667, "conf": 1}, {"frame": 143, "track_id": 1, "x": 0.600925925925926, "y": 0.5385416666666667, "w": 0.13425925925925927, "h": 0.053125, "conf": 1}, {"frame": 144, "track_id": 1, "x": 0.6175925925925926, "y": 0.43802083333333336, "w": 0.09907407407407408, "h": 0.15833333333333333, "conf": 1}, {"frame": 145, "track_id": 1, "x": 0.6148148148148148, "y": 0.5369791666666667, "w": 0.06759259259259259, "h": 0.06041666666666667, "conf": 1}, {"frame": 146, "track_id": 1, "x": 0.6240740740740741, "y": 0.4666666666666667, "w": 0.05462962962962963, "h": 0.134375, "conf": 1}, {"frame": 147, "track_id": 1, "x": 0.625, "y": 0.46979166666666666, "w": 0.025925925925925925, "h": 0.11614583333333334, "conf": 1}, {"frame": 148, "track_id": 1, "x": 0.6240740740740741, "y": 0.47239583333333335, "w": 0.025925925925925925, "h": 0.11302083333333333, "conf": 1}, {"frame": 159, "track_id": 0, "x": 0.6092592592592593, "y": 0.4270833333333333, "w": 0.15092592592592594, "h": 0.13697916666666668, "conf": 1}, {"frame": 159, "track_id": 1, "x": 0.6101851851851852, "y": 0.4276041666666667, "w": 0.15092592592592594, "h": 0.13697916666666668, "conf": 1}, {"frame": 160, "track_id": 0, "x": 0.6037037037037037, "y": 0.4276041666666667, "w": 0.12962962962962962, "h": 0.11458333333333333, "conf": 1}, {"frame": 160, "track_id": 1, "x": 0.6037037037037037, "y": 0.4270833333333333, "w": 0.13148148148148148, "h": 0.115625, "conf": 1}, {"frame": 161, "track_id": 0, "x": 0.5962962962962963, "y": 0.43020833333333336, "w": 0.1287037037037037, "h": 0.18541666666666667, "conf": 1}, {"frame": 161, "track_id": 1, "x": 0.5953703703703703, "y": 0.43020833333333336, "w": 0.12962962962962962, "h": 0.1859375, "conf": 1}, {"frame": 162, "track_id": 0, "x": 0.6074074074074074, "y": 0.5234375, "w": 0.13333333333333333, "h": 0.0859375, "conf": 1}, {"frame": 162, "track_id": 1, "x": 0.6064814814814815, "y": 0.5229166666666667, "w": 0.13425925925925927, "h": 0.0875, "conf": 1}, {"frame": 163, "track_id": 0, "x": 0.6074074074074074, "y": 0.5234375, "w": 0.13425925925925927, "h": 0.0859375, "conf": 1}, {"frame": 163, "track_id": 1, "x": 0.6074074074074074, "y": 0.5234375, "w": 0.13425925925925927, "h": 0.08645833333333333, "conf": 1}, {"frame": 164, "track_id": 0, "x": 0.5796296296296296, "y": 0.5, "w": 0.15185185185185185, "h": 0.09791666666666667, "conf": 1}, {"frame": 164, "track_id": 1, "x": 0.5787037037037037, "y": 0.5, "w": 0.15185185185185185, "h": 0.09791666666666667, "conf": 1}, {"frame": 165, "track_id": 0, "x": 0.6407407407407407, "y": 0.5526041666666667, "w": 0.06851851851851852, "h": 0.0390625, "conf": 1}, {"frame": 165, "track_id": 1, "x": 0.6407407407407407, "y": 0.5526041666666667, "w": 0.07037037037037037, "h": 0.0390625, "conf": 1}, {"frame": 166, "track_id": 0, "x": 0.5898148148148148, "y": 0.43385416666666665, "w": 0.08796296296296297, "h": 0.023958333333333335, "conf": 1}, {"frame": 166, "track_id": 1, "x": 0.5861111111111111, "y": 0.43333333333333335, "w": 0.09259259259259259, "h": 0.024479166666666666, "conf": 1}, {"frame": 172, "track_id": 0, "x": 0.5342592592592592, "y": 0.43697916666666664, "w": 0.09259259259259259, "h": 0.028125, "conf": 1}, {"frame": 172, "track_id": 1, "x": 0.5314814814814814, "y": 0.43697916666666664, "w": 0.1, "h": 0.029166666666666667, "conf": 1}, {"frame": 174, "track_id": 0, "x": 0.5212962962962963, "y": 0.43802083333333336, "w": 0.11851851851851852, "h": 0.04479166666666667, "conf": 1}, {"frame": 174, "track_id": 1, "x": 0.5203703703703704, "y": 0.4375, "w": 0.12222222222222222, "h": 0.04583333333333333, "conf": 1}, {"frame": 175, "track_id": 0, "x": 0.5166666666666667, "y": 0.43697916666666664, "w": 0.1287037037037037, "h": 0.0796875, "conf": 1}, {"frame": 175, "track_id": 1, "x": 0.5157407407407407, "y": 0.4375, "w": 0.14907407407407408, "h": 0.078125, "conf": 1}, {"frame": 176, "track_id": 0, "x": 0.5101851851851852, "y": 0.43802083333333336, "w": 0.12407407407407407, "h": 0.0953125, "conf": 1}, {"frame": 176, "track_id": 1, "x": 0.5092592592592593, "y": 0.43802083333333336, "w": 0.1259259259259259, "h": 0.09427083333333333, "conf": 1}, {"frame": 177, "track_id": 0, "x": 0.5027777777777778, "y": 0.4375, "w": 0.1259259259259259, "h": 0.11197916666666667, "conf": 1}, {"frame": 177, "track_id": 1, "x": 0.5018518518518519, "y": 0.43697916666666664, "w": 0.14444444444444443, "h": 0.1125, "conf": 1}, {"frame": 178, "track_id": 0, "x": 0.5027777777777778, "y": 0.4375, "w": 0.1259259259259259, "h": 0.1125, "conf": 1}, {"frame": 178, "track_id": 1, "x": 0.5018518518518519, "y": 0.43697916666666664, "w": 0.15185185185185185, "h": 0.11302083333333333, "conf": 1}, {"frame": 179, "track_id": 0, "x": 0.49537037037037035, "y": 0.43802083333333336, "w": 0.1388888888888889, "h": 0.11614583333333334, "conf": 1}, {"frame": 179, "track_id": 1, "x": 0.49444444444444446, "y": 0.43802083333333336, "w": 0.14074074074074075, "h": 0.11666666666666667, "conf": 1}, {"frame": 180, "track_id": 0, "x": 0.4935185185185185, "y": 0.4375, "w": 0.15925925925925927, "h": 0.071875, "conf": 1}, {"frame": 180, "track_id": 1, "x": 0.4925925925925926, "y": 0.4375, "w": 0.1574074074074074, "h": 0.07239583333333334, "conf": 1}, {"frame": 181, "track_id": 0, "x": 0.487962962962963, "y": 0.43802083333333336, "w": 0.09722222222222222, "h": 0.03958333333333333, "conf": 1}, {"frame": 181, "track_id": 1, "x": 0.48703703703703705, "y": 0.43802083333333336, "w": 0.1, "h": 0.040625, "conf": 1}, {"frame": 182, "track_id": 0, "x": 0.4898148148148148, "y": 0.43802083333333336, "w": 0.09814814814814815, "h": 0.04635416666666667, "conf": 1}, {"frame": 182, "track_id": 1, "x": 0.4888888888888889, "y": 0.43802083333333336, "w": 0.10092592592592593, "h": 0.046875, "conf": 1}, {"frame": 183, "track_id": 0, "x": 0.4898148148148148, "y": 0.43802083333333336, "w": 0.09814814814814815, "h": 0.04635416666666667, "conf": 1}, {"frame": 183, "track_id": 1, "x": 0.4888888888888889, "y": 0.43802083333333336, "w": 0.10092592592592593, "h": 0.046875, "conf": 1}, {"frame": 184, "track_id": 0, "x": 0.4888888888888889, "y": 0.43802083333333336, "w": 0.13518518518518519, "h": 0.08854166666666667, "conf": 1}, {"frame": 184, "track_id": 1, "x": 0.4888888888888889, "y": 0.43802083333333336, "w": 0.1388888888888889, "h": 0.0890625, "conf": 1}, {"frame": 185, "track_id": 0, "x": 0.49166666666666664, "y": 0.43697916666666664, "w": 0.10277777777777777, "h": 0.1171875, "conf": 1}, {"frame": 185, "track_id": 1, "x": 0.49166666666666664, "y": 0.43697916666666664, "w": 0.1037037037037037, "h": 0.11770833333333333, "conf": 1}, {"frame": 186, "track_id": 0, "x": 0.4962962962962963, "y": 0.4359375, "w": 0.10833333333333334, "h": 0.07239583333333334, "conf": 1}, {"frame": 186, "track_id": 1, "x": 0.4962962962962963, "y": 0.4359375, "w": 0.10833333333333334, "h": 0.07395833333333333, "conf": 1}, {"frame": 187, "track_id": 0, "x": 0.4981481481481482, "y": 0.4354166666666667, "w": 0.10925925925925926, "h": 0.14739583333333334, "conf": 1}, {"frame": 187, "track_id": 1, "x": 0.4981481481481482, "y": 0.4354166666666667, "w": 0.10925925925925926, "h": 0.14739583333333334, "conf": 1}, {"frame": 188, "track_id": 0, "x": 0.4981481481481482, "y": 0.4354166666666667, "w": 0.10833333333333334, "h": 0.14739583333333334, "conf": 1}, {"frame": 188, "track_id": 1, "x": 0.4981481481481482, "y": 0.4354166666666667, "w": 0.10925925925925926, "h": 0.146875, "conf": 1}, {"frame": 189, "track_id": 0, "x": 0.5, "y": 0.434375, "w": 0.12777777777777777, "h": 0.16197916666666667, "conf": 1}, {"frame": 189, "track_id": 1, "x": 0.49907407407407406, "y": 0.43385416666666665, "w": 0.12962962962962962, "h": 0.1625, "conf": 1}, {"frame": 190, "track_id": 0, "x": 0.5, "y": 0.43333333333333335, "w": 0.12685185185185185, "h": 0.18697916666666667, "conf": 1}, {"frame": 190, "track_id": 1, "x": 0.5, "y": 0.43333333333333335, "w": 0.12685185185185185, "h": 0.1875, "conf": 1}, {"frame": 191, "track_id": 0, "x": 0.5009259259259259, "y": 0.43333333333333335, "w": 0.1287037037037037, "h": 0.18697916666666667, "conf": 1}, {"frame": 191, "track_id": 1, "x": 0.5009259259259259, "y": 0.43333333333333335, "w": 0.12777777777777777, "h": 0.1875, "conf": 1}, {"frame": 192, "track_id": 0, "x": 0.5009259259259259, "y": 0.4322916666666667, "w": 0.12962962962962962, "h": 0.17447916666666666, "conf": 1}, {"frame": 192, "track_id": 1, "x": 0.5018518518518519, "y": 0.4322916666666667, "w": 0.12777777777777777, "h": 0.175, "conf": 1}, {"frame": 193, "track_id": 0, "x": 0.5009259259259259, "y": 0.4322916666666667, "w": 0.12962962962962962, "h": 0.17395833333333333, "conf": 1}, {"frame": 193, "track_id": 1, "x": 0.5009259259259259, "y": 0.4322916666666667, "w": 0.12962962962962962, "h": 0.175, "conf": 1}, {"frame": 194, "track_id": 0, "x": 0.5009259259259259, "y": 0.43020833333333336, "w": 0.12962962962962962, "h": 0.15572916666666667, "conf": 1}, {"frame": 194, "track_id": 1, "x": 0.5009259259259259, "y": 0.43072916666666666, "w": 0.13055555555555556, "h": 0.15520833333333334, "conf": 1}, {"frame": 195, "track_id": 0, "x": 0.5092592592592593, "y": 0.42864583333333334, "w": 0.12037037037037036, "h": 0.1125, "conf": 1}, {"frame": 195, "track_id": 1, "x": 0.5083333333333333, "y": 0.42864583333333334, "w": 0.12222222222222222, "h": 0.1125, "conf": 1}, {"frame": 196, "track_id": 0, "x": 0.512962962962963, "y": 0.4296875, "w": 0.11574074074074074, "h": 0.08802083333333334, "conf": 1}, {"frame": 196, "track_id": 1, "x": 0.5111111111111111, "y": 0.42864583333333334, "w": 0.11851851851851852, "h": 0.08958333333333333, "conf": 1}, {"frame": 197, "track_id": 0, "x": 0.5148148148148148, "y": 0.42864583333333334, "w": 0.1111111111111111, "h": 0.07916666666666666, "conf": 1}, {"frame": 197, "track_id": 1, "x": 0.5138888888888888, "y": 0.42916666666666664, "w": 0.11203703703703703, "h": 0.07916666666666666, "conf": 1}, {"frame": 198, "track_id": 0, "x": 0.5148148148148148, "y": 0.42864583333333334, "w": 0.11018518518518519, "h": 0.07760416666666667, "conf": 1}, {"frame": 198, "track_id": 1, "x": 0.5138888888888888, "y": 0.42864583333333334, "w": 0.11203703703703703, "h": 0.078125, "conf": 1}, {"frame": 199, "track_id": 0, "x": 0.512962962962963, "y": 0.428125, "w": 0.09722222222222222, "h": 0.042708333333333334, "conf": 1}, {"frame": 199, "track_id": 1, "x": 0.512962962962963, "y": 0.42864583333333334, "w": 0.09814814814814815, "h": 0.042708333333333334, "conf": 1}, {"frame": 200, "track_id": 0, "x": 0.5185185185185185, "y": 0.428125, "w": 0.09351851851851851, "h": 0.04583333333333333, "conf": 1}, {"frame": 200, "track_id": 1, "x": 0.5185185185185185, "y": 0.42864583333333334, "w": 0.09351851851851851, "h": 0.04583333333333333, "conf": 1}, {"frame": 201, "track_id": 0, "x": 0.5259259259259259, "y": 0.43020833333333336, "w": 0.08611111111111111, "h": 0.044270833333333336, "conf": 1}, {"frame": 201, "track_id": 1, "x": 0.524074074074074, "y": 0.43020833333333336, "w": 0.08888888888888889, "h": 0.04479166666666667, "conf": 1}, {"frame": 202, "track_id": 0, "x": 0.5148148148148148, "y": 0.43072916666666666, "w": 0.1361111111111111, "h": 0.06770833333333333, "conf": 1}, {"frame": 202, "track_id": 1, "x": 0.5148148148148148, "y": 0.43125, "w": 0.12407407407407407, "h": 0.06510416666666667, "conf": 1}, {"frame": 203, "track_id": 0, "x": 0.5148148148148148, "y": 0.43072916666666666, "w": 0.1388888888888889, "h": 0.06770833333333333, "conf": 1}, {"frame": 203, "track_id": 1, "x": 0.5148148148148148, "y": 0.43125, "w": 0.12407407407407407, "h": 0.0640625, "conf": 1}, {"frame": 204, "track_id": 0, "x": 0.5185185185185185, "y": 0.4328125, "w": 0.11944444444444445, "h": 0.06614583333333333, "conf": 1}, {"frame": 204, "track_id": 1, "x": 0.5185185185185185, "y": 0.4328125, "w": 0.12037037037037036, "h": 0.06666666666666667, "conf": 1}, {"frame": 205, "track_id": 0, "x": 0.5351851851851852, "y": 0.43385416666666665, "w": 0.1037037037037037, "h": 0.0625, "conf": 1}, {"frame": 205, "track_id": 1, "x": 0.5342592592592592, "y": 0.43385416666666665, "w": 0.10462962962962963, "h": 0.06197916666666667, "conf": 1}, {"frame": 206, "track_id": 0, "x": 0.5916666666666667, "y": 0.43802083333333336, "w": 0.046296296296296294, "h": 0.053125, "conf": 1}, {"frame": 206, "track_id": 1, "x": 0.5907407407407408, "y": 0.43854166666666666, "w": 0.04814814814814815, "h": 0.05416666666666667, "conf": 1}, {"frame": 236, "track_id": 0, "x": 0.562037037037037, "y": 0.45208333333333334, "w": 0.0787037037037037, "h": 0.17291666666666666, "conf": 1}, {"frame": 236, "track_id": 1, "x": 0.5611111111111111, "y": 0.45364583333333336, "w": 0.07777777777777778, "h": 0.17395833333333333, "conf": 1}, {"frame": 237, "track_id": 0, "x": 0.562037037037037, "y": 0.4546875, "w": 0.08703703703703704, "h": 0.17291666666666666, "conf": 1}, {"frame": 237, "track_id": 1, "x": 0.562037037037037, "y": 0.45416666666666666, "w": 0.08888888888888889, "h": 0.17395833333333333, "conf": 1}, {"frame": 238, "track_id": 0, "x": 0.562962962962963, "y": 0.45416666666666666, "w": 0.08703703703703704, "h": 0.1734375, "conf": 1}, {"frame": 238, "track_id": 1, "x": 0.562037037037037, "y": 0.45416666666666666, "w": 0.08981481481481482, "h": 0.17395833333333333, "conf": 1}, {"frame": 239, "track_id": 0, "x": 0.5675925925925925, "y": 0.4546875, "w": 0.08333333333333333, "h": 0.146875, "conf": 1}, {"frame": 239, "track_id": 1, "x": 0.5657407407407408, "y": 0.4546875, "w": 0.08888888888888889, "h": 0.1484375, "conf": 1}, {"frame": 240, "track_id": 0, "x": 0.5731481481481482, "y": 0.45677083333333335, "w": 0.09166666666666666, "h": 0.17291666666666666, "conf": 1}, {"frame": 240, "track_id": 1, "x": 0.5722222222222222, "y": 0.45677083333333335, "w": 0.09259259259259259, "h": 0.1734375, "conf": 1}, {"frame": 241, "track_id": 0, "x": 0.5796296296296296, "y": 0.46510416666666665, "w": 0.09166666666666666, "h": 0.165625, "conf": 1}, {"frame": 241, "track_id": 1, "x": 0.5787037037037037, "y": 0.4546875, "w": 0.09166666666666666, "h": 0.1765625, "conf": 1}, {"frame": 242, "track_id": 0, "x": 0.5851851851851851, "y": 0.4432291666666667, "w": 0.08796296296296297, "h": 0.18958333333333333, "conf": 1}, {"frame": 242, "track_id": 1, "x": 0.5842592592592593, "y": 0.4432291666666667, "w": 0.08981481481481482, "h": 0.19114583333333332, "conf": 1}, {"frame": 243, "track_id": 0, "x": 0.5851851851851851, "y": 0.4427083333333333, "w": 0.08796296296296297, "h": 0.19010416666666666, "conf": 1}, {"frame": 243, "track_id": 1, "x": 0.5842592592592593, "y": 0.4427083333333333, "w": 0.08981481481481482, "h": 0.19114583333333332, "conf": 1}, {"frame": 277, "track_id": 1, "x": 0.14629629629629629, "y": 0.45364583333333336, "w": 0.1037037037037037, "h": 0.196875, "conf": 1}, {"frame": 278, "track_id": 1, "x": 0.14629629629629629, "y": 0.45364583333333336, "w": 0.1037037037037037, "h": 0.19739583333333333, "conf": 1}, {"frame": 279, "track_id": 0, "x": 0.12314814814814815, "y": 0.4510416666666667, "w": 0.18055555555555555, "h": 0.20416666666666666, "conf": 1}, {"frame": 279, "track_id": 1, "x": 0.11944444444444445, "y": 0.45364583333333336, "w": 0.1675925925925926, "h": 0.19895833333333332, "conf": 1}, {"frame": 280, "track_id": 0, "x": 0.14444444444444443, "y": 0.47604166666666664, "w": 0.17962962962962964, "h": 0.18333333333333332, "conf": 1}, {"frame": 280, "track_id": 1, "x": 0.09907407407407408, "y": 0.4786458333333333, "w": 0.15555555555555556, "h": 0.175, "conf": 1}, {"frame": 281, "track_id": 0, "x": 0.13796296296296295, "y": 0.5427083333333333, "w": 0.1287037037037037, "h": 0.11927083333333334, "conf": 1}, {"frame": 281, "track_id": 1, "x": 0.09166666666666666, "y": 0.54375, "w": 0.1712962962962963, "h": 0.11927083333333334, "conf": 1}, {"frame": 282, "track_id": 0, "x": 0.07222222222222222, "y": 0.6020833333333333, "w": 0.16018518518518518, "h": 0.06354166666666666, "conf": 1}, {"frame": 282, "track_id": 1, "x": 0.07222222222222222, "y": 0.603125, "w": 0.15462962962962962, "h": 0.0625, "conf": 1}, {"frame": 283, "track_id": 0, "x": 0.07222222222222222, "y": 0.6026041666666667, "w": 0.1537037037037037, "h": 0.06302083333333333, "conf": 1}, {"frame": 283, "track_id": 1, "x": 0.07222222222222222, "y": 0.6015625, "w": 0.15462962962962962, "h": 0.0640625, "conf": 1}, {"frame": 284, "track_id": 0, "x": 0.10648148148148148, "y": 0.484375, "w": 0.13518518518518519, "h": 0.18333333333333332, "conf": 1}, {"frame": 284, "track_id": 1, "x": 0.10925925925925926, "y": 0.48333333333333334, "w": 0.13240740740740742, "h": 0.18333333333333332, "conf": 1}, {"frame": 285, "track_id": 0, "x": 0.06018518518518518, "y": 0.5578125, "w": 0.11296296296296296, "h": 0.11041666666666666, "conf": 1}, {"frame": 285, "track_id": 1, "x": 0.06018518518518518, "y": 0.5572916666666666, "w": 0.10277777777777777, "h": 0.10989583333333333, "conf": 1}, {"frame": 286, "track_id": 0, "x": 0.02962962962962963, "y": 0.4557291666666667, "w": 0.13240740740740742, "h": 0.21197916666666666, "conf": 1}, {"frame": 286, "track_id": 1, "x": 0.0, "y": 0.45625, "w": 0.16111111111111112, "h": 0.2109375, "conf": 1}, {"frame": 287, "track_id": 0, "x": 0.0, "y": 0.4557291666666667, "w": 0.13703703703703704, "h": 0.1296875, "conf": 1}, {"frame": 287, "track_id": 1, "x": 0.0, "y": 0.45625, "w": 0.13703703703703704, "h": 0.1296875, "conf": 1}, {"frame": 288, "track_id": 0, "x": 0.0, "y": 0.4557291666666667, "w": 0.13703703703703704, "h": 0.1296875, "conf": 1}, {"frame": 288, "track_id": 1, "x": 0.0, "y": 0.45625, "w": 0.13703703703703704, "h": 0.12916666666666668, "conf": 1}, {"frame": 289, "track_id": 0, "x": 0.0, "y": 0.4552083333333333, "w": 0.09537037037037037, "h": 0.2125, "conf": 1}, {"frame": 289, "track_id": 1, "x": 0.0, "y": 0.4546875, "w": 0.13055555555555556, "h": 0.21197916666666666, "conf": 1}, {"frame": 290, "track_id": 0, "x": 0.0, "y": 0.4552083333333333, "w": 0.07222222222222222, "h": 0.21145833333333333, "conf": 1}, {"frame": 290, "track_id": 1, "x": 0.0, "y": 0.4546875, "w": 0.07222222222222222, "h": 0.2109375, "conf": 1}, {"frame": 291, "track_id": 0, "x": 0.0, "y": 0.45677083333333335, "w": 0.06481481481481481, "h": 0.209375, "conf": 1}, {"frame": 291, "track_id": 1, "x": 0.0, "y": 0.45677083333333335, "w": 0.10092592592592593, "h": 0.2078125, "conf": 1}, {"frame": 292, "track_id": 0, "x": 0.0, "y": 0.4546875, "w": 0.06388888888888888, "h": 0.20989583333333334, "conf": 1}, {"frame": 292, "track_id": 1, "x": 0.0, "y": 0.4546875, "w": 0.10648148148148148, "h": 0.209375, "conf": 1}, {"frame": 293, "track_id": 0, "x": 0.0, "y": 0.4546875, "w": 0.06388888888888888, "h": 0.21041666666666667, "conf": 1}, {"frame": 293, "track_id": 1, "x": 0.0, "y": 0.4546875, "w": 0.1037037037037037, "h": 0.209375, "conf": 1}, {"frame": 294, "track_id": 0, "x": 0.0, "y": 0.45364583333333336, "w": 0.06759259259259259, "h": 0.2125, "conf": 1}, {"frame": 294, "track_id": 1, "x": 0.0, "y": 0.453125, "w": 0.09537037037037037, "h": 0.2125, "conf": 1}, {"frame": 295, "track_id": 0, "x": 0.0, "y": 0.45208333333333334, "w": 0.0712962962962963, "h": 0.21145833333333333, "conf": 1}, {"frame": 295, "track_id": 1, "x": 0.0, "y": 0.4515625, "w": 0.0712962962962963, "h": 0.2109375, "conf": 1}, {"frame": 118, "track_id": 0, "x": 0.5157407407407407, "y": 0.36041666666666666, "w": 0.11944444444444445, "h": 0.16145833333333334, "conf": 1}, {"frame": 118, "track_id": 1, "x": 0.33240740740740743, "y": 0.45, "w": 0.1925925925925926, "h": 0.19010416666666666, "conf": 1}, {"frame": 117, "track_id": 0, "x": 0.5175925925925926, "y": 0.36041666666666666, "w": 0.11666666666666667, "h": 0.1609375, "conf": 1}, {"frame": 117, "track_id": 1, "x": 0.33240740740740743, "y": 0.45, "w": 0.1935185185185185, "h": 0.190625, "conf": 1}, {"frame": 116, "track_id": 0, "x": 0.5314814814814814, "y": 0.3541666666666667, "w": 0.10462962962962963, "h": 0.1609375, "conf": 1}, {"frame": 116, "track_id": 1, "x": 0.31666666666666665, "y": 0.45364583333333336, "w": 0.19074074074074074, "h": 0.19114583333333332, "conf": 1}, {"frame": 115, "track_id": 0, "x": 0.5361111111111111, "y": 0.34739583333333335, "w": 0.10925925925925926, "h": 0.15885416666666666, "conf": 1}, {"frame": 115, "track_id": 1, "x": 0.2962962962962963, "y": 0.45729166666666665, "w": 0.18703703703703703, "h": 0.19010416666666666, "conf": 1}, {"frame": 114, "track_id": 0, "x": 0.5481481481481482, "y": 0.34270833333333334, "w": 0.10740740740740741, "h": 0.15833333333333333, "conf": 1}, {"frame": 114, "track_id": 1, "x": 0.2814814814814815, "y": 0.46145833333333336, "w": 0.19907407407407407, "h": 0.18541666666666667, "conf": 1}, {"frame": 113, "track_id": 0, "x": 0.5564814814814815, "y": 0.33645833333333336, "w": 0.1111111111111111, "h": 0.15729166666666666, "conf": 1}, {"frame": 113, "track_id": 1, "x": 0.2712962962962963, "y": 0.46510416666666665, "w": 0.1962962962962963, "h": 0.17864583333333334, "conf": 1}, {"frame": 112, "track_id": 0, "x": 0.5564814814814815, "y": 0.33645833333333336, "w": 0.1111111111111111, "h": 0.15677083333333333, "conf": 1}, {"frame": 112, "track_id": 1, "x": 0.2712962962962963, "y": 0.465625, "w": 0.1962962962962963, "h": 0.17760416666666667, "conf": 1}, {"frame": 111, "track_id": 0, "x": 0.5685185185185185, "y": 0.33177083333333335, "w": 0.1175925925925926, "h": 0.15416666666666667, "conf": 1}, {"frame": 111, "track_id": 1, "x": 0.2657407407407407, "y": 0.46875, "w": 0.17962962962962964, "h": 0.17447916666666666, "conf": 1}, {"frame": 110, "track_id": 0, "x": 0.575925925925926, "y": 0.32708333333333334, "w": 0.12037037037037036, "h": 0.15416666666666667, "conf": 1}, {"frame": 110, "track_id": 1, "x": 0.25092592592592594, "y": 0.4713541666666667, "w": 0.18981481481481483, "h": 0.17239583333333333, "conf": 1}, {"frame": 109, "track_id": 0, "x": 0.5814814814814815, "y": 0.3265625, "w": 0.12407407407407407, "h": 0.14895833333333333, "conf": 1}, {"frame": 109, "track_id": 1, "x": 0.23055555555555557, "y": 0.4744791666666667, "w": 0.21203703703703702, "h": 0.16979166666666667, "conf": 1}, {"frame": 108, "track_id": 0, "x": 0.5824074074074074, "y": 0.321875, "w": 0.12962962962962962, "h": 0.14739583333333334, "conf": 1}, {"frame": 108, "track_id": 1, "x": 0.2101851851851852, "y": 0.47708333333333336, "w": 0.2212962962962963, "h": 0.16822916666666668, "conf": 1}, {"frame": 107, "track_id": 0, "x": 0.5814814814814815, "y": 0.321875, "w": 0.13055555555555556, "h": 0.14739583333333334, "conf": 1}, {"frame": 107, "track_id": 1, "x": 0.20925925925925926, "y": 0.4765625, "w": 0.2212962962962963, "h": 0.16875, "conf": 1}, {"frame": 106, "track_id": 0, "x": 0.5842592592592593, "y": 0.31979166666666664, "w": 0.1361111111111111, "h": 0.1453125, "conf": 1}, {"frame": 106, "track_id": 1, "x": 0.20092592592592592, "y": 0.4765625, "w": 0.21666666666666667, "h": 0.16979166666666667, "conf": 1}, {"frame": 105, "track_id": 0, "x": 0.5944444444444444, "y": 0.31927083333333334, "w": 0.13425925925925927, "h": 0.13958333333333334, "conf": 1}, {"frame": 105, "track_id": 1, "x": 0.17314814814814813, "y": 0.4895833333333333, "w": 0.22314814814814815, "h": 0.15989583333333332, "conf": 1}, {"frame": 104, "track_id": 0, "x": 0.6018518518518519, "y": 0.3171875, "w": 0.1388888888888889, "h": 0.134375, "conf": 1}, {"frame": 104, "track_id": 1, "x": 0.1287037037037037, "y": 0.4984375, "w": 0.23333333333333334, "h": 0.1640625, "conf": 1}, {"frame": 103, "track_id": 0, "x": 0.6083333333333333, "y": 0.3171875, "w": 0.14166666666666666, "h": 0.1296875, "conf": 1}, {"frame": 103, "track_id": 1, "x": 0.10277777777777777, "y": 0.5026041666666666, "w": 0.18888888888888888, "h": 0.15520833333333334, "conf": 1}, {"frame": 102, "track_id": 0, "x": 0.6074074074074074, "y": 0.31666666666666665, "w": 0.14166666666666666, "h": 0.13020833333333334, "conf": 1}, {"frame": 102, "track_id": 1, "x": 0.10277777777777777, "y": 0.5026041666666666, "w": 0.18888888888888888, "h": 0.15520833333333334, "conf": 1}, {"frame": 101, "track_id": 0, "x": 0.6203703703703703, "y": 0.3151041666666667, "w": 0.14166666666666666, "h": 0.1265625, "conf": 1}, {"frame": 101, "track_id": 1, "x": 0.07962962962962963, "y": 0.5104166666666666, "w": 0.20092592592592592, "h": 0.15052083333333333, "conf": 1}, {"frame": 100, "track_id": 0, "x": 0.6333333333333333, "y": 0.31614583333333335, "w": 0.14074074074074075, "h": 0.12083333333333333, "conf": 1}, {"frame": 100, "track_id": 1, "x": 0.06388888888888888, "y": 0.5177083333333333, "w": 0.21296296296296297, "h": 0.14791666666666667, "conf": 1}, {"frame": 99, "track_id": 0, "x": 0.6407407407407407, "y": 0.3151041666666667, "w": 0.1425925925925926, "h": 0.11875, "conf": 1}, {"frame": 99, "track_id": 1, "x": 0.04537037037037037, "y": 0.525, "w": 0.21944444444444444, "h": 0.14583333333333334, "conf": 1}, {"frame": 98, "track_id": 0, "x": 0.649074074074074, "y": 0.3140625, "w": 0.1425925925925926, "h": 0.11614583333333334, "conf": 1}, {"frame": 98, "track_id": 1, "x": 0.025925925925925925, "y": 0.5302083333333333, "w": 0.22777777777777777, "h": 0.14375, "conf": 1}, {"frame": 97, "track_id": 0, "x": 0.649074074074074, "y": 0.3140625, "w": 0.1425925925925926, "h": 0.11614583333333334, "conf": 1}, {"frame": 97, "track_id": 1, "x": 0.025925925925925925, "y": 0.5307291666666667, "w": 0.22962962962962963, "h": 0.14322916666666666, "conf": 1}, {"frame": 96, "track_id": 0, "x": 0.6574074074074074, "y": 0.3125, "w": 0.14351851851851852, "h": 0.11458333333333333, "conf": 1}, {"frame": 96, "track_id": 1, "x": 0.011111111111111112, "y": 0.5338541666666666, "w": 0.22592592592592592, "h": 0.14114583333333333, "conf": 1}, {"frame": 95, "track_id": 0, "x": 0.6694444444444444, "y": 0.31302083333333336, "w": 0.14444444444444443, "h": 0.1109375, "conf": 1}, {"frame": 95, "track_id": 1, "x": 0.0, "y": 0.5364583333333334, "w": 0.22962962962962963, "h": 0.140625, "conf": 1}, {"frame": 94, "track_id": 0, "x": 0.6824074074074075, "y": 0.3104166666666667, "w": 0.14537037037037037, "h": 0.11145833333333334, "conf": 1}, {"frame": 94, "track_id": 1, "x": 0.0, "y": 0.5380208333333333, "w": 0.21944444444444444, "h": 0.14010416666666667, "conf": 1}, {"frame": 93, "track_id": 0, "x": 0.687962962962963, "y": 0.3078125, "w": 0.1537037037037037, "h": 0.11197916666666667, "conf": 1}, {"frame": 93, "track_id": 1, "x": 0.0, "y": 0.5390625, "w": 0.2074074074074074, "h": 0.13958333333333334, "conf": 1}, {"frame": 92, "track_id": 0, "x": 0.687962962962963, "y": 0.3078125, "w": 0.1537037037037037, "h": 0.11197916666666667, "conf": 1}, {"frame": 92, "track_id": 1, "x": 0.0, "y": 0.5390625, "w": 0.2074074074074074, "h": 0.1390625, "conf": 1}, {"frame": 91, "track_id": 0, "x": 0.6972222222222222, "y": 0.30572916666666666, "w": 0.1537037037037037, "h": 0.1140625, "conf": 1}, {"frame": 91, "track_id": 1, "x": 0.007407407407407408, "y": 0.5390625, "w": 0.19444444444444445, "h": 0.1375, "conf": 1}, {"frame": 90, "track_id": 0, "x": 0.7055555555555556, "y": 0.3020833333333333, "w": 0.15462962962962962, "h": 0.103125, "conf": 1}, {"frame": 90, "track_id": 1, "x": 0.018518518518518517, "y": 0.5380208333333333, "w": 0.1925925925925926, "h": 0.13541666666666666, "conf": 1}, {"frame": 89, "track_id": 0, "x": 0.725, "y": 0.2984375, "w": 0.14907407407407408, "h": 0.0765625, "conf": 1}, {"frame": 89, "track_id": 1, "x": 0.04814814814814815, "y": 0.5359375, "w": 0.1787037037037037, "h": 0.13020833333333334, "conf": 1}, {"frame": 88, "track_id": 0, "x": 0.7398148148148148, "y": 0.29583333333333334, "w": 0.14444444444444443, "h": 0.09947916666666666, "conf": 1}, {"frame": 88, "track_id": 1, "x": 0.06666666666666667, "y": 0.5260416666666666, "w": 0.17037037037037037, "h": 0.13333333333333333, "conf": 1}, {"frame": 87, "track_id": 0, "x": 0.7388888888888889, "y": 0.29583333333333334, "w": 0.14537037037037037, "h": 0.1, "conf": 1}, {"frame": 87, "track_id": 1, "x": 0.06666666666666667, "y": 0.5265625, "w": 0.16944444444444445, "h": 0.1328125, "conf": 1}, {"frame": 86, "track_id": 0, "x": 0.7583333333333333, "y": 0.29270833333333335, "w": 0.14444444444444443, "h": 0.12760416666666666, "conf": 1}, {"frame": 86, "track_id": 1, "x": 0.06944444444444445, "y": 0.5088541666666667, "w": 0.1814814814814815, "h": 0.14270833333333333, "conf": 1}, {"frame": 85, "track_id": 0, "x": 0.7851851851851852, "y": 0.28854166666666664, "w": 0.1425925925925926, "h": 0.1390625, "conf": 1}, {"frame": 85, "track_id": 1, "x": 0.08425925925925926, "y": 0.490625, "w": 0.18333333333333332, "h": 0.15208333333333332, "conf": 1}, {"frame": 84, "track_id": 0, "x": 0.8064814814814815, "y": 0.2859375, "w": 0.1398148148148148, "h": 0.1421875, "conf": 1}, {"frame": 84, "track_id": 1, "x": 0.10092592592592593, "y": 0.48072916666666665, "w": 0.1814814814814815, "h": 0.15572916666666667, "conf": 1}, {"frame": 83, "track_id": 0, "x": 0.8398148148148148, "y": 0.2833333333333333, "w": 0.13333333333333333, "h": 0.14739583333333334, "conf": 1}, {"frame": 83, "track_id": 1, "x": 0.13240740740740742, "y": 0.4713541666666667, "w": 0.17777777777777778, "h": 0.15833333333333333, "conf": 1}, {"frame": 82, "track_id": 0, "x": 0.8398148148148148, "y": 0.2833333333333333, "w": 0.13333333333333333, "h": 0.14739583333333334, "conf": 1}, {"frame": 82, "track_id": 1, "x": 0.13240740740740742, "y": 0.4713541666666667, "w": 0.17777777777777778, "h": 0.1578125, "conf": 1}, {"frame": 81, "track_id": 0, "x": 0.8796296296296297, "y": 0.278125, "w": 0.11944444444444445, "h": 0.153125, "conf": 1}, {"frame": 81, "track_id": 1, "x": 0.17314814814814813, "y": 0.46822916666666664, "w": 0.18425925925925926, "h": 0.15364583333333334, "conf": 1}, {"frame": 80, "track_id": 0, "x": 0.9046296296296297, "y": 0.27760416666666665, "w": 0.09444444444444444, "h": 0.153125, "conf": 1}, {"frame": 80, "track_id": 1, "x": 0.19814814814814816, "y": 0.4713541666666667, "w": 0.19444444444444445, "h": 0.14739583333333334, "conf": 1}, {"frame": 79, "track_id": 0, "x": 0.9333333333333333, "y": 0.2765625, "w": 0.06574074074074074, "h": 0.18489583333333334, "conf": 1}, {"frame": 79, "track_id": 1, "x": 0.21666666666666667, "y": 0.48385416666666664, "w": 0.19814814814814816, "h": 0.13333333333333333, "conf": 1}, {"frame": 78, "track_id": 0, "x": 0.9648148148148148, "y": 0.2755208333333333, "w": 0.03425925925925926, "h": 0.121875, "conf": 1}, {"frame": 78, "track_id": 1, "x": 0.2388888888888889, "y": 0.4947916666666667, "w": 0.20277777777777778, "h": 0.12395833333333334, "conf": 1}, {"frame": 77, "track_id": 0, "x": 0.9648148148148148, "y": 0.275, "w": 0.03425925925925926, "h": 0.12135416666666667, "conf": 1}, {"frame": 77, "track_id": 1, "x": 0.2388888888888889, "y": 0.4947916666666667, "w": 0.2037037037037037, "h": 0.12447916666666667, "conf": 1}, {"frame": 76, "track_id": 0, "x": 0.9861111111111112, "y": 0.32760416666666664, "w": 0.012962962962962963, "h": 0.03229166666666667, "conf": 1}, {"frame": 76, "track_id": 1, "x": 0.262037037037037, "y": 0.49270833333333336, "w": 0.2101851851851852, "h": 0.134375, "conf": 1}, {"frame": 75, "track_id": 1, "x": 0.2861111111111111, "y": 0.4942708333333333, "w": 0.2101851851851852, "h": 0.1421875, "conf": 1}, {"frame": 74, "track_id": 1, "x": 0.30833333333333335, "y": 0.496875, "w": 0.20092592592592592, "h": 0.15208333333333332, "conf": 1}, {"frame": 73, "track_id": 1, "x": 0.3351851851851852, "y": 0.5005208333333333, "w": 0.18333333333333332, "h": 0.16041666666666668, "conf": 1}, {"frame": 72, "track_id": 1, "x": 0.3351851851851852, "y": 0.5, "w": 0.18333333333333332, "h": 0.1609375, "conf": 1}, {"frame": 71, "track_id": 1, "x": 0.362962962962963, "y": 0.5036458333333333, "w": 0.16574074074074074, "h": 0.16822916666666668, "conf": 1}, {"frame": 70, "track_id": 1, "x": 0.387037037037037, "y": 0.5098958333333333, "w": 0.1675925925925926, "h": 0.17291666666666666, "conf": 1}, {"frame": 69, "track_id": 1, "x": 0.4074074074074074, "y": 0.5161458333333333, "w": 0.17037037037037037, "h": 0.178125, "conf": 1}, {"frame": 68, "track_id": 1, "x": 0.4083333333333333, "y": 0.5213541666666667, "w": 0.17592592592592593, "h": 0.18385416666666668, "conf": 1}, {"frame": 67, "track_id": 1, "x": 0.4083333333333333, "y": 0.5213541666666667, "w": 0.17592592592592593, "h": 0.18333333333333332, "conf": 1}, {"frame": 66, "track_id": 1, "x": 0.4074074074074074, "y": 0.5276041666666667, "w": 0.1787037037037037, "h": 0.18541666666666667, "conf": 1}, {"frame": 65, "track_id": 1, "x": 0.39166666666666666, "y": 0.5317708333333333, "w": 0.18888888888888888, "h": 0.18958333333333333, "conf": 1}, {"frame": 64, "track_id": 1, "x": 0.37962962962962965, "y": 0.5385416666666667, "w": 0.1925925925925926, "h": 0.19270833333333334, "conf": 1}, {"frame": 63, "track_id": 1, "x": 0.36666666666666664, "y": 0.5479166666666667, "w": 0.1962962962962963, "h": 0.19270833333333334, "conf": 1}, {"frame": 62, "track_id": 1, "x": 0.3648148148148148, "y": 0.5473958333333333, "w": 0.19814814814814816, "h": 0.19322916666666667, "conf": 1}, {"frame": 61, "track_id": 1, "x": 0.35555555555555557, "y": 0.5541666666666667, "w": 0.2037037037037037, "h": 0.19270833333333334, "conf": 1}, {"frame": 60, "track_id": 1, "x": 0.34444444444444444, "y": 0.5630208333333333, "w": 0.20925925925925926, "h": 0.19114583333333332, "conf": 1}, {"frame": 59, "track_id": 1, "x": 0.3296296296296296, "y": 0.5723958333333333, "w": 0.2222222222222222, "h": 0.19010416666666666, "conf": 1}, {"frame": 58, "track_id": 1, "x": 0.31851851851851853, "y": 0.5770833333333333, "w": 0.23333333333333334, "h": 0.18958333333333333, "conf": 1}, {"frame": 57, "track_id": 1, "x": 0.31851851851851853, "y": 0.5770833333333333, "w": 0.2324074074074074, "h": 0.1890625, "conf": 1}, {"frame": 56, "track_id": 1, "x": 0.3111111111111111, "y": 0.5828125, "w": 0.23981481481481481, "h": 0.18802083333333333, "conf": 1}, {"frame": 55, "track_id": 1, "x": 0.29907407407407405, "y": 0.5880208333333333, "w": 0.2388888888888889, "h": 0.18802083333333333, "conf": 1}, {"frame": 54, "track_id": 1, "x": 0.2833333333333333, "y": 0.590625, "w": 0.23703703703703705, "h": 0.18489583333333334, "conf": 1}, {"frame": 53, "track_id": 1, "x": 0.2657407407407407, "y": 0.5916666666666667, "w": 0.23333333333333334, "h": 0.184375, "conf": 1}, {"frame": 52, "track_id": 1, "x": 0.2657407407407407, "y": 0.5916666666666667, "w": 0.2324074074074074, "h": 0.18229166666666666, "conf": 1}, {"frame": 51, "track_id": 1, "x": 0.2490740740740741, "y": 0.590625, "w": 0.22870370370370371, "h": 0.18072916666666666, "conf": 1}, {"frame": 50, "track_id": 1, "x": 0.23333333333333334, "y": 0.5880208333333333, "w": 0.225, "h": 0.18333333333333332, "conf": 1}, {"frame": 49, "track_id": 1, "x": 0.21666666666666667, "y": 0.5848958333333333, "w": 0.22407407407407406, "h": 0.18020833333333333, "conf": 1}, {"frame": 48, "track_id": 1, "x": 0.20277777777777778, "y": 0.5838541666666667, "w": 0.2222222222222222, "h": 0.175, "conf": 1}, {"frame": 47, "track_id": 1, "x": 0.20277777777777778, "y": 0.5838541666666667, "w": 0.2222222222222222, "h": 0.17447916666666666, "conf": 1}, {"frame": 46, "track_id": 1, "x": 0.19166666666666668, "y": 0.5817708333333333, "w": 0.21851851851851853, "h": 0.17083333333333334, "conf": 1}, {"frame": 45, "track_id": 1, "x": 0.1787037037037037, "y": 0.5791666666666667, "w": 0.21851851851851853, "h": 0.16979166666666667, "conf": 1}, {"frame": 44, "track_id": 1, "x": 0.1638888888888889, "y": 0.5776041666666667, "w": 0.21296296296296297, "h": 0.165625, "conf": 1}, {"frame": 43, "track_id": 1, "x": 0.15185185185185185, "y": 0.5755208333333334, "w": 0.2074074074074074, "h": 0.15989583333333332, "conf": 1}, {"frame": 42, "track_id": 1, "x": 0.15185185185185185, "y": 0.575, "w": 0.20925925925925926, "h": 0.16197916666666667, "conf": 1}, {"frame": 41, "track_id": 1, "x": 0.1675925925925926, "y": 0.571875, "w": 0.2, "h": 0.1671875, "conf": 1}, {"frame": 40, "track_id": 1, "x": 0.18888888888888888, "y": 0.5682291666666667, "w": 0.18518518518518517, "h": 0.175, "conf": 1}, {"frame": 39, "track_id": 1, "x": 0.2037037037037037, "y": 0.5677083333333334, "w": 0.17407407407407408, "h": 0.17760416666666667, "conf": 1}, {"frame": 38, "track_id": 1, "x": 0.22037037037037038, "y": 0.5604166666666667, "w": 0.15648148148148147, "h": 0.18697916666666667, "conf": 1}, {"frame": 37, "track_id": 1, "x": 0.22037037037037038, "y": 0.5557291666666667, "w": 0.15555555555555556, "h": 0.19166666666666668, "conf": 1}, {"frame": 36, "track_id": 1, "x": 0.23703703703703705, "y": 0.5682291666666667, "w": 0.14722222222222223, "h": 0.18020833333333333, "conf": 1}, {"frame": 35, "track_id": 1, "x": 0.24537037037037038, "y": 0.5692708333333333, "w": 0.15092592592592594, "h": 0.17604166666666668, "conf": 1}, {"frame": 34, "track_id": 1, "x": 0.25277777777777777, "y": 0.5713541666666667, "w": 0.1574074074074074, "h": 0.16822916666666668, "conf": 1}, {"frame": 33, "track_id": 1, "x": 0.26666666666666666, "y": 0.5770833333333333, "w": 0.16018518518518518, "h": 0.159375, "conf": 1}, {"frame": 32, "track_id": 1, "x": 0.26666666666666666, "y": 0.5770833333333333, "w": 0.16018518518518518, "h": 0.159375, "conf": 1}, {"frame": 31, "track_id": 1, "x": 0.28703703703703703, "y": 0.578125, "w": 0.15555555555555556, "h": 0.15520833333333334, "conf": 1}, {"frame": 30, "track_id": 1, "x": 0.2962962962962963, "y": 0.5755208333333334, "w": 0.16574074074074074, "h": 0.15416666666666667, "conf": 1}, {"frame": 29, "track_id": 1, "x": 0.30833333333333335, "y": 0.5744791666666667, "w": 0.1675925925925926, "h": 0.15260416666666668, "conf": 1}, {"frame": 28, "track_id": 1, "x": 0.32222222222222224, "y": 0.5739583333333333, "w": 0.16574074074074074, "h": 0.15052083333333333, "conf": 1}, {"frame": 27, "track_id": 1, "x": 0.32222222222222224, "y": 0.5739583333333333, "w": 0.16574074074074074, "h": 0.15052083333333333, "conf": 1}, {"frame": 26, "track_id": 1, "x": 0.3333333333333333, "y": 0.5760416666666667, "w": 0.16666666666666666, "h": 0.14947916666666666, "conf": 1}, {"frame": 25, "track_id": 1, "x": 0.3398148148148148, "y": 0.5770833333333333, "w": 0.17592592592592593, "h": 0.15364583333333334, "conf": 1}, {"frame": 24, "track_id": 1, "x": 0.34814814814814815, "y": 0.5786458333333333, "w": 0.2, "h": 0.15572916666666667, "conf": 1}, {"frame": 23, "track_id": 1, "x": 0.3638888888888889, "y": 0.5796875, "w": 0.21574074074074073, "h": 0.1609375, "conf": 1}, {"frame": 22, "track_id": 1, "x": 0.3638888888888889, "y": 0.5796875, "w": 0.21388888888888888, "h": 0.1609375, "conf": 1}, {"frame": 21, "track_id": 1, "x": 0.387037037037037, "y": 0.5854166666666667, "w": 0.21944444444444444, "h": 0.1703125, "conf": 1}, {"frame": 20, "track_id": 1, "x": 0.39814814814814814, "y": 0.5890625, "w": 0.2111111111111111, "h": 0.17604166666666668, "conf": 1}, {"frame": 19, "track_id": 1, "x": 0.41203703703703703, "y": 0.5927083333333333, "w": 0.20925925925925926, "h": 0.1796875, "conf": 1}, {"frame": 18, "track_id": 1, "x": 0.4398148148148148, "y": 0.5973958333333333, "w": 0.18333333333333332, "h": 0.17239583333333333, "conf": 1}, {"frame": 17, "track_id": 1, "x": 0.4398148148148148, "y": 0.5973958333333333, "w": 0.18333333333333332, "h": 0.17239583333333333, "conf": 1}, {"frame": 16, "track_id": 1, "x": 0.45555555555555555, "y": 0.6005208333333333, "w": 0.17407407407407408, "h": 0.1671875, "conf": 1}, {"frame": 15, "track_id": 1, "x": 0.48518518518518516, "y": 0.6026041666666667, "w": 0.15092592592592594, "h": 0.1625, "conf": 1}, {"frame": 14, "track_id": 1, "x": 0.5166666666666667, "y": 0.6036458333333333, "w": 0.15925925925925927, "h": 0.15989583333333332, "conf": 1}, {"frame": 13, "track_id": 1, "x": 0.5342592592592592, "y": 0.6036458333333333, "w": 0.16666666666666666, "h": 0.15677083333333333, "conf": 1}, {"frame": 12, "track_id": 1, "x": 0.5342592592592592, "y": 0.6036458333333333, "w": 0.16666666666666666, "h": 0.15729166666666666, "conf": 1}, {"frame": 11, "track_id": 1, "x": 0.5518518518518518, "y": 0.6041666666666666, "w": 0.18981481481481483, "h": 0.15364583333333334, "conf": 1}, {"frame": 10, "track_id": 1, "x": 0.5657407407407408, "y": 0.6036458333333333, "w": 0.2037037037037037, "h": 0.15, "conf": 1}, {"frame": 9, "track_id": 1, "x": 0.575925925925926, "y": 0.603125, "w": 0.19907407407407407, "h": 0.14635416666666667, "conf": 1}, {"frame": 8, "track_id": 1, "x": 0.587037037037037, "y": 0.603125, "w": 0.1814814814814815, "h": 0.1421875, "conf": 1}, {"frame": 7, "track_id": 1, "x": 0.587037037037037, "y": 0.6026041666666667, "w": 0.18055555555555555, "h": 0.14270833333333333, "conf": 1}, {"frame": 6, "track_id": 1, "x": 0.600925925925926, "y": 0.603125, "w": 0.1648148148148148, "h": 0.13802083333333334, "conf": 1}, {"frame": 5, "track_id": 1, "x": 0.6083333333333333, "y": 0.6010416666666667, "w": 0.1638888888888889, "h": 0.13385416666666666, "conf": 1}, {"frame": 4, "track_id": 1, "x": 0.6129629629629629, "y": 0.5994791666666667, "w": 0.19814814814814816, "h": 0.1296875, "conf": 1}, {"frame": 3, "track_id": 1, "x": 0.6351851851851852, "y": 0.6, "w": 0.2388888888888889, "h": 0.13020833333333334, "conf": 1}, {"frame": 2, "track_id": 1, "x": 0.6351851851851852, "y": 0.6, "w": 0.2388888888888889, "h": 0.13020833333333334, "conf": 1}, {"frame": 1, "track_id": 1, "x": 0.6518518518518519, "y": 0.6010416666666667, "w": 0.25277777777777777, "h": 0.13854166666666667, "conf": 1}, {"frame": 0, "track_id": 1, "x": 0.6620370370370371, "y": 0.603125, "w": 0.26944444444444443, "h": 0.15520833333333334, "conf": 1}]
assets/example_0.json ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "class_name": "player",
4
+ "object_id": 0,
5
+ "boundingBox": {
6
+ "x0": 551.4322856068611,
7
+ "y0": 687.3054885864258,
8
+ "x1": 690.9895893931389,
9
+ "y1": 1003.9445114135742
10
+ }
11
+ },
12
+ {
13
+ "class_name": "player",
14
+ "object_id": 1,
15
+ "boundingBox": {
16
+ "x0": 353.87999564409256,
17
+ "y0": 862.4811029434204,
18
+ "x1": 572.1356293559074,
19
+ "y1": 1230.0188970565796
20
+ }
21
+ }
22
+ ]
pilbox.py CHANGED
@@ -1,8 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  def im_crop(im_rgb_array, x0, y0, x1, y1):
 
2
  return im_rgb_array[y0:y1, x0:x1, :]
3
 
4
 
5
  def im_center_crop(im_rgb_array, w, h):
 
6
  h_, w_, _ = im_rgb_array.shape
7
  assert (
8
  w_ >= w and h_ >= h
@@ -17,16 +40,17 @@ def im_center_crop(im_rgb_array, w, h):
17
  def load_pil_font(
18
  preferred_font_name: str = "arial.ttf", size: int = 12, fallback_to_any: bool = True
19
  ):
20
- """
21
- Attempts to load a font, with fallbacks.
22
  Args:
23
- font_name (str): The name or relative path of the font file (e.g., 'arial.ttf').
24
- size (int): The font size.
25
- fallback_to_default (bool): If True, falls back to Pillow's default font.
 
 
 
26
  Returns:
27
- PIL.ImageFont.FreeTypeFont: The loaded font object.
28
- Raises:
29
- OSError: If no font can be loaded and fallback is not enabled.
30
  """
31
  any_fonts = ["DejaVuSans.ttf", "LiberationSans-Regular.ttf", "Arial Unicode.ttf"]
32
  # 1. Try absolute path relative to script
@@ -74,11 +98,72 @@ def load_pil_font(
74
  continue # Try next path
75
 
76
  logger.warning("load_pil_font: Falling back to Pillow's default font.")
77
- return (
78
- ImageFont.load_default()
79
- ) # [9](https://www.geeksforgeeks.org/python/python-pil-imagefont-load_default/)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
 
 
 
 
82
  def im_draw_bbox(
83
  pil_im,
84
  x0,
@@ -88,28 +173,54 @@ def im_draw_bbox(
88
  color="black",
89
  width=3,
90
  caption=None,
91
- caption_font=ImageFont.load_default(),
 
92
  ):
93
- """
94
- draw bounding box on the input image pil_im in-place
 
 
 
 
95
  Args:
96
- color: color name as read by Pillow.ImageColor
 
 
 
 
 
 
97
  """
 
 
98
 
99
- if any([type(i) == float for i in [x0, y0, x1, y1]]):
100
- warnings.warn(
101
- f"im_draw_bbox: at least one of x0,y0,x1,y1 is of the type float and is converted to int."
102
- )
103
- x0 = int(x0)
104
- y0 = int(y0)
105
- x1 = int(x1)
106
- y1 = int(y1)
107
 
108
  draw = ImageDraw.Draw(pil_im)
109
  draw.rectangle([(x0, y0), (x1, y1)], outline=color, width=width)
 
110
  if caption:
111
- draw.text((x0, y0), text=caption, fill=color, font=caption_font)
112
- # return None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
 
114
 
115
  def im_draw_point(
@@ -121,6 +232,7 @@ def im_draw_point(
121
  width: int = 2,
122
  color: str = "red",
123
  ) -> Image.Image:
 
124
  # Initialize variable for drawing image
125
  im_draw = pil_im.copy()
126
  draw = ImageDraw.Draw(im_draw)
@@ -140,8 +252,103 @@ def im_draw_point(
140
  xy=(draw_x + size + size / 2, draw_y - size / 2),
141
  text=caption,
142
  fill=color,
143
- # stroke_width=width,
144
  font_size=width * 5,
145
  )
146
 
147
  return im_draw
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """PILBox: ultra-lite bounding-box annotation using only numpy + Pillow.
2
+
3
+ Bounding boxes use the **pascal_voc** convention: absolute pixel coordinates
4
+ ``(x0, y0, x1, y1)`` for the top-left and bottom-right corners, matching the
5
+ ``boundingBox`` dict found in ``assets/example_0.json``.
6
+
7
+ The only third-party dependencies are ``numpy``, ``Pillow`` and ``loguru``.
8
+ """
9
+
10
+ import os
11
+ import json
12
+ import colorsys
13
+
14
+ import numpy as np
15
+ from PIL import Image, ImageDraw, ImageFont
16
+ from loguru import logger
17
+
18
+
19
+ # --------------------------------------------------------------------------- #
20
+ # Image helpers (kept for future features)
21
+ # --------------------------------------------------------------------------- #
22
  def im_crop(im_rgb_array, x0, y0, x1, y1):
23
+ """Crop an RGB numpy image to the pascal_voc box ``(x0, y0, x1, y1)``."""
24
  return im_rgb_array[y0:y1, x0:x1, :]
25
 
26
 
27
  def im_center_crop(im_rgb_array, w, h):
28
+ """Center-crop an RGB numpy image to width ``w`` and height ``h``."""
29
  h_, w_, _ = im_rgb_array.shape
30
  assert (
31
  w_ >= w and h_ >= h
 
40
  def load_pil_font(
41
  preferred_font_name: str = "arial.ttf", size: int = 12, fallback_to_any: bool = True
42
  ):
43
+ """Attempt to load a TrueType font, with fallbacks.
44
+
45
  Args:
46
+ preferred_font_name: The name or relative path of the font file
47
+ (e.g. ``'arial.ttf'``).
48
+ size: The font size in points.
49
+ fallback_to_any: If True, tries a list of common fonts before falling
50
+ back to Pillow's default font.
51
+
52
  Returns:
53
+ PIL.ImageFont.FreeTypeFont | PIL.ImageFont.ImageFont: The loaded font.
 
 
54
  """
55
  any_fonts = ["DejaVuSans.ttf", "LiberationSans-Regular.ttf", "Arial Unicode.ttf"]
56
  # 1. Try absolute path relative to script
 
98
  continue # Try next path
99
 
100
  logger.warning("load_pil_font: Falling back to Pillow's default font.")
101
+ return ImageFont.load_default(size=size)
102
+
103
+
104
+ # --------------------------------------------------------------------------- #
105
+ # Color palette (unbounded, generated — no matplotlib)
106
+ # --------------------------------------------------------------------------- #
107
+ # Golden-angle in the unit hue circle; stepping by it spreads hues as far apart
108
+ # as possible for any count, so consecutive indices never collide visually.
109
+ _GOLDEN_RATIO_CONJUGATE = 0.6180339887498949
110
+
111
+
112
+ def palette_color(index: int, saturation: float = 0.65, value: float = 0.95) -> str:
113
+ """Return the ``index``-th visually distinct color as a ``#rrggbb`` string.
114
+
115
+ Hues are spaced by the golden angle so any number of colors stay far apart,
116
+ meaning the palette never runs out (no fixed list, no matplotlib).
117
+
118
+ Note:
119
+ If you prefer fixed *named* colors instead, ``PIL.ImageColor.colormap``
120
+ exposes ~148 built-in CSS/X11 color names (e.g. ``"lime"``, ``"cyan"``).
121
 
122
+ Args:
123
+ index: Zero-based color index.
124
+ saturation: HSV saturation in ``[0, 1]``.
125
+ value: HSV value/brightness in ``[0, 1]``.
126
+
127
+ Returns:
128
+ Hex color string usable directly by Pillow, e.g. ``"#f23a1b"``.
129
+
130
+ >>> palette_color(0)
131
+ '#f25454'
132
+ >>> palette_color(0) != palette_color(1)
133
+ True
134
+ """
135
+ hue = (index * _GOLDEN_RATIO_CONJUGATE) % 1.0
136
+ r, g, b = colorsys.hsv_to_rgb(hue, saturation, value)
137
+ return "#{:02x}{:02x}{:02x}".format(int(r * 255), int(g * 255), int(b * 255))
138
+
139
+
140
+ def color_for(key, mapping: dict) -> str:
141
+ """Return a stable palette color for ``key``, assigning a new one if unseen.
142
+
143
+ ``mapping`` is mutated in place to remember which palette index each distinct
144
+ key was given (first-seen order), so repeated calls are deterministic.
145
+
146
+ Args:
147
+ key: Any hashable value to color by (e.g. an object id or class name).
148
+ mapping: Dict tracking ``key -> palette index`` across calls.
149
+
150
+ Returns:
151
+ A ``#rrggbb`` color string.
152
+
153
+ >>> m = {}
154
+ >>> color_for("a", m) == color_for("a", m) # stable
155
+ True
156
+ >>> color_for("a", m) != color_for("b", m) # distinct
157
+ True
158
+ """
159
+ if key not in mapping:
160
+ mapping[key] = len(mapping)
161
+ return palette_color(mapping[key])
162
 
163
+
164
+ # --------------------------------------------------------------------------- #
165
+ # Drawing
166
+ # --------------------------------------------------------------------------- #
167
  def im_draw_bbox(
168
  pil_im,
169
  x0,
 
173
  color="black",
174
  width=3,
175
  caption=None,
176
+ caption_font=None,
177
+ text_color="black",
178
  ):
179
+ """Draw a bounding box (and optional label tab) on ``pil_im`` in place.
180
+
181
+ The caption is rendered as a filled tab in ``color`` sitting just above the
182
+ box's top-left corner, with the text drawn in ``text_color`` — matching the
183
+ look of ``assets/example_0_out.jpg``.
184
+
185
  Args:
186
+ pil_im: Target ``PIL.Image.Image`` (drawn on in place).
187
+ x0, y0, x1, y1: pascal_voc box coordinates (floats are coerced to int).
188
+ color: Box outline / label-tab color, as read by ``PIL.ImageColor``.
189
+ width: Outline width in pixels.
190
+ caption: Optional label text. If falsy, no label is drawn.
191
+ caption_font: Optional ``PIL.ImageFont``; defaults to Pillow's default.
192
+ text_color: Color of the caption text drawn on the tab.
193
  """
194
+ if any(isinstance(i, float) for i in [x0, y0, x1, y1]):
195
+ x0, y0, x1, y1 = int(x0), int(y0), int(x1), int(y1)
196
 
197
+ if caption_font is None:
198
+ caption_font = ImageFont.load_default()
 
 
 
 
 
 
199
 
200
  draw = ImageDraw.Draw(pil_im)
201
  draw.rectangle([(x0, y0), (x1, y1)], outline=color, width=width)
202
+
203
  if caption:
204
+ caption = str(caption)
205
+ # Measure the text so the tab hugs it.
206
+ left, top, right, bottom = draw.textbbox((0, 0), caption, font=caption_font)
207
+ tw, th = right - left, bottom - top
208
+ pad = 2
209
+ tab_h = th + 2 * pad
210
+ # Sit the tab above the box; if there's no room, place it inside.
211
+ tab_top = y0 - tab_h
212
+ if tab_top < 0:
213
+ tab_top = y0
214
+ draw.rectangle(
215
+ [(x0, tab_top), (x0 + tw + 2 * pad, tab_top + tab_h)],
216
+ fill=color,
217
+ )
218
+ draw.text(
219
+ (x0 + pad - left, tab_top + pad - top),
220
+ text=caption,
221
+ fill=text_color,
222
+ font=caption_font,
223
+ )
224
 
225
 
226
  def im_draw_point(
 
232
  width: int = 2,
233
  color: str = "red",
234
  ) -> Image.Image:
235
+ """Return a copy of ``pil_im`` with a cross marker drawn at ``(x, y)``."""
236
  # Initialize variable for drawing image
237
  im_draw = pil_im.copy()
238
  draw = ImageDraw.Draw(im_draw)
 
252
  xy=(draw_x + size + size / 2, draw_y - size / 2),
253
  text=caption,
254
  fill=color,
 
255
  font_size=width * 5,
256
  )
257
 
258
  return im_draw
259
+
260
+
261
+ def annotate(
262
+ image: Image.Image,
263
+ objects,
264
+ *,
265
+ label_key: str = "object_id",
266
+ color_key: str = "object_id",
267
+ bbox_key: str = "boundingBox",
268
+ width: int = 3,
269
+ font=None,
270
+ ) -> Image.Image:
271
+ """Draw every object's pascal_voc bounding box on a copy of ``image``.
272
+
273
+ Args:
274
+ image: Source ``PIL.Image.Image`` (never mutated; a copy is returned).
275
+ objects: Iterable of dicts. Each must hold a pascal_voc box under
276
+ ``bbox_key`` as ``{"x0", "y0", "x1", "y1"}`` and, optionally, values
277
+ under ``label_key`` and ``color_key``.
278
+ label_key: Object key whose value is drawn as the box label.
279
+ color_key: Object key whose value groups boxes into colors (each distinct
280
+ value gets its own palette color).
281
+ bbox_key: Object key holding the pascal_voc box dict.
282
+ width: Box outline width in pixels.
283
+ font: Optional ``PIL.ImageFont`` for labels; defaults to Pillow's default.
284
+
285
+ Returns:
286
+ A new annotated ``PIL.Image.Image``.
287
+
288
+ >>> im = Image.new("RGB", (100, 100), "white")
289
+ >>> objs = [{"object_id": 0, "boundingBox": {"x0": 10, "y0": 10, "x1": 40, "y1": 60}}]
290
+ >>> out = annotate(im, objs)
291
+ >>> out.size
292
+ (100, 100)
293
+ >>> out is im
294
+ False
295
+ """
296
+ out = image.copy()
297
+ color_map: dict = {}
298
+ for obj in objects:
299
+ box = obj[bbox_key]
300
+ color = color_for(obj.get(color_key), color_map)
301
+ caption = obj.get(label_key)
302
+ im_draw_bbox(
303
+ out,
304
+ x0=box["x0"],
305
+ y0=box["y0"],
306
+ x1=box["x1"],
307
+ y1=box["y1"],
308
+ color=color,
309
+ width=width,
310
+ caption=None if caption is None else str(caption),
311
+ caption_font=font,
312
+ )
313
+ return out
314
+
315
+
316
+ def annotate_file(
317
+ image_path: str,
318
+ annotations_path: str,
319
+ output_path: str,
320
+ *,
321
+ label_key: str = "object_id",
322
+ color_key: str = "object_id",
323
+ width: int = 3,
324
+ font_size: int = 20,
325
+ ) -> str:
326
+ """Annotate ``image_path`` using boxes from a JSON file and save the result.
327
+
328
+ Args:
329
+ image_path: Path to the source image.
330
+ annotations_path: Path to a JSON file holding a list of object dicts
331
+ (see :func:`annotate`).
332
+ output_path: Where to write the annotated image.
333
+ label_key: Object key drawn as each box's label.
334
+ color_key: Object key used to group boxes into colors.
335
+ width: Box outline width in pixels.
336
+ font_size: Label font size in points.
337
+
338
+ Returns:
339
+ ``output_path``.
340
+ """
341
+ with open(annotations_path) as f:
342
+ objects = json.load(f)
343
+ image = Image.open(image_path).convert("RGB")
344
+ font = load_pil_font(size=font_size)
345
+ out = annotate(
346
+ image,
347
+ objects,
348
+ label_key=label_key,
349
+ color_key=color_key,
350
+ width=width,
351
+ font=font,
352
+ )
353
+ out.save(output_path)
354
+ return output_path
pyproject.toml CHANGED
@@ -9,5 +9,6 @@ dependencies = [
9
  "transformers==4.44.0",
10
  "pydantic==2.10.6",
11
  "loguru>=0.7.3",
12
- "qwen-vl-utils>=0.0.11"
 
13
  ]
 
9
  "transformers==4.44.0",
10
  "pydantic==2.10.6",
11
  "loguru>=0.7.3",
12
+ "qwen-vl-utils>=0.0.11",
13
+ "typer>=0.16.0",
14
  ]
tests/test_pilbox.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Unit tests for the lite pilbox bounding-box annotation module."""
2
+
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ import pilbox
7
+
8
+
9
+ def _sample_objects():
10
+ return [
11
+ {"object_id": 0, "boundingBox": {"x0": 10, "y0": 10, "x1": 40, "y1": 60}},
12
+ {"object_id": 1, "boundingBox": {"x0": 50, "y0": 20, "x1": 90, "y1": 80}},
13
+ ]
14
+
15
+
16
+ def test_annotate_returns_same_size_copy_without_mutating_input():
17
+ im = Image.new("RGB", (100, 100), "white")
18
+ before = np.array(im).copy()
19
+
20
+ out = pilbox.annotate(im, _sample_objects())
21
+
22
+ assert isinstance(out, Image.Image)
23
+ assert out.size == im.size
24
+ # input is untouched
25
+ assert np.array_equal(np.array(im), before)
26
+ # output actually drew something (differs from a blank image)
27
+ assert not np.array_equal(np.array(out), before)
28
+
29
+
30
+ def test_color_for_is_stable_and_distinct():
31
+ mapping = {}
32
+ a1 = pilbox.color_for("a", mapping)
33
+ b = pilbox.color_for("b", mapping)
34
+ a2 = pilbox.color_for("a", mapping)
35
+
36
+ assert a1 == a2 # stable across calls
37
+ assert a1 != b # distinct keys -> distinct colors
38
+ assert a1.startswith("#") and len(a1) == 7
39
+
40
+
41
+ def test_palette_color_never_repeats_consecutively():
42
+ colors = [pilbox.palette_color(i) for i in range(50)]
43
+ assert all(c.startswith("#") and len(c) == 7 for c in colors)
44
+ # consecutive golden-angle hues are always far apart
45
+ assert all(colors[i] != colors[i + 1] for i in range(len(colors) - 1))
46
+
47
+
48
+ def test_im_draw_bbox_coerces_float_coords():
49
+ im = Image.new("RGB", (100, 100), "white")
50
+ before = np.array(im).copy()
51
+
52
+ # floats must not raise and must draw
53
+ pilbox.im_draw_bbox(im, 10.5, 10.9, 40.2, 60.7, color="red", caption="x")
54
+
55
+ assert not np.array_equal(np.array(im), before)
56
+
57
+
58
+ def test_annotate_custom_keys():
59
+ im = Image.new("RGB", (100, 100), "white")
60
+ objs = [{"cls": "player", "box": {"x0": 5, "y0": 5, "x1": 30, "y1": 30}}]
61
+ out = pilbox.annotate(im, objs, label_key="cls", color_key="cls", bbox_key="box")
62
+ assert out.size == (100, 100)
uv.lock CHANGED
The diff for this file is too large to render. See raw diff