Skip to content

workers / wine_inventory / src / pince_shelf / vision / crop_with_json.py

Path: workers/wine_inventory/src/pince_shelf/vision/crop_with_json.py
Lane: workers
Executable: yes

Purpose

Crop shelf cell images from a rectified shelf image using a JSON polygon file.

Refactor goals (Wine Platform conventions): - Callable run(cfg) for orchestration (stock_runtime.py) - Keep a simple main() for manual debugging - NO argparse: driven by project settings (INI + env) and constants in this file - Logging + exceptions (pipeline can stop on failure)

Inputs (default): - Image: <snapshot_dir>/shelf_rectified.jpg - JSON: <snapshot_dir>/cells_polygons.json (or auto-detected)

Outputs: - Crops: <cfg.paths["crop_out"]>/<cell_id>.png (cell_id is already formatted like nn_nn) - Debug: <cfg.paths["crop_out"]>/crop_cells_debug/...

Entry points

  • __main__ guard detected

Key symbols

Classes

  • CellPoly

Functions

  • _crop_one(img, cell)
  • _draw_polys_debug(img, cells)
  • _find_polygons_json(snapshot_dir)
  • _load_json(path)
  • _mkdir(p)
  • _parse_cells(data)
  • _poly_bbox(poly, w, h)
  • _safe_imread(path)
  • main()
  • run(cfg)

Configuration & environment

  • (no env vars detected by regex)

Dependencies (imports)

  • __future__
  • cv2
  • dataclasses
  • json
  • logging
  • numpy
  • pathlib
  • pince_shelf.config.settings
  • pince_shelf.utils.paths
  • typing

Operational notes (fill in)

  • Headless/interactive:
  • Systemd unit (if any):
  • Schedules/triggers:
  • Debug artifacts:
  • Failure modes: