Skip to content

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

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

Purpose

pince_shelf corner marker tracking (industrial-style)

Goal - Reliably find 4 corner markers (white square with black dot) to rectify shelf image.

Method 1) Use expected corner locations from pince_shelf.ini (cfg.main_points). 2) Track each corner independently inside a bounded ROI using template matching on gradient magnitude (robust to lighting). 3) Refine the matched location by locating the black dot centroid near the match. 4) Validate the 4-point quad (convex, large enough). 5) Warp perspective.

Templates - Store 4 png templates: TL.png TR.png BL.png BR.png. - You can initialize them from a "good" snapshot with --init-templates.

Debug outputs (written to snapshot_dir/tmp/shelf_debug): - 00_roi_overlay.png : original with corner-search ROIs - 01_grad_roi.png : gradient image (for inspection) - 02_tracked_points.png : final tracked points + corr score - 03_warped.png : rectified image - 04_capture_ready_roi.png : shelf ROI used for illumination-readiness gate - 05_capture_ready_frame.png : accepted snapshot frame

CLI (minimal): python detect_corner_markers_industrial.py --cam python detect_corner_markers_industrial.py --init-templates

Entry points

  • __main__ guard detected

Key symbols

Classes

  • Settings

Functions

  • _clahe_gray(bgr)
  • _draw_capture_ready_roi(frame, roi, metrics)
  • _ensure_dir(p)
  • _expected_from_cfg(cfg)
  • _frame_luma_stats(frame, roi)
  • _gradmag(gray)
  • _is_good_quad(pts)
  • _order_points_tl_tr_bl_br(pts)
  • _roi_rect(cx, cy, r, w, h)
  • _scene_illumination_ready(frames)
  • _shelf_roi_from_expected(cfg, frame_shape)
  • _write_dbg(debug_dir, name, img)
  • geometric_stabilize(pts)
  • init_templates_from_snapshot(bgr, expected, template_dir)
  • load_corner_templates(template_dir)
  • main()
  • read_good_frame_with_reconnect(rtsp_url)
  • rectify_by_markers(bgr, pts, settings, debug_dir)
  • refine_by_dot(gray, cx, cy)
  • run(cfg)
  • serialize_pts(pts)
  • smooth_with_history(current_pts, json_dir)
  • take_snapshot(cfg)
  • track_all_corners(bgr, expected, templates_grad, settings, debug_dir)
  • track_corner(bgr, expected_xy, template_grad)

Configuration & environment

  • (no env vars detected by regex)

Dependencies (imports)

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

Operational notes (fill in)

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