Skip to content

feat: color_filter for OCR#1145

Merged
MistEO merged 4 commits intomainfrom
feat/color_ocr
Feb 24, 2026
Merged

feat: color_filter for OCR#1145
MistEO merged 4 commits intomainfrom
feat/color_ocr

Conversation

@MistEO
Copy link
Member

@MistEO MistEO commented Feb 24, 2026

fix #1009

Summary by Sourcery

为 OCR 节点引入可选的基于颜色的预处理功能,并将其配置贯穿管线、绑定层以及文档。

New Features:

  • 为 OCR 管线节点添加可选的颜色过滤配置,在 OCR 识别之前利用已有的 ColorMatch 参数对图像进行二值化处理。

Enhancements:

  • 将颜色过滤支持接入 OCRer 组件,包括 ROI 预处理以及将其从批处理优化中排除。
  • 扩展管线的解析、导出以及类型定义(C++、Python、NodeJS、JSON schema),以支持新的 OCR 字段 color_filter

Documentation:

  • 在英文和中文的管线协议文档中记录 OCR 节点的新增配置项 color_filter,包括其行为和限制。

Tests:

  • 更新 Python 管线测试,用于覆盖对新 OCR 字段 color_filter 的解析和使用场景。
Original summary in English

Summary by Sourcery

Introduce optional color-based preprocessing for OCR nodes and plumb its configuration through the pipeline, bindings, and documentation.

New Features:

  • Add optional color filter configuration to OCR pipeline nodes to binarize images using existing ColorMatch parameters before OCR recognition.

Enhancements:

  • Wire color filter support into the OCRer component, including ROI preprocessing and exclusion from batch optimization.
  • Extend pipeline parsing, dumping, and type definitions (C++, Python, NodeJS, JSON schema) to handle the new OCR color_filter field.

Documentation:

  • Document the new color_filter option for OCR nodes in the English and Chinese pipeline protocol docs, including behavior and limitations.

Tests:

  • Update Python pipeline tests to cover parsing and usage of the new OCR color_filter field.

Copilot AI review requested due to automatic review settings February 24, 2026 16:42
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我在这里给出了一些整体性的反馈:

  • ColorFilterConfig 中,建议使用与 ColorMatcherParam::method 相同的类型(或显式使用 cv::ColorConversionCodes 枚举),而不是使用带有魔法默认值 4 的原始 int 类型,以降低转换代码出错的可能性,并让其更具自说明性。
  • PipelineTask::try_add_ocr_node 中,带有 color_filter 的 OCR 节点会被静默地排除在批处理优化之外;添加一条简短注释来解释这一行为,将有助于未来的维护者理解为什么这里需要提前返回。
给 AI 智能体的提示
Please address the comments from this code review:

## Overall Comments
- In `ColorFilterConfig`, consider using the same type as `ColorMatcherParam::method` (or an explicit `cv::ColorConversionCodes` enum) instead of a raw `int` with a magic default `4`, to make the conversion code less error‑prone and self‑documenting.
- In `PipelineTask::try_add_ocr_node`, OCR nodes with `color_filter` are silently excluded from batch optimization; adding a brief comment explaining this behavior would help future maintainers understand why the early return is necessary.

Sourcery 对开源项目是免费的——如果你觉得我们的代码审查有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进后续的代码审查。
Original comment in English

Hey - I've left some high level feedback:

  • In ColorFilterConfig, consider using the same type as ColorMatcherParam::method (or an explicit cv::ColorConversionCodes enum) instead of a raw int with a magic default 4, to make the conversion code less error‑prone and self‑documenting.
  • In PipelineTask::try_add_ocr_node, OCR nodes with color_filter are silently excluded from batch optimization; adding a brief comment explaining this behavior would help future maintainers understand why the early return is necessary.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `ColorFilterConfig`, consider using the same type as `ColorMatcherParam::method` (or an explicit `cv::ColorConversionCodes` enum) instead of a raw `int` with a magic default `4`, to make the conversion code less error‑prone and self‑documenting.
- In `PipelineTask::try_add_ocr_node`, OCR nodes with `color_filter` are silently excluded from batch optimization; adding a brief comment explaining this behavior would help future maintainers understand why the early return is necessary.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a color_filter field to the OCR recognition type in the pipeline protocol, allowing OCR nodes to reference a ColorMatch node and apply its color binarization logic before performing OCR recognition. This is useful for improving OCR accuracy on images with specific color patterns by preprocessing them with color-based filtering.

Changes:

  • Added color_filter field to OCR recognition parameters across the entire codebase (C++, bindings, schema, documentation)
  • Implemented color filtering logic in OCRer that applies ColorMatch node's color parameters to binarize images before OCR
  • Excluded OCR nodes with color_filter from batch optimization to maintain per-node filtering correctness

Reviewed changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tools/pipeline.schema.json Added color_filter field definition to OCR recognition schema
test/python/pipeline_test.py Added test case validating color_filter field parsing and retrieval
source/binding/Python/maa/pipeline.py Added color_filter field to JOCR dataclass
source/binding/NodeJS/src/apis/pipeline.d.ts Added color_filter field to OCR TypeScript interface
source/MaaFramework/Vision/VisionTypes.h Added color_filter field to OCRerParam struct
source/MaaFramework/Vision/OCRer.h Added ColorFilterConfig struct and color_filter parameter to OCRer constructor
source/MaaFramework/Vision/OCRer.cpp Implemented apply_color_filter method and integrated it into OCR prediction pipeline
source/MaaFramework/Task/PipelineTask.cpp Excluded OCR nodes with color_filter from batch optimization
source/MaaFramework/Task/Component/Recognizer.cpp Added validation and extraction of ColorMatch node parameters for color filtering
source/MaaFramework/Resource/PipelineTypesV2.h Added color_filter field to JOCR struct for serialization
source/MaaFramework/Resource/PipelineParser.cpp Added parsing logic for color_filter field
source/MaaFramework/Resource/PipelineDumper.cpp Added serialization of color_filter field
docs/en_us/3.1-PipelineProtocol.md Documented color_filter field in English
docs/zh_cn/3.1-任务流水线协议.md Documented color_filter field in Chinese (not shown in diff but verified to exist)

@MistEO MistEO merged commit 53b4080 into main Feb 24, 2026
19 checks passed
@MistEO MistEO deleted the feat/color_ocr branch February 24, 2026 18:14
neko-para added a commit to neko-para/maa-support-extension that referenced this pull request Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

建议:为ocr识别新增颜色反转或者画面只保留特定颜色区间来ocr

2 participants