|
| 1 | +Barcode Decoding (1-D) |
| 2 | +====================== |
| 3 | + |
| 4 | +The framework already decodes QR codes (``read_qr``), but had no reader for the |
| 5 | +*1-D* barcodes (EAN-13 / EAN-8 / UPC-A / Code-128) that label physical goods, |
| 6 | +inventory tickets and shipping labels — the most common thing a desktop or kiosk |
| 7 | +automation needs to read off a product screen. ``read_barcodes`` fills that gap |
| 8 | +using OpenCV's ``cv2.barcode.BarcodeDetector``. |
| 9 | + |
| 10 | +The decode step is an **injectable seam**: the default decoder calls OpenCV, but |
| 11 | +tests (and alternative engines) can pass their own ``decoder`` callable, so the |
| 12 | +feature is fully unit-testable headlessly and degrades gracefully — a build of |
| 13 | +OpenCV without the ``barcode`` module simply returns an empty list instead of |
| 14 | +raising. Imports no ``PySide6``. |
| 15 | + |
| 16 | +Headless API |
| 17 | +------------ |
| 18 | + |
| 19 | +.. code-block:: python |
| 20 | +
|
| 21 | + from je_auto_control import read_barcodes |
| 22 | +
|
| 23 | + # decode every 1-D barcode currently on screen |
| 24 | + for code in read_barcodes(): |
| 25 | + print(code["type"], code["text"], code["points"]) |
| 26 | +
|
| 27 | + # restrict to a region, or decode a saved image instead of the screen |
| 28 | + read_barcodes(region=[0, 0, 400, 200]) |
| 29 | + read_barcodes("label.png") |
| 30 | +
|
| 31 | +``read_barcodes(source=None, *, region=None, decoder=None)`` returns a list of |
| 32 | +``{"text", "type", "points"}`` dicts, one per detected barcode (``points`` is the |
| 33 | +four-corner polygon in image coordinates). ``source`` may be an image path or an |
| 34 | +array; when omitted the screen (optionally cropped to ``region``) is grabbed. The |
| 35 | +grayscale conversion reuses the shared ``visual_match`` haystack loader, so no new |
| 36 | +image-loading code is added. |
| 37 | + |
| 38 | +Executor command |
| 39 | +---------------- |
| 40 | + |
| 41 | +``AC_read_barcodes`` (``source`` / ``region`` → ``{count, barcodes}``) is exposed |
| 42 | +as the MCP tool ``ac_read_barcodes`` (read-only) and as a Script Builder command |
| 43 | +**Read Barcodes (1-D)** under **OCR**. |
0 commit comments