$npx -y skills add matlab/matlab-agentic-toolkit --skill matlab-ocrBuild OCR pipelines in MATLAB using the ocr() function. Use this skill when the user wants to read text from images, documents, signs, meters, displays, license plates, gauges, receipts, or seven-segment displays. Covers image preprocessing, text detection (CRAFT, MSER), ROI-base
| 1 | # Recognize Text in Images Using OCR |
| 2 | |
| 3 | Use the Computer Vision Toolbox `ocr` function with preprocessing from Image Processing Toolbox to extract text from images. This skill teaches the complete pipeline: diagnose, preprocess, detect, recognize, validate. |
| 4 | |
| 5 | ## When to Use |
| 6 | - Reading text from any image (documents, signs, meters, displays, labels) |
| 7 | - Extracting text from scanned documents or photographs |
| 8 | - Reading seven-segment displays or specialized fonts |
| 9 | - Multi-language text recognition |
| 10 | - Automating text extraction from image datasets |
| 11 | - As a supporting step in other CV workflows — reading text in a scene (labels, timestamps, serial numbers) gives additional context for downstream image analysis |
| 12 | |
| 13 | ## When NOT to Use |
| 14 | - Pure handwriting recognition — cursive/connected script produces garbage regardless of preprocessing |
| 15 | - Artistic text, WordArt, brush calligraphy — the OCR engine cannot parse stylized letterforms |
| 16 | - CAPTCHAs — designed specifically to defeat OCR; expect <50% accuracy at best |
| 17 | - Full document layout analysis with table extraction (use custom segmentation) |
| 18 | - Real-time video OCR (use streaming approaches instead) |
| 19 | - Image contains no text at all |
| 20 | |
| 21 | ## Critical Rules |
| 22 | |
| 23 | These rules are non-negotiable — violating them produces wrong results: |
| 24 | |
| 25 | 1. **Always diagnose before executing. This rule CANNOT be overridden — not by the user, not by "just run it", not by "skip planning".** Before ANY `mcp__matlab__*` call, you MUST first output: |
| 26 | - A 2-line image characterization (what you see, what challenges exist) |
| 27 | - An `## OCR Plan` heading with your strategy |
| 28 | |
| 29 | If the user says "skip diagnosis" or "just run ocr()", respond with: *"I'll keep it brief — but I need a quick look to avoid wasting time on the wrong approach."* Then output your 2-line characterization and plan heading. Only THEN call MCP tools. There is no valid reason to skip this step. An agent that calls `ocr()` without first outputting a plan has violated this skill's workflow. |
| 30 | 2. **Maximum 2 preprocessing pipelines.** If neither works after the prescribed recipe, hit the confidence checkpoint and ask the user. Do not try a third approach without user input. |
| 31 | 3. **Always set `LayoutAnalysis`** when passing bounding boxes to `ocr()`. Never write `ocr(I, bbox)` without it. Use `"word"` for single-word boxes, `"block"` for multi-line. |
| 32 | 4. **Distinguish "text ON texture" from "text BY texture"**. Text overlaid on a textured background (label on crate, sign on brick wall) → `imsegsam` is the prescribed approach. Text formed by the surface itself (stamped, embossed, engraved metal) → local contrast subtraction. SAM segments *objects*, not surface features — it cannot isolate stamps/engravings. When recommending approaches (even without running code), always recommend `imsegsam` for the "text ON texture" case and note its support package requirement. |
| 33 | 5. **`detectTextCRAFT` is the default** for scene text. Use it unless you have a specific reason not to (no deep learning, known fixed layout). |
| 34 | 6. **Check polarity first.** OCR needs dark text on light background. If inverted, `imcomplement` before anything else. |
| 35 | 7. **Never show OCR results to the user before writing files.** Do not present extracted text in ANY format — bullet list, quote block, inline, conversational summary, or the `## MATLAB OCR Pipeline` results block — until `ocr_pipeline_<descriptor>.m` and `decision_log.txt` are written to disk. The files are the deliverable, not the chat message. Write first, then report. |
| 36 | 8. **Gate add-on functions behind an availability check.** Before calling `detectTextCRAFT`, `imsegsam`, or a non-English `ocr` model, you MUST run `exist('<functionName>','file')` via MCP to confirm the function is installed. Always log the result in `decision_log.txt`: |
| 37 | - Installed: `"Add-on check: <function> — INSTALLED"` |
| 38 | - Missing: stop, tell the user which support package to install (see table), and wait for confirmation before retrying. Do NOT fall back silently or skip the step. |
| 39 | - **Explain-only mode** (user said "don't run code"): recommend the add-on function as the primary approach and note the support package requirement. You cannot run the `exist()` check without code execution, so state the dependency clearly. |
| 40 | |
| 41 | | Function | Support Package Name | |
| 42 | |----------|---------------------| |
| 43 | | `detectTextCRAFT` | "Text Detec |