Matlab Recognize Text 标志

Matlab Recognize Text

组织热门
matlab
matlab-recognize-text

Build 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-based recognition, multi-language OCR, and custom model training. Use when: OCR, text recognition, extract text from image, character recognition, document scanning, meter reading, gauge reading, receipt scanning, digitize text from photo.

概览

发布者matlab
代码仓库matlab-agentic-toolkit
技能名称matlab-recognize-text
星标数
1.2K
复刻数
138
附带文件
8
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 8 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 matlab 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Matlab Recognize Text AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/matlab/matlab-agentic-toolkit/tree/main/skills-catalog/image-processing-and-computer-vision/matlab-recognize-text
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/matlab/matlab-agentic-toolkit.git /tmp/matlab-agentic-toolkit
mkdir -p .claude/skills
cp -r /tmp/matlab-agentic-toolkit/skills-catalog/image-processing-and-computer-vision/matlab-recognize-text .claude/skills/matlab-recognize-text
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Matlab Recognize Text,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Matlab Recognize Text。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Matlab Recognize Text 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Recognize Text in Images Using OCR

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.

When to Use

  • Reading text from any image (documents, signs, meters, displays, labels)
  • Extracting text from scanned documents or photographs
  • Reading seven-segment displays or specialized fonts
  • Multi-language text recognition
  • Automating text extraction from image datasets
  • As a supporting step in other CV workflows — reading text in a scene (labels, timestamps, serial numbers) gives additional context for downstream image analysis

When NOT to Use

  • Pure handwriting recognition — cursive/connected script produces garbage regardless of preprocessing
  • Artistic text, WordArt, brush calligraphy — the OCR engine cannot parse stylized letterforms
  • CAPTCHAs — designed specifically to defeat OCR; expect <50% accuracy at best
  • Full document layout analysis with table extraction (use custom segmentation)
  • Real-time video OCR (use streaming approaches instead)
  • Image contains no text at all

Critical Rules

These rules are non-negotiable — violating them produces wrong results:

  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:

    • A 2-line image characterization (what you see, what challenges exist)
    • An ## OCR Plan heading with your strategy

    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.

  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.

  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.

  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.

  5. detectTextCRAFT is the default for scene text. Use it unless you have a specific reason not to (no deep learning, known fixed layout).

  6. Check polarity first. OCR needs dark text on light background. If inverted, imcomplement before anything else.

  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.

  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:

    • Installed: "Add-on check: <function> — INSTALLED"
    • 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.
    • 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.
    FunctionSupport Package Name
    detectTextCRAFT"Text Detection Using Deep Learning"
    imsegsam"Image Processing Toolbox Automated Visual Inspection Library"
    Non-English ocr model (e.g., "japanese")"OCR Language Data"

    Missing template: "This step requires the <function> function, which needs the support package. Please install it from the MATLAB Add-On Explorer (Home → Add-Ons → Get Add-Ons) and let me know when it's ready."

Anti-Patterns — Do NOT Do This

  • Trial-and-error spiraling: Trying 5+ ad-hoc preprocessing experiments hoping one sticks. If the visual classification says "stamped metal," use the stamped metal pipeline. Period.
  • Skipping the plan: "I'll just try one quick thing first." No. Diagnose → plan → execute.
  • Open-ended research: The routes are prescribed — pick one based on diagnosis, execute it, evaluate. This is not exploratory research.
  • Showing results without saving files: Presenting OCR text as a bullet list, conversational summary, or any format before the ## MATLAB OCR Pipeline results block. That block can only appear after files are written to disk. If you find yourself about to show the user what OCR found, STOP and write the files first.

Workflow

Progress Reporting + Output Template

Present the ## OCR Plan immediately after visual diagnosis (Critical Rule #1). Then execute the pipeline. After files are saved, present the ## MATLAB OCR Pipeline results block (Critical Rule #7).

OCR Plan (output before any MATLAB code runs)
## OCR Plan

**Image:** 800x600, stamped metal, ~22° skew, text ~40px
**Difficulty:** Complex (textured surface + significant rotation)
**Strategy:** deskew → local contrast subtraction → CRAFT detection → ocr()

For simple images:

## OCR Plan

**Image:** 1200x800, clean scanned document, no skew
**Difficulty:** Simple
**Strategy:** binarize → ocr() directly
Results Block (output ONLY after files are written to disk)
## MATLAB OCR Pipeline: SUCCESS

**Pipeline:** deskew (22.6°) → local contrast subtraction → CRAFT detection → ocr() per region

| Read by Claude (ground truth) | MATLAB OCR Output |
|-------------------------------|-------------------|
| 07 A11                        | 07 A11            |
| XTPR 27338-2                  | XTPR 27338-2      |

**Metrics** (via `evaluateOCR`): CER 0.00 | WER 0.00
**Files written:**
- `ocr_pipeline_stamped_metal.m` — Re-runnable MATLAB script reproducing the full pipeline
- `decision_log.txt` — Diagnosis, routing decisions, and confidence scores

For failures:

## MATLAB OCR Pipeline: FAILED

**Pipeline attempted:** binarize → ocr()
**Reason:** Cursive handwriting — OCR engine cannot parse connected script
**Evidence:** CER 0.91 | WER 1.00

| Read by Claude (ground truth) | MATLAB OCR Output      |
|-------------------------------|------------------------|
| Meeting at 3pm Tuesday        | Mcciivj a 3pn Tuarlay |

**Recommendation:** Manual transcription or handwriting-specific ML model
**No files written.**
GATE (Critical Rule #7)

Do NOT present the ## MATLAB OCR Pipeline results block until files are confirmed on disk. No bullet lists, no quotes, no summaries — nothing that reveals extracted text before files are written.

Step 1: Diagnose

Always start here. Look at the image, visually read the text (this becomes your ground truth), classify the image, and present the ## OCR Plan — all before any MATLAB code runs.

Your visual classification determines the preprocessing route:

Visual ClassificationPreprocessing Route
Clean document, minimal skewBinarize → OCR directly (skip to Step 4)
Low contrast / uneven lightingimtophat or adapthisteq → binarize
Stamped / embossed / engraved (text IS the surface)Local contrast subtraction (Step 2)
Text overlaid on textured background (label on crate, sign on wall)imsegsam SAM segmentation (Step 3)
Significant skew (>10°)Deskew FIRST, then preprocess
Tiny text (<50px)imresize 4-8x first

After classification, confirm via MATLAB: binarization check, skew measurement, and quick experiments.

matlab
% TEMPLATE — not executable
I = imread("yourImage.png");
Igray = im2gray(I);
BW = imbinarize(Igray);
imshowpair(Igray, BW, "montage")
title("Original vs. What OCR Sees")

Skew measurement must be deterministic. The centroid fitting method is sensitive to which blobs are included. To ensure reproducibility:

  • Use ALL text-sized blobs (filter by area range, e.g., 50-5000px), not "top N by area"
  • Alternatively, use the Hough transform (hough + houghpeaks + houghlines) on edges for a robust angle estimate
  • The pipeline .m script must reproduce the exact same skew angle on re-run — if it doesn't, the deskew approach is fragile and must be replaced

Binarization diagnostic:

  • Text clearly legible → Skip to Step 4
  • Text faint/merged/noisy → Preprocessing (Step 2)
  • White on black → imcomplement
  • Too small (<50px) → imresize 4-8x
  • Rotated/skewed → Deskew BEFORE other preprocessing
  • Characters too bold/bleeding → imerode(BW, strel("disk",1))
  • Characters too thin/broken → imdilate(BW, strel("disk",1))
  • Dark borders/scan frame → imclearborder(BW) or crop
  • Metal texture dominates → Local contrast subtraction

Escalation rule: If 2+ preprocessing attempts still produce garbled results or <80% confidence, identify the root cause:

  • Image too small (sub-50px)? → Resize 4-8x is the fix
  • Text overlaid on textured background? → imsegsam (SAM)
  • Text formed by surface texture (stamped/embossed)? → Local contrast subtraction
  • Font unrecognizable (handwriting, calligraphy)? → OCR engine limitation; consider trainOCR

MANDATORY Confidence warning: High confidence does NOT guarantee correctness. OCR can report >0.9 confidence on completely wrong text, especially on small or unusual images. Always validate results against expected content.

Step 2: Preprocess the Image

Apply preprocessing based on your diagnosis. See reference/preprocessing-guide.md for full code examples.

Pipeline routing:

ClassificationMethodKey function
Uneven lightingTop-hat illumination correctionimtophat + imreconstruct
Stamped/embossed/engravedLocal contrast subtractionimgaussfilt(Igray,30) - Igray
Skewed >10°Deskew FIRST via centroid fittingimrotate
Small text <50pxScale up 4-8ximresize
Inverted polarityComplementimcomplement

Key rules:

  • Deskew BEFORE other preprocessing — rotation invalidates morphological operations
  • OCR expects dark text on light background — use imcomplement if inverted
  • For small clean images, try OCR on resized grayscale before binarizing — anti-aliasing helps
  • Add 10px white border with padarray(BW, [10 10], 1) if text touches edges

Step 3: Detect Text Regions (Critical)

For natural scenes (street signs, product labels, meter faces), isolating text regions before calling ocr is critical. These images have complex backgrounds that confuse the OCR engine. For scanned documents with uniform backgrounds, this step is less important — ocr has built-in page layout analysis that handles well-formatted documents automatically.

Default choice: detectTextCRAFT. Unless you have a specific reason to use another method (no deep learning available, known fixed layout, etc.), always prefer CRAFT for scene text. It outperforms MSER on complex backgrounds.

MANDATORY before using CRAFT or SAM: Run exist('detectTextCRAFT','file') or exist('imsegsam','file') via MCP. If the result is 0, stop and ask the user to install the required support package (Critical Rule #8). Do NOT proceed without confirmation.

Choose a detection method based on your image type:

Image TypeMethodWhen to Use
Natural scene (signs, products)detectTextCRAFTPreferred for complex backgrounds
Document with sparse textdetectMSERFeaturesClassic approach, no deep learning needed
Known fixed locationManual ROI [x y w h]Consistent image layout (e.g., meter face always in same spot)
Text on uniform backgroundregionprops on binaryFind connected components by area/aspect ratio
Color-distinct textColor segmentationIsolate text by color channel thresholding
Text overlaid on textured backgroundimsegsam (SAM)Label on crate, sign on brick wall (text is a separate object)
Simple clean documentNone (use ocr directly)Clean scans with uniform background

SAM warning: Do NOT use SAM for stamped, embossed, engraved, or etched text — these are surface features, not objects. Use local contrast subtraction (Step 2) instead. SAM takes ~60-120s and needs full resolution (never downscale).

See reference/detection-methods.md for code examples of each method (CRAFT, MSER, SAM, manual ROI, connected components, color segmentation).

Step 4: Recognize Text

RULE: Always set LayoutAnalysis when passing bounding boxes to ocr(). Never call ocr(I, bbox) without it — the default "auto" fails on small regions. Use "word" for single-word boxes, "block" for multi-line regions.

Common patterns: ocr(I), ocr(I, bbox, LayoutAnalysis="word"), ocr(BW, CharacterSet="0123456789"), ocr(I, roi, Model="seven-segment", LayoutAnalysis="word"). See reference/function-reference.md for full examples.

If detection succeeded but recognition returns garbage: The problem is preprocessing or skew, not detection. Return to Step 2:

  • Skew >10° causes total failure even on clean binary images
  • Try local contrast subtraction if the image is textured
  • Try OCR on preprocessed grayscale rather than binary — anti-aliasing helps

Step 5: Validate Results

Filter by results.WordConfidences > 0.7. Check results.CharacterConfidences for suspect characters. See reference/function-reference.md for validation code patterns.

MANDATORY ACTION: Run evaluateOCR with ground truth.

You MUST compute OCR metrics using evaluateOCR. The ground truth is either:

  1. Text you (Claude) read visually from the image — use this by default
  2. Text the user provided — use this if the user supplies expected text or corrects your read

Run this via MCP after recognition:

matlab
% evaluateOCR signature:
%   metrics = evaluateOCR(ocrTextObj, groundTruthCellArray)
%   - ocrTextObj: the ocrText object returned directly by ocr()
%   - groundTruthCellArray: cell array of strings, one per expected text region
metrics = evaluateOCR(results, {"07 A11"; "XTPR 27338-2"});
fprintf("Character Error Rate (CER): %.2f\n", metrics.CharacterErrorRate);
fprintf("Word Error Rate (WER): %.2f\n", metrics.WordErrorRate);

Always run evaluateOCR via MCP and report the actual CER and WER values.

MANDATORY ACTION: Confidence checkpoint — when to ask the user:

If ANY of these are true, show the user what you got and ask them to confirm or correct:

  • Mean word confidence < 0.6
  • CER > 0.10 or WER > 0.20
  • You attempted 2+ preprocessing approaches and results still look wrong
  • The recognized text doesn't make semantic sense AND you can't read it yourself in the image
  • OCR returns fewer words than you can visually count in the image

Ask clearly: "I'm not confident in this result. OCR returned [text] (CER: 0.12, WER: 0.20). Can you tell me what the text actually says? I'll use that to tune the pipeline."

If the user provides ground truth, re-run evaluateOCR with the corrected ground truth and adjust preprocessing to minimize CER/WER.

After validation, proceed immediately to Step 6 — do not present results until files are on disk.

Step 6: Save Pipeline + Log

Save the pipeline as a .m script that is re-runnable on different images. Never hardcode values computed interactively — include all detection code (skew angle measurement, threshold selection, ROI detection).

Naming: ocr_pipeline_<descriptor>.m (e.g., ocr_pipeline_stamped_metal.m)

MANDATORY Requirements:

  • Include comments explaining each DECISION (why this approach, not just what)
  • Always show diagnostic figures (imshowpair, insertShape for bounding boxes, insertObjectAnnotation for boxes and text)
  • Use detectTextCRAFT + per-region ocr() with CharacterSet and LayoutAnalysis="word" for textured/complex images (not full-image LayoutAnalysis="block" which gives lower confidence)
  • Always include timestamp of when file is created. And include comment that says "Created using matlab-recognize-text Skill". Also produce a decision_log.txt — one line per decision point, format: [step] TYPE: description. Types: VISUAL, EXPERIMENT, DECISION, RESULT, GAP. Example:
[1] VISUAL: Stamped metal, ~20° skew, embossed characters
[2] DECISION: Local contrast subtraction (stamped text confirmed)
[3] EXPERIMENT: Centroid fitting → skew angle = 22.6°
[4] RESULT: "07 AN / XTPR 27338-2" — confidence 0.74 mean
[5] GAP: "A11" misread as "AN" — thin stamps merge at this resolution

This file is what the user sends back if the skill didn't fully work.

Quick Reference

LayoutAnalysis rule: Always set LayoutAnalysis when passing ROI boxes ("word", "block", or "none"). Default "auto" fails on small regions.

Key functions: ocr, detectTextCRAFT, imsegsam, imbinarize, imtophat, imcomplement, imresize, bwareaopen, imrotate. See reference/function-reference.md and reference/batch-pipeline.md.

Custom Model Training

MANDATORY: Present the gating checklist BEFORE recommending training. Train only if ALL are true: (1) preprocessing + parameter tuning still fails, (2) font/charset not in built-in models, (3) you have labeled ground truth, (4) use case is high-volume/repeated. Try first: Model="seven-segment", Model="french", CharacterSet, LayoutAnalysis.

Programmatic API (always use these, not the ocrTrainer app): trainOCR, ocrTrainingOptions, ocrTrainingData. See reference/training-guide.md for full workflow.

Multi-Language Support

MANDATORY before using a non-English model: Run exist('ocrLanguageData','dir') via MCP. If the result is 0, stop and ask the user to install the "OCR Language Data" support package (Critical Rule #8). Do NOT proceed without confirmation.

Use Model="japanese" (or "french-fast" for quantized). Requires OCR Language Data support package. See reference/supported-languages.md.

Troubleshooting

SymptomCauseFix
Empty resultsLight text on dark backgroundimcomplement(imbinarize(Igray))
Garbage charactersNo preprocessingBinarize, crop to ROI, use CharacterSet
"O"→"0" or "l"→"1"Ambiguous glyphsCharacterSet to exclude impossible chars
Seven-segment wrongLayout splits linesLayoutAnalysis="word"
Text too small<20px tallimresize(I, 3) before OCR
Words split oddlySkewed textDeskew via centroid fitting + imrotate

When OCR fails, return to Step 1 and re-inspect the binarized output. Do not loop on unsolvable cases (cursive handwriting, CAPTCHAs, <30px text, curved/arc text) — tell the user early. See reference/limitations.md.


Copyright 2026 The MathWorks, Inc.


附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Matlab Recognize Text AI 技能有什么作用?

Build 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-based recognition, multi-language OCR, and custom model training. Use when: OCR, text recognition, extract text from image, character recognition, document scanning, meter reading, gauge reading, receipt scanning, digitize text from photo.

为什么在 TypingMind 中使用 Matlab Recognize Text?

因为您只需安装一次,就能搭配任何模型使用。Matlab Recognize Text 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Matlab Recognize Text?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/matlab/matlab-agentic-toolkit/tree/main/skills-catalog/image-processing-and-computer-vision/matlab-recognize-text。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Matlab Recognize Text?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Matlab Recognize Text 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Matlab Recognize Text 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Matlab Recognize Text AI 技能免费吗?

matlab 已在 GitHub 上发布了该技能。请查看代码仓库了解许可条款。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇