api.services.label_ocr¶
Label OCR for the receiving workflow (product-creation spec §6A “Identify and group”): read a label photo with the OCR sidecar (ocr/, RapidOCR) and extract candidate brand, model and serial number.
Candidates only: the app shows them next to the photo and a person applies
them. Runs in a Celery task (api/tasks.py run_label_ocr) so capture never
waits for it.
Attributes¶
Functions¶
|
|
|
Top to bottom, then left to right (rows within ~12 px). |
|
Brand, model and serial candidates. The serial is searched by its |
|
Same serial up to separators/case, or one containing the other. |
Module Contents¶
- api.services.label_ocr.OCR_TIMEOUT_SECONDS = 60¶
- api.services.label_ocr.SERIAL_LABEL = '(?:s\\s*/\\s*n|[s5][e3]r[il1|!][a@4][l1|i][\\s.\\-]*(?:no|n[o°º]|number|nr)?|n[o°º]\\s*(?:de\\s*...¶
- api.services.label_ocr.MODEL_LABEL = '(?:(?:model(?:(?:e|l)\\b)?|mod\\.|type|typ|device|r[ée]f(?:[ée]rence)?\\.?)(?:\\s*(?:no|nr|n[o°º...¶
- api.services.label_ocr.PART_LABEL = '(?:cat\\.?\\s*(?:no|nr)\\.?|p\\s*/\\s*n|part\\s*(?:no|number)|art\\.?\\s*-?\\s*(?:no|nr)\\.?)'¶
- api.services.label_ocr.TRUNCATED_SERIAL¶
- api.services.label_ocr.VALUE = '(?!(?:no|nr|n[o°º]|number|num)\\b)([A-Za-z0-9][A-Za-z0-9\\-/.]{2,}(?:\\s[A-Za-z0-9\\-/.]{1,})?)'¶
- api.services.label_ocr.SERIAL_VALUE = '(?!(?:no|nr|n[o°º]|number|num)\\b)(?=\\S*\\d)([A-Za-z0-9][A-Za-z0-9\\-/.]{2,})'¶
- api.services.label_ocr.SEPARATOR = '\\s*[:#.\\-]{0,3}\\s*'¶
- api.services.label_ocr.call_ocr(image: bytes, content_type: str = 'image/jpeg') list[dict[str, Any]]¶
- api.services.label_ocr.reading_order(lines: list[dict[str, Any]]) list[dict[str, Any]]¶
Top to bottom, then left to right (rows within ~12 px).
- api.services.label_ocr.SERIAL_KEYWORDS = ('serial', 'serialno', 'serialnr', 'serialnumber', 'seriennr', 'seriennummer', 'seriesno',...¶
- api.services.label_ocr.FUZZY_LABEL_RATIO = 0.8¶
- api.services.label_ocr.extract_fields(lines: list[dict[str, Any]], brands: list[str]) dict[str, Any]¶
Brand, model and serial candidates. The serial is searched by its label, then by a label that only looks like one (OCR errors, unusual spelling), then by its shape alone: the guesses carry
guess: trueand a lower confidence.
- api.services.label_ocr.serial_matches(expected: str | None, found: str | None) bool¶
Same serial up to separators/case, or one containing the other.