[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7C7CDEDTXR2QJPTPM3SHMV9":3,"skill-same:01M7C7CDEDTXR2QJPTPM3SHMV9":45},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":6,"ownerHtmlUrl":29,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":30,"install":31,"resources":44},"01M7C7CDEDTXR2QJPTPM3SHMV9","image-ocr",null,"Extract text content from images using Tesseract OCR via Python","linyouxue\u002Fskill-repair-benchmark","linyouxue","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F216151464?v=4","01M7BJEVCXKD74KH6FG9CBVSQB","林宥学","01M7BJEVE02NP217V93BKZFC0J",0,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fjpg-ocr-stat\u002Fevaluation\u002Fresults\u002Fmethods\u002Fskillaxe-claude4.7\u002Fgroup_02\u002Frun_02\u002Finputs\u002Fskills\u002Fimage-ocr\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: image-ocr\ndescription: Extract text content from images using Tesseract OCR via Python\n---\n\n# Image OCR Skill\n\n## Purpose\nExtract text from images (JPG\u002FPNG\u002Fetc.) using Tesseract (`pytesseract`) with receipt-friendly preprocessing and downstream parsing guidance.\n\n## When to Use\n- Scanned receipts\u002Finvoices where you must extract specific fields (e.g., date, total)\n- Batch OCR over many images\n\n## Required Libraries\n```python\nimport pytesseract\nfrom PIL import Image, ImageFilter, ImageOps\nimport os\nimport re\n```\n\n## Practical OCR Guidance for Receipts\n\n### 1) Preserve line structure\nReceipt parsing depends on line breaks. Prefer `image_to_string` outputs with newlines preserved.\n\n### 2) Use a strong default OCR baseline first\nMany receipt failures are OCR-quality failures.\n\n**Recommended baseline (try first):**\n- Preprocess: **grayscale + autocontrast**\n- OCR config: `--psm 6` (uniform block; strong default for receipts)\n\nOnly if the baseline fails, try additional variants.\n\n### 3) Minimal preprocessing variants (small set)\nTry these variants (in order):\n1. Grayscale + autocontrast (baseline)\n2. Grayscale + autocontrast + sharpen\n3. Thresholded (binary) at 1–2 thresholds\n4. Invert only if white-on-dark\n\n**Upscaling (high leverage for small\u002Ffaint receipts)**\n- If the shortest side is small (rule of thumb: `\u003C 900px`) or OCR drops\u002Fmerges digits (e.g., `1`→`7`), run an additional pass on a **2× upscaled** image.\n- If totals are still garbled (missing decimal point, keyword partially missing), add a **3× upscaled** pass and try `--psm 4` (single column) as a targeted fallback.\n- Upscaling can fix digit-merge errors on totals, but can also introduce new errors; treat it as an additional candidate source.\n\n### 4) Multi-pass OCR: select best *field* candidate, don’t concatenate\nConcatenating multi-pass text can introduce duplicate\u002Fconflicting totals.\nInstead:\n- run multiple OCR passes\n- extract date\u002Ftotal candidates per pass\n- score candidates and keep the best\n\n**Important:** Some receipts OCR better *without* preprocessing. If the baseline pass yields low-quality text (missing decimals, heavy garbage), also run a raw\u002Fdefault pass and treat it as another candidate source.\n\n## Field Extraction Heuristics (Receipts)\n\n### Date extraction (reduce false positives)\nReceipts often contain multiple date-like strings (header date\u002Ftime vs print date vs other numeric IDs).\n\n**Candidate generation**\n- Accept common formats:\n  - `dd\u002Fmm\u002Fyyyy`, `dd-mm-yyyy`, `dd\u002Fmm\u002Fyy`, `dd-mm-yy`\n  - `yyyy-mm-dd`\n- Validate plausibility:\n  - year in a reasonable range (e.g., 2000–2035)\n  - month 1–12, day 1–31\n\n**Candidate ranking (most important first)**\n1. Prefer dates on lines with an explicit label (case-insensitive):\n   - `DATE`, `DATED`, `DOC DATE`, `INVOICE DATE`\n   - **Label-tolerant matching**: treat common OCR near-misses as labels too, e.g. `DAIE`, `DAtE`, `DATA`.\n2. If multiple labeled dates exist, prefer the *primary header Date field*:\n   - appears in the header block (top portion of receipt)\n   - appears near other header keys like `INVOICE`, `RECEIPT`, `BILL NO`, `DOC #`, `CASHIER`, `TIME`\n   - **Prefer a clean `Date:` line over secondary header lines** (e.g., `Salesperson ... Data: ...`) when both exist.\n3. Prefer dates near a `TIME` token on the same\u002Fadjacent line.\n\n**Ambiguity note**\n- Do not “fix” ambiguous day\u002Fmonth swaps unless you have a strong cue.\n- If forced, Malaysian receipts commonly use `dd\u002Fmm`, but only apply when both interpretations are valid.\n\n### Total amount extraction (avoid subtotals\u002Fcash\u002Fchange)\nReceipts contain many amounts; the payable total is usually near the bottom and may be affected by rounding.\n\n**Priority keywords (highest → lowest)**\n1. `GRAND TOTAL`\n2. `TOTAL RM`, `TOTAL: RM` (also tolerate OCR `RN` for `RM`)\n3. `TOTAL AMOUNT`\n4. `TOTAL ROUNDED`, `TOTAL AMT ROUNDED`, `AMOUNT ROUNDED`, `ROUNDED TOTAL`, `TOTAL AFTER ROUNDING`\n5. `NETT TOTAL`, `NET TOTAL`, `TOTAL`, `AMOUNT`, `TOTAL DUE`, `AMOUNT DUE`, `BALANCE DUE`\n\n**Label-tolerant matching for GRAND TOTAL (common OCR corruption)**\nTreat these as GRAND TOTAL equivalents when scanning lines:\n- missing space\u002Fpunctuation: `GRANDTOTAL`, `GrandTotal.`, `GrandTota.`, `GRAND TOTA`, `GRAND TOTAI`\n\nThis matters because otherwise the extractor may fall back to weaker `TOTAL`\u002F`AMOUNT` matches or even to payment lines.\n\n**Exclusions (skip these as totals)**\nAlways exclude lines whose *primary meaning* is not the payable total:\n- `SUBTOTAL`, `SUB TOTAL`\n- `DISCOUNT`\n- `CHANGE`\n- `CASH TENDERED`, `CASH RECEIVED`, `CASH PAYMENT` (payment lines; not the payable total)\n- **Item-count totals**: `TOTAL ITEM`, `TOTAL ITEMS`, `ITEM COUNT`, `TOTAL QTY`\n- **Pre-tax totals**: `EXCL`, `EXCLUDING` (e.g., `Total (Excluding GST)`)\n\nAlso exclude **column headers** that contain `AMOUNT` but are not summary totals:\n- lines like `Description Qty Price Amount`, `QTY PRICE AMOUNT`, `AMOUNT TAX`, etc.\n\n**Important: GST\u002FSST\u002FTAX as modifiers**\nDo **not** blanket-exclude every line containing `GST`\u002F`SST`\u002F`TAX`.\n- Lines like `Total (Inclusive of GST)` can be the correct total.\n- Exclude only when the line is clearly a tax-only total\u002Fsummary (e.g., `GST Summary`, `Total GST`).\n\n**Rounding handling (common exact-match failure) — HARD RULE**\nIf a rounding adjustment exists (`ROUNDING`, `ROUNDING ADJ`, `Rounding Adj`) and there is a later\u002Ffinal\n`TOTAL` \u002F `TOTAL ROUNDED` \u002F `TOTAL AFTER ROUNDING` line, **always prefer the later\u002Ffinal total**.\n\n**Split keyword\u002Famount across lines (tight trigger)**\nUse the “next line last number” fallback **only when the keyword line has no digits at all**.\n\nAdditionally, do **not** apply this fallback to **column-header** lines (e.g., `Description Qty Price Amount`) even though they contain `AMOUNT`.\n\n**Anchor-driven outlier rejection (critical for OCR digit flips like 102.00→702.00)**\nWhen multiple total-like candidates exist, do not rely on “last TOTAL wins” or “majority across OCR variants” alone.\n\n1. Extract **anchor amounts** (if present):\n   - `SUBTOTAL` amount\n   - `PAYMENT` amount (or `VISA`, `MASTERCARD` charge amount)\n   - `TOTAL AFTER ROUNDING` \u002F `TOTAL ROUNDED` amount\n2. If **two or more** anchors agree (exact match after normalization) and a candidate total differs,\n   treat the candidate as an OCR outlier and reject it.\n3. **Mechanical override (make it hard to miss):**\n   - If `PAYMENT` exists and matches one candidate total, prefer the candidate matching `PAYMENT`.\n   - If `SUBTOTAL` exists and matches one candidate total, prefer the candidate matching `SUBTOTAL`.\n   - Only allow a “rounded total” line to override anchors if it is consistent with them (or differs only by a small rounding delta that is explicitly shown).\n\n### Amount string normalization (critical for exact-match scoring)\nWhen you extract a numeric amount:\n- Remove currency markers (`RM`, `$`) and thousands separators (`,`)\n- Normalize common OCR punctuation:\n  - treat `:` or `;` between digits as `.` when it looks like a decimal separator (e.g., `92:80` → `92.80`)\n- Output must be a string with **exactly two decimal places** (e.g., `\"47.70\"`).\n- If extraction fails\u002Funcertain: output **None\u002Fnull**.\n  - **Never** output an empty string.\n\n**Drop-in final validation snippet (prevents empty-string bugs + fixes 92:80)**\n```python\nimport re\n\ndef finalize_amount(maybe_amount_str):\n    if maybe_amount_str is None:\n        return None\n    s = str(maybe_amount_str).strip()\n    if not s:\n        return None\n    s = s.replace(',', '')\n    # Normalize OCR decimal separators like 92:80 or 92;80\n    s = re.sub(r'(\\d)[:;](\\d{2})\\b', r'\\1.\\2', s)\n    m = re.search(r'(\\d+)(?:\\.(\\d{1,2}))?$', s)\n    if not m:\n        return None\n    whole = m.group(1)\n    frac = (m.group(2) or '00').ljust(2, '0')\n    return f\"{int(whole)}.{frac[:2]}\"\n```\n\n## Code Example: receipt-oriented multi-pass OCR (texts kept separate)\n```python\nfrom PIL import Image, ImageOps, ImageFilter\nimport pytesseract\n\n\ndef _variants(img):\n    g = ImageOps.grayscale(img)\n    yield ImageOps.autocontrast(g)  # baseline\n    yield ImageOps.autocontrast(g).filter(ImageFilter.SHARPEN)\n    for t in (110, 140):\n        yield ImageOps.autocontrast(g).point(lambda p, tt=t: 255 if p > tt else 0)\n\n\ndef ocr_receipt_texts(image_path):\n    img = Image.open(image_path)\n\n    # Include a raw\u002Fdefault pass because some receipts OCR better without preprocessing.\n    texts = [pytesseract.image_to_string(img, lang='eng')]\n\n    # Strong baseline first.\n    psm_modes = ['--psm 6', '--psm 4', '--psm 11']\n    for v in _variants(img):\n        for psm in psm_modes:\n            txt = pytesseract.image_to_string(v, lang='eng', config=psm)\n            if txt and txt.strip():\n                texts.append(txt)\n\n    # Optional: add an upscaled pass as another candidate source.\n    if min(img.size) \u003C 900:\n        big2 = img.resize((img.size[0] * 2, img.size[1] * 2))\n        big2 = ImageOps.autocontrast(ImageOps.grayscale(big2))\n        texts.append(pytesseract.image_to_string(big2, lang='eng', config='--psm 6'))\n\n        # Harder fallback: 3× + PSM 4 can recover faint “Grand Total” lines.\n        big3 = img.resize((img.size[0] * 3, img.size[1] * 3))\n        big3 = ImageOps.autocontrast(ImageOps.grayscale(big3))\n        texts.append(pytesseract.image_to_string(big3, lang='eng', config='--psm 4'))\n\n    return texts\n```\n\n## Error Handling\n- If OCR is empty\u002Fgarbage, try a different PSM and a thresholded variant.\n- If the receipt is rotated, try rotating 90\u002F180 degrees and re-running OCR.\n\n## Quality Self-Check\n- [ ] Preserve newlines in OCR output\n- [ ] Start with grayscale+autocontrast + `--psm 6` baseline\n- [ ] Also consider a raw\u002Fdefault OCR pass as an additional candidate source\n- [ ] Consider a 2× upscaled OCR pass as an additional candidate source (don’t blindly trust it)\n- [ ] If totals\u002Fkeywords are still garbled, consider a 3× upscaled + `--psm 4` pass as a targeted fallback\n- [ ] Date: prefer label-adjacent, header-block candidates; validate plausibility\n- [ ] Total: apply priority keywords + exclusions\n- [ ] Exclude column-header lines containing `AMOUNT` (e.g., `Description Qty Price Amount`)\n- [ ] Split-line fallback triggers only when keyword line has **no digits** and is **not** a column header\n- [ ] If rounding adjustment exists and a later TOTAL exists: **take the later TOTAL**\n- [ ] Apply anchor-driven outlier rejection (Subtotal\u002FPayment\u002FRounded-total consistency)\n- [ ] Normalize totals to exactly two decimals (including `92:80` → `92.80`)\n- [ ] Final schema guard: empty\u002Fwhitespace-only → **None\u002Fnull** (never empty string)\n\n## Limitations\n- Tesseract accuracy drops on very faint ink, heavy blur, or extreme skew\n- Complex multi-column layouts may require cropping or per-region OCR\n\n## Version History\n- **1.1.6** (2026-10-21): Added explicit exclusion of column-header lines containing AMOUNT; clarified that split-line fallback must not trigger on headers; added optional 3× upscale + PSM4 fallback for faint\u002Fgarbled GRAND TOTAL lines; expanded GRAND TOTAL tolerant variants to include punctuation\u002Fno-space forms.\n- **1.1.5** (2026-10-21): Added label-tolerant GRAND TOTAL matching; tightened split-line fallback trigger (only when keyword line has no digits); expanded cash-payment exclusions; emphasized that anchor-consistency must override OCR-variant majority voting for totals\n- **1.1.4** (2026-10-21): Added explicit 2× upscaling as a candidate OCR pass; strengthened mechanical anchor-consistency override for totals; clarified header-date preference when multiple labeled dates exist; added explicit schema-guard checklist item\n- **1.1.3** (2026-10-21): Added anchor-driven outlier rejection (Subtotal\u002FPayment\u002FRounded consistency), made rounding precedence a hard rule, strengthened header-context date ranking, and added a drop-in final validation snippet to prevent empty-string totals\n- **1.1.2** (2026-10-21): Strengthened default preprocessing+PSM baseline, added explicit item-count exclusions, clarified rounding precedence as hard rule, and added explicit final output validation step\n- **1.1.1** (2026-10-21): Added label-tolerant date ranking, rounding precedence, outlier rejection, strict null\u002F2dp normalization\n- **1.0.0** (2026-01-13): Initial release\n","# Image OCR Skill\n\n## Purpose\nExtract text from images (JPG\u002FPNG\u002Fetc.) using Tesseract (`pytesseract`) with receipt-friendly preprocessing and downstream parsing guidance.\n\n## When to Use\n- Scanned receipts\u002Finvoices where you must extract specific fields (e.g., date, total)\n- Batch OCR over many images\n\n## Required Libraries\n```python\nimport pytesseract\nfrom PIL import Image, ImageFilter, ImageOps\nimport os\nimport re\n```\n\n## Practical OCR Guidance for Receipts\n\n### 1) Preserve line structure\nReceipt parsing depends on line breaks. Prefer `image_to_string` outputs with newlines preserved.\n\n### 2) Use a strong default OCR baseline first\nMany receipt failures are OCR-quality failures.\n\n**Recommended baseline (try first):**\n- Preprocess: **grayscale + autocontrast**\n- OCR config: `--psm 6` (uniform block; strong default for receipts)\n\nOnly if the baseline fails, try additional variants.\n\n### 3) Minimal preprocessing variants (small set)\nTry these variants (in order):\n1. Grayscale + autocontrast (baseline)\n2. Grayscale + autocontrast + sharpen\n3. Thresholded (binary) at 1–2 thresholds\n4. Invert only if white-on-dark\n\n**Upscaling (high leverage for small\u002Ffaint receipts)**\n- If the shortest side is small (rule of thumb: `\u003C 900px`) or OCR drops\u002Fmerges digits (e.g., `1`→`7`), run an additional pass on a **2× upscaled** image.\n- If totals are still garbled (missing decimal point, keyword partially missing), add a **3× upscaled** pass and try `--psm 4` (single column) as a targeted fallback.\n- Upscaling can fix digit-merge errors on totals, but can also introduce new errors; treat it as an additional candidate source.\n\n### 4) Multi-pass OCR: select best *field* candidate, don’t concatenate\nConcatenating multi-pass text can introduce duplicate\u002Fconflicting totals.\nInstead:\n- run multiple OCR passes\n- extract date\u002Ftotal candidates per pass\n- score candidates and keep the best\n\n**Important:** Some receipts OCR better *without* preprocessing. If the baseline pass yields low-quality text (missing decimals, heavy garbage), also run a raw\u002Fdefault pass and treat it as another candidate source.\n\n## Field Extraction Heuristics (Receipts)\n\n### Date extraction (reduce false positives)\nReceipts often contain multiple date-like strings (header date\u002Ftime vs print date vs other numeric IDs).\n\n**Candidate generation**\n- Accept common formats:\n  - `dd\u002Fmm\u002Fyyyy`, `dd-mm-yyyy`, `dd\u002Fmm\u002Fyy`, `dd-mm-yy`\n  - `yyyy-mm-dd`\n- Validate plausibility:\n  - year in a reasonable range (e.g., 2000–2035)\n  - month 1–12, day 1–31\n\n**Candidate ranking (most important first)**\n1. Prefer dates on lines with an explicit label (case-insensitive):\n   - `DATE`, `DATED`, `DOC DATE`, `INVOICE DATE`\n   - **Label-tolerant matching**: treat common OCR near-misses as labels too, e.g. `DAIE`, `DAtE`, `DATA`.\n2. If multiple labeled dates exist, prefer the *primary header Date field*:\n   - appears in the header block (top portion of receipt)\n   - appears near other header keys like `INVOICE`, `RECEIPT`, `BILL NO`, `DOC #`, `CASHIER`, `TIME`\n   - **Prefer a clean `Date:` line over secondary header lines** (e.g., `Salesperson ... Data: ...`) when both exist.\n3. Prefer dates near a `TIME` token on the same\u002Fadjacent line.\n\n**Ambiguity note**\n- Do not “fix” ambiguous day\u002Fmonth swaps unless you have a strong cue.\n- If forced, Malaysian receipts commonly use `dd\u002Fmm`, but only apply when both interpretations are valid.\n\n### Total amount extraction (avoid subtotals\u002Fcash\u002Fchange)\nReceipts contain many amounts; the payable total is usually near the bottom and may be affected by rounding.\n\n**Priority keywords (highest → lowest)**\n1. `GRAND TOTAL`\n2. `TOTAL RM`, `TOTAL: RM` (also tolerate OCR `RN` for `RM`)\n3. `TOTAL AMOUNT`\n4. `TOTAL ROUNDED`, `TOTAL AMT ROUNDED`, `AMOUNT ROUNDED`, `ROUNDED TOTAL`, `TOTAL AFTER ROUNDING`\n5. `NETT TOTAL`, `NET TOTAL`, `TOTAL`, `AMOUNT`, `TOTAL DUE`, `AMOUNT DUE`, `BALANCE DUE`\n\n**Label-tolerant matching for GRAND TOTAL (common OCR corruption)**\nTreat these as GRAND TOTAL equivalents when scanning lines:\n- missing space\u002Fpunctuation: `GRANDTOTAL`, `GrandTotal.`, `GrandTota.`, `GRAND TOTA`, `GRAND TOTAI`\n\nThis matters because otherwise the extractor may fall back to weaker `TOTAL`\u002F`AMOUNT` matches or even to payment lines.\n\n**Exclusions (skip these as totals)**\nAlways exclude lines whose *primary meaning* is not the payable total:\n- `SUBTOTAL`, `SUB TOTAL`\n- `DISCOUNT`\n- `CHANGE`\n- `CASH TENDERED`, `CASH RECEIVED`, `CASH PAYMENT` (payment lines; not the payable total)\n- **Item-count totals**: `TOTAL ITEM`, `TOTAL ITEMS`, `ITEM COUNT`, `TOTAL QTY`\n- **Pre-tax totals**: `EXCL`, `EXCLUDING` (e.g., `Total (Excluding GST)`)\n\nAlso exclude **column headers** that contain `AMOUNT` but are not summary totals:\n- lines like `Description Qty Price Amount`, `QTY PRICE AMOUNT`, `AMOUNT TAX`, etc.\n\n**Important: GST\u002FSST\u002FTAX as modifiers**\nDo **not** blanket-exclude every line containing `GST`\u002F`SST`\u002F`TAX`.\n- Lines like `Total (Inclusive of GST)` can be the correct total.\n- Exclude only when the line is clearly a tax-only total\u002Fsummary (e.g., `GST Summary`, `Total GST`).\n\n**Rounding handling (common exact-match failure) — HARD RULE**\nIf a rounding adjustment exists (`ROUNDING`, `ROUNDING ADJ`, `Rounding Adj`) and there is a later\u002Ffinal\n`TOTAL` \u002F `TOTAL ROUNDED` \u002F `TOTAL AFTER ROUNDING` line, **always prefer the later\u002Ffinal total**.\n\n**Split keyword\u002Famount across lines (tight trigger)**\nUse the “next line last number” fallback **only when the keyword line has no digits at all**.\n\nAdditionally, do **not** apply this fallback to **column-header** lines (e.g., `Description Qty Price Amount`) even though they contain `AMOUNT`.\n\n**Anchor-driven outlier rejection (critical for OCR digit flips like 102.00→702.00)**\nWhen multiple total-like candidates exist, do not rely on “last TOTAL wins” or “majority across OCR variants” alone.\n\n1. Extract **anchor amounts** (if present):\n   - `SUBTOTAL` amount\n   - `PAYMENT` amount (or `VISA`, `MASTERCARD` charge amount)\n   - `TOTAL AFTER ROUNDING` \u002F `TOTAL ROUNDED` amount\n2. If **two or more** anchors agree (exact match after normalization) and a candidate total differs,\n   treat the candidate as an OCR outlier and reject it.\n3. **Mechanical override (make it hard to miss):**\n   - If `PAYMENT` exists and matches one candidate total, prefer the candidate matching `PAYMENT`.\n   - If `SUBTOTAL` exists and matches one candidate total, prefer the candidate matching `SUBTOTAL`.\n   - Only allow a “rounded total” line to override anchors if it is consistent with them (or differs only by a small rounding delta that is explicitly shown).\n\n### Amount string normalization (critical for exact-match scoring)\nWhen you extract a numeric amount:\n- Remove currency markers (`RM`, `$`) and thousands separators (`,`)\n- Normalize common OCR punctuation:\n  - treat `:` or `;` between digits as `.` when it looks like a decimal separator (e.g., `92:80` → `92.80`)\n- Output must be a string with **exactly two decimal places** (e.g., `\"47.70\"`).\n- If extraction fails\u002Funcertain: output **None\u002Fnull**.\n  - **Never** output an empty string.\n\n**Drop-in final validation snippet (prevents empty-string bugs + fixes 92:80)**\n```python\nimport re\n\ndef finalize_amount(maybe_amount_str):\n    if maybe_amount_str is None:\n        return None\n    s = str(maybe_amount_str).strip()\n    if not s:\n        return None\n    s = s.replace(',', '')\n    # Normalize OCR decimal separators like 92:80 or 92;80\n    s = re.sub(r'(\\d)[:;](\\d{2})\\b', r'\\1.\\2', s)\n    m = re.search(r'(\\d+)(?:\\.(\\d{1,2}))?$', s)\n    if not m:\n        return None\n    whole = m.group(1)\n    frac = (m.group(2) or '00').ljust(2, '0')\n    return f\"{int(whole)}.{frac[:2]}\"\n```\n\n## Code Example: receipt-oriented multi-pass OCR (texts kept separate)\n```python\nfrom PIL import Image, ImageOps, ImageFilter\nimport pytesseract\n\n\ndef _variants(img):\n    g = ImageOps.grayscale(img)\n    yield ImageOps.autocontrast(g)  # baseline\n    yield ImageOps.autocontrast(g).filter(ImageFilter.SHARPEN)\n    for t in (110, 140):\n        yield ImageOps.autocontrast(g).point(lambda p, tt=t: 255 if p > tt else 0)\n\n\ndef ocr_receipt_texts(image_path):\n    img = Image.open(image_path)\n\n    # Include a raw\u002Fdefault pass because some receipts OCR better without preprocessing.\n    texts = [pytesseract.image_to_string(img, lang='eng')]\n\n    # Strong baseline first.\n    psm_modes = ['--psm 6', '--psm 4', '--psm 11']\n    for v in _variants(img):\n        for psm in psm_modes:\n            txt = pytesseract.image_to_string(v, lang='eng', config=psm)\n            if txt and txt.strip():\n                texts.append(txt)\n\n    # Optional: add an upscaled pass as another candidate source.\n    if min(img.size) \u003C 900:\n        big2 = img.resize((img.size[0] * 2, img.size[1] * 2))\n        big2 = ImageOps.autocontrast(ImageOps.grayscale(big2))\n        texts.append(pytesseract.image_to_string(big2, lang='eng', config='--psm 6'))\n\n        # Harder fallback: 3× + PSM 4 can recover faint “Grand Total” lines.\n        big3 = img.resize((img.size[0] * 3, img.size[1] * 3))\n        big3 = ImageOps.autocontrast(ImageOps.grayscale(big3))\n        texts.append(pytesseract.image_to_string(big3, lang='eng', config='--psm 4'))\n\n    return texts\n```\n\n## Error Handling\n- If OCR is empty\u002Fgarbage, try a different PSM and a thresholded variant.\n- If the receipt is rotated, try rotating 90\u002F180 degrees and re-running OCR.\n\n## Quality Self-Check\n- [ ] Preserve newlines in OCR output\n- [ ] Start with grayscale+autocontrast + `--psm 6` baseline\n- [ ] Also consider a raw\u002Fdefault OCR pass as an additional candidate source\n- [ ] Consider a 2× upscaled OCR pass as an additional candidate source (don’t blindly trust it)\n- [ ] If totals\u002Fkeywords are still garbled, consider a 3× upscaled + `--psm 4` pass as a targeted fallback\n- [ ] Date: prefer label-adjacent, header-block candidates; validate plausibility\n- [ ] Total: apply priority keywords + exclusions\n- [ ] Exclude column-header lines containing `AMOUNT` (e.g., `Description Qty Price Amount`)\n- [ ] Split-line fallback triggers only when keyword line has **no digits** and is **not** a column header\n- [ ] If rounding adjustment exists and a later TOTAL exists: **take the later TOTAL**\n- [ ] Apply anchor-driven outlier rejection (Subtotal\u002FPayment\u002FRounded-total consistency)\n- [ ] Normalize totals to exactly two decimals (including `92:80` → `92.80`)\n- [ ] Final schema guard: empty\u002Fwhitespace-only → **None\u002Fnull** (never empty string)\n\n## Limitations\n- Tesseract accuracy drops on very faint ink, heavy blur, or extreme skew\n- Complex multi-column layouts may require cropping or per-region OCR\n\n## Version History\n- **1.1.6** (2026-10-21): Added explicit exclusion of column-header lines containing AMOUNT; clarified that split-line fallback must not trigger on headers; added optional 3× upscale + PSM4 fallback for faint\u002Fgarbled GRAND TOTAL lines; expanded GRAND TOTAL tolerant variants to include punctuation\u002Fno-space forms.\n- **1.1.5** (2026-10-21): Added label-tolerant GRAND TOTAL matching; tightened split-line fallback trigger (only when keyword line has no digits); expanded cash-payment exclusions; emphasized that anchor-consistency must override OCR-variant majority voting for totals\n- **1.1.4** (2026-10-21): Added explicit 2× upscaling as a candidate OCR pass; strengthened mechanical anchor-consistency override for totals; clarified header-date preference when multiple labeled dates exist; added explicit schema-guard checklist item\n- **1.1.3** (2026-10-21): Added anchor-driven outlier rejection (Subtotal\u002FPayment\u002FRounded consistency), made rounding precedence a hard rule, strengthened header-context date ranking, and added a drop-in final validation snippet to prevent empty-string totals\n- **1.1.2** (2026-10-21): Strengthened default preprocessing+PSM baseline, added explicit item-count exclusions, clarified rounding precedence as hard rule, and added explicit final output validation step\n- **1.1.1** (2026-10-21): Added label-tolerant date ranking, rounding precedence, outlier rejection, strict null\u002F2dp normalization\n- **1.0.0** (2026-01-13): Initial release\n",{"name":5,"description":7},"main","cdcb6d230f3b15c3c33f8a2bdd16439f43602cbe","jpg-ocr-stat\u002Fevaluation\u002Fresults\u002Fmethods\u002Fskillaxe-claude4.7\u002Fgroup_02\u002Frun_02\u002Finputs\u002Fskills\u002Fimage-ocr",1,"https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark","https:\u002F\u002Fgithub.com\u002Flinyouxue","2026-11-14 20:28:35",{"source":8,"skillName":5,"commands":32,"prompt":42,"zipAvailable":43},[33,36,39],{"tool":34,"command":35},"npx","npx skills add linyouxue\u002Fskill-repair-benchmark --skill image-ocr",{"tool":37,"command":38},"bunx","bunx skills add linyouxue\u002Fskill-repair-benchmark --skill image-ocr",{"tool":40,"command":41},"pnpm","pnpm dlx skills add linyouxue\u002Fskill-repair-benchmark --skill image-ocr","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fjpg-ocr-stat\u002Fevaluation\u002Fresults\u002Fmethods\u002Fskillaxe-claude4.7\u002Fgroup_02\u002Frun_02\u002Finputs\u002Fskills\u002Fimage-ocr\u002FSKILL.md",true,[],[46,53,60,66,71,76],{"skillNo":47,"name":48,"nameZh":6,"description":49,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":50,"categories":51,"keywords":52,"publishedAt":19},"01M7E1HGVRY73NBJ022CJG13X6","video-frame-extraction","Extract frames from video files and save them as images using OpenCV","https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fjpg-ocr-stat\u002Fresult\u002Fskilltta-claude4.7\u002Fgroup_03\u002Frun_03\u002Finputs\u002Fskills\u002Fvideo-frame-extraction\u002FSKILL.md",[],[],{"skillNo":54,"name":55,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":57,"categories":58,"keywords":59,"publishedAt":19},"01M7E1HAG5R7CJ9C8NYJS771MB","openai-vision","Analyze images and multi-frame sequences using OpenAI GPT vision models","https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fjpg-ocr-stat\u002Fresult\u002Fskilltta-claude4.7\u002Fgroup_03\u002Frun_03\u002Finputs\u002Fskills\u002Fopenai-vision\u002FSKILL.md",[],[],{"skillNo":61,"name":5,"nameZh":6,"description":62,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":63,"categories":64,"keywords":65,"publishedAt":19},"01M7E1H7DADKB6QBWKC2KQ63SZ","Extract text content from images using Tesseract OCR via Python, including structured field extraction from receipts and forms","https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fjpg-ocr-stat\u002Fresult\u002Fskilltta-claude4.7\u002Fgroup_03\u002Frun_03\u002Finputs\u002Fskills\u002Fimage-ocr\u002FSKILL.md",[],[],{"skillNo":67,"name":48,"nameZh":6,"description":49,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":68,"categories":69,"keywords":70,"publishedAt":19},"01M7E1H0WBNT43TENGQY7AVZHD","https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fjpg-ocr-stat\u002Fresult\u002Fskilltta-claude4.7\u002Fgroup_03\u002Frun_02\u002Finputs\u002Fskills\u002Fvideo-frame-extraction\u002FSKILL.md",[],[],{"skillNo":72,"name":55,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":73,"categories":74,"keywords":75,"publishedAt":19},"01M7E1GTC7D4N4Q2EF03875J9E","https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fjpg-ocr-stat\u002Fresult\u002Fskilltta-claude4.7\u002Fgroup_03\u002Frun_02\u002Finputs\u002Fskills\u002Fopenai-vision\u002FSKILL.md",[],[],{"skillNo":77,"name":5,"nameZh":6,"description":62,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":78,"categories":79,"keywords":80,"publishedAt":19},"01M7E1GQ92CWFMGH53KSSE4WER","https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fjpg-ocr-stat\u002Fresult\u002Fskilltta-claude4.7\u002Fgroup_03\u002Frun_02\u002Finputs\u002Fskills\u002Fimage-ocr\u002FSKILL.md",[],[]]