Add imgproc TrueType text rendering: FontFace + FontFace-based PutText/GetTextSize - #1929
Merged
Merged
Conversation
…t/GetTextSize
Wraps the OpenCV 5 built-in STB TrueType renderer (replacing the contrib
freetype module):
- FontFace class: default / embedded ("sans", "italic", "uni") / custom-path
fonts, plus Set, Name, SetInstance / GetInstance (variable-font axes).
- Cv2.PutText and Cv2.GetTextSize overloads taking a FontFace (size, weight,
PutTextFlags, optional wrap Range). Text is marshaled as UTF-8 so full
Unicode renders correctly.
- PutTextFlags enum (align / origin / wrap).
Native entry points in a new imgproc_FontFace.h; font path/name strings use
the Windows/NotWindows marshaling split while text content uses UTF-8.
Tests: FontFace creation (default + embedded), GetTextSize, ASCII + Unicode
PutText pixel checks, and SetInstance/GetInstance. Full ImgProc suite green
(142 passed).
Refs #1924.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This was referenced Jun 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Wraps the OpenCV 5 built-in STB TrueType text renderer (which replaces the contrib
freetypemodule) — from #1924.New API
FontFaceclass: default font, embedded fonts ("sans","italic","uni"), or a custom font path. ExposesSet,Name, andSetInstance/GetInstancefor variable-font axes (e.g.wght,slnt).Cv2.PutText/Cv2.GetTextSizeoverloads taking aFontFace(fontsize,weight,PutTextFlags, optional wrapRange).PutTextreturns the continuation point;GetTextSizereturns the boundingRect.PutTextFlagsenum (align / origin / wrap).Text is marshaled as UTF-8, so full Unicode renders correctly (unlike the legacy Hershey
PutText, which is ANSI).Native bridge
imgproc_FontFace.h(included fromimgproc.cpp).Test
FontFaceTest:sans,uni).GetTextSizereturns a positive-sized rect.PutTextdraws pixels and advances the cursor (ASCII).PutTextwith a Unicode string (Greek + Cyrillic) using theunifont draws pixels.SetInstance/GetInstanceround-trip wiring.Rebuilt
OpenCvSharpExternlocally; full ImgProc suite green (142 passed).Refs #1924.
🤖 Generated with Claude Code