Skip to content

Fix: Handle grayscale image matching with RGB templates matching#5700

Open
ycnliu wants to merge 4 commits into
LmeSzinc:devfrom
ycnliu:fix/template-grayscale-matching
Open

Fix: Handle grayscale image matching with RGB templates matching#5700
ycnliu wants to merge 4 commits into
LmeSzinc:devfrom
ycnliu:fix/template-grayscale-matching

Conversation

@ycnliu
Copy link
Copy Markdown

@ycnliu ycnliu commented Jun 5, 2026

Fixes the OpenCV matchTemplate assertion error when matching RGB template frames against grayscale images.

Issue

Campaign OCR fails with error:
cv2.error: (-215:Assertion failed) (depth == CV_8U || depth == CV_32F) && type == _templ.type() && _img.dims() <= 2

This occurs when TEMPLATE_STAGE_CLEAR_20240725 (GIF with RGB frames) is matched against grayscale stage images in
campaign_extract_name_image().

Changes

  • Added automatic grayscale conversion of templates when input image is grayscale in Template.match_multi()
  • Handles both GIF and non-GIF templates
  • Prevents type mismatch between RGB templates and grayscale input images

Testing

The fix ensures that when a grayscale image is passed to match_multi(), any RGB templates are automatically converted to grayscale
before matching.

LmeSzinc and others added 4 commits May 21, 2026 00:45
Add: Event Alliance Before the Hagiobull (event_20260520_cn)
Fixed OpenCV matchTemplate assertion error when matching RGB template
frames against grayscale images. The error occurred in campaign OCR
when TEMPLATE_STAGE_CLEAR_20240725 (GIF with RGB frames) was matched
against grayscale stage images.

Changes:
- Added automatic grayscale conversion of templates when input image
  is grayscale in Template.match_multi()
- Handles both GIF and non-GIF templates
- Prevents cv2.error: (-215:Assertion failed) type mismatch
@LmeSzinc
Copy link
Copy Markdown
Owner

LmeSzinc commented Jun 5, 2026

Convert TEMPLATE_STAGE_CLEAR_20240725 to grayscale image instead. Converting channels internally may have bad performance and hard to notice

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.

2 participants