Jpg ocr stat

From XuShuwenn/RedAct · View interactive version

Jpg ocr stat is an AI agent skill from the GitHub repository XuShuwenn/RedAct. Extract date and total amount from receipt JPG images using OCR, and write results to Excel file.

How to use this skill

Skill file

Receipt OCR and Statistics

When to Use

Mandatory executor-protocol checklist

Input

Output

Excel file /app/workspace/stat_ocr.xlsx:

Execution

Validation Workflow

Date Extraction

Total Amount Extraction

Keywords (priority order):

  1. GRAND TOTAL
  2. TOTAL RM, TOTAL: RM
  3. TOTAL AMOUNT
  4. TOTAL, AMOUNT, TOTAL DUE, etc.

Use candidate scoring, not just "last number on a matched line". Prefer lines with strong final-total phrases and penalize headers/summary labels such as Description Amount, Sales, Qty, QTY ITEM TOTAL, or non-final tax summaries.

Build the total decision in two phases: (1) collect candidate amounts from same-line or clearly adjacent total-related text, then (2) rank candidates by positive and negative context. Do not use a raw "keyword hit + last number" rule as the final selector.

When choosing between nearby totals, prefer the payable/final-total line over tax-inclusive sales summaries or table/header lines. Examples to penalize unless they clearly indicate the final payable amount: Total Sales Incl GST, Description Amount, Amount, Sales, item-table headers, and intermediate summary lines.

Enforce keyword priority strictly: if a higher-priority keyword is present, do not fall back to lower-priority groups for that receipt.

If implementing grouped scans in code, track whether any higher-priority group matched at all; once matched, either return an amount from that group or return null for unresolved total rather than continuing to lower-priority groups.

Accept an amount only when it is on the same line as, or immediately adjacent to, a total-related keyword. Treat next-line fallback after a keyword as high-risk; use it only when same-line extraction fails and the keyword line clearly indicates a payable final total, not a broad header/table label or metadata.

Before accepting a total candidate, check nearby OCR text for conflicting numeric contexts (for example litres, quantities, unit prices, item lines, reference numbers, or header/table labels). If the candidate is not clearly the payable final total, set it to null instead of forcing a match.

Treat exclusion terms as negative signals, not absolute blockers: do not discard a line just because it contains GST/SST if it also contains a high-priority total phrase like TOTAL RM or GRAND TOTAL.

Exclude or heavily penalize lines with: SUBTOTAL, DISCOUNT, CHANGE, CASH TENDERED, ROUNDING, tax-only summaries.

Treat generic words like AMOUNT or TOTAL alone as weak signals; prefer strong phrases such as GRAND TOTAL, TOTAL RM, TOTAL AMOUNT, or TOTAL DUE.

Prefer specific final-total phrases and stronger keyword matches over a larger numeric value elsewhere. Reject candidates near unrelated contexts such as litre/quantity/unit-price/item lines, even if the OCR text is noisy.

Do not invent decimals from ambiguous integers unless the receipt text gives strong explicit currency or decimal evidence. Prefer decimal amounts associated with total keywords; avoid plain integers unless the receipt clearly shows no cents.

Treat 0.00 as suspicious unless the OCR text explicitly shows a zero total; otherwise inspect the source line or fallback match and set to null if unresolved.

Do NOT let a later weak match override an earlier stronger total candidate just because it appears lower on the receipt.

Use semantic labels as the primary signal for totals: prioritize payable/final-total phrases, then use exclusions/penalties to reject lookalikes such as subtotal, tax summary, change, cash tendered, rounding, item-table headers, and quantity/price lines.

Do not choose a candidate mainly because it is the largest number or the last number on the receipt; require stronger labeled final-total context.

Evaluate all OCR variants before choosing total_amount; do not stop at the first non-null match.

Use a ranked selection pattern:

  1. collect total candidates from every OCR/preprocessing variant
  2. normalize lightly corrupted amount strings only when strong nearby total context supports it (for example 85. 54 -> 85.54, 538 00 -> 538.00, 99,80 -> 99.80, and standard comma-thousands cleanup)
  3. score by keyword strength, same-line proximity, final-total context, and plausibility
  4. prefer repeated non-zero candidates across variants over one-off weak matches
  5. write null if candidates conflict and no clear winner remains

Do not lock in 0.00, null, or another weak value from an early variant while later variants contain a stronger supported total.

If multiple total candidates conflict and context does not clearly disambiguate them, set total_amount to null.

Handle comma separators (1,234.56).

Extraction Reliability

Extraction Reliability

Tips

Execution and Recovery

Final Verification

Final Verification

Execution and Recovery

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.